public final class DataIndexIndex extends Object
DataTimeIndex
. Die Folge der Eintraege (min, max) ist nicht monoton,
weil es beim Nachfordern Rueckspruenge geben kann. Stattdessen sind die Eintraege nur nach dem min-Wert sortiert. Ein Eintrag enthaelt Minimum, Maximum des
Datenindex und die ContainerID.Modifier and Type | Class and Description |
---|---|
static class |
DataIndexIndex.IndexStartmode
Modi, mit denen ein Index angelegt werden kann (siehe
DataTimeIndex.DataTimeIndex(int,String,byte[],IndexStartmode) ) |
Modifier and Type | Field and Description |
---|---|
static DataIndexIndex.IndexStartmode |
APPEND_REUSE_LAST |
private long |
biggestDIMaxInFile
Hilfsvariablen
|
private static int |
CONTID_POS |
private long[] |
currentEntry
Current Entry Array - aktuelle Daten
|
static DataIndexIndex.IndexStartmode |
ERASE_OLD |
private static String |
ERROR_ACCESS |
private static String |
ERROR_CLOSE |
private static String |
ERROR_OPEN |
private long |
filePositionReactivatedEntry |
static String |
IDX_FILENAME
Dateiname, unter dem alle Indices dieser Art gespeichert werden
|
private static int |
MAX_POS |
private static int |
MIN_POS
Positionen einzelner Daten im Enty-Array
|
static int |
NO_VALUE
Flag, mit dem signalisiert wird, dass ein Eintrag "keinen Wert" hat
|
private int |
rbBiggestEntry |
private byte[] |
rbBuffer |
private boolean |
rbFileupdateNecessary |
private int |
rbOffsetOfFirstUnsavedFromSmallest |
private int |
rbSmallestEntry |
Constructor and Description |
---|
DataIndexIndex(int bufferSize)
Erzeugt einen neuen DatenIndexIndex.
|
DataIndexIndex(int bufferSize,
String basePath,
byte[] temp,
DataIndexIndex.IndexStartmode startmode)
Erzeugt einen neuen DatenIndex.
|
Modifier and Type | Method and Description |
---|---|
void |
add(String basePath,
byte[] temp,
long dIMin,
long dIMax,
long contId)
Fügt dem Index einen neuen Eintrag hinzu.
|
private long |
binaryFileSearch(RandomAccessFile raf,
byte[] temp,
long key)
Ermittelt mit einer binären Suche die Position, an der der Key1 untergebracht werden kann.
|
int |
capacity()
Anzahl der Einträge, die dieser Index im RAM halten kann
|
void |
checkForAdd(String basePath,
byte[] temp,
long dIMin,
long dIMax,
long contId)
Prüft, ob dem Index ein neuer Eintrag hinzugefügt werden könnte.
|
void |
closeIndex(String basePath,
byte[] temp)
Schließt den Index und speichert alle geänderten Daten auf Platte.
|
private int |
containsKey(byte[] array,
int cnt,
long key) |
private void |
currentEntryToBuffer(String basePath,
byte[] temp) |
int |
entries()
Anzahl der Einträge, die dieser Index im RAM hält
|
private void |
flush(String basePath) |
long |
getAbsolutDIdxMin(String basePath)
Liefert den kleinsten DT Min Wert, der jemals in diesem Index gespeichert wird.
|
IndexResult |
getContainerID(String basePath,
byte[] temp,
long dIMin,
long dIMax)
Liefert eine Matrix mit DIMin/Max und ContainerIds, deren DTMin/Max-Werte zwischen dTMin und dTMax liegen.
|
long |
getCurrentCID()
Liefert die aktuelle Container ID.
|
long |
getCurrentDIMax()
Liefert vom aktuellen Eintrag den Max-Wert des DatenIndex
|
long |
getCurrentDIMin()
Liefert vom aktuellen Eintrag den Min-Wert des DatenIndex
|
private long[][] |
getMaximaFromFile(RandomAccessFile raf,
byte[] temp,
int fileStart,
int fileEnd) |
private void |
ifClose(RandomAccessFile raf) |
private RandomAccessFile |
ifOpen(String basePath) |
private void |
insertIntoFile(String basePath,
byte[] temp) |
private void |
linearFileSearch(RandomAccessFile raf,
byte[] temp,
IndexResult ir,
long min,
long max) |
private static int |
locateEntry(byte[] buffer,
long[] entry) |
private void |
osAppendToFile(OutputStream os) |
private boolean |
overlap(long firstMin,
long firstMax,
long secondMin,
long secondMax) |
private void |
rbAddCurrentEntry() |
private void |
rbAppendCurrentEntry() |
private void |
rbAppendToFile(RandomAccessFile raf) |
private int |
rbBytePos(int pos) |
private boolean |
rbCacheChanged() |
private int |
rbCapacity() |
private int |
rbCapacityInBytes() |
private int |
rbElementsInbetween(int start,
int stop,
int ringbufferSize) |
private int |
rbEntries() |
private int |
rbEntryLength() |
private void |
rbExtractMaxima() |
private int |
rbFindDIMin(long key) |
private long |
rbGetCID(int index) |
private long |
rbGetDIMax(int index) |
private long |
rbGetDIMin(int index) |
private long[] |
rbGetEntry(int index) |
private long[] |
rbGetFileAnchor() |
private int |
rbGetFirstUnsaved() |
private boolean |
rbHasUnsavedData() |
private void |
rbInit(int entries) |
private void |
rbInsertElement() |
private void |
rbLoad(RandomAccessFile raf) |
private void |
rbMoveEntryLeft(int index) |
private void |
rbMoveEntryRight(int index) |
private boolean |
rbMustBeSaved() |
private int |
rbStep(int index) |
private int |
rbStepBack(int index) |
private String |
rbToString() |
void |
resize(int newSize,
String basePath)
Verändert die Größe des RingBuffers.
|
String |
toString()
Gibt den Inhalt des ByteBuffers als String aus, inkl Angaben über Kapazität, Anzahl der Einträge und des CurrentEntries.
|
private void |
updateCurrentEntryInFile(String basePath) |
void |
updateMax(long newDIMax)
Aktualisiert den Max-Wert des aktuellsten Eintrages.
|
public static final String IDX_FILENAME
public static final int NO_VALUE
public static final DataIndexIndex.IndexStartmode APPEND_REUSE_LAST
public static final DataIndexIndex.IndexStartmode ERASE_OLD
private static final int MIN_POS
private static final int MAX_POS
private static final int CONTID_POS
private static final String ERROR_OPEN
private static final String ERROR_CLOSE
private static final String ERROR_ACCESS
private long biggestDIMaxInFile
private long filePositionReactivatedEntry
private long[] currentEntry
private byte[] rbBuffer
private int rbSmallestEntry
private int rbBiggestEntry
private int rbOffsetOfFirstUnsavedFromSmallest
private boolean rbFileupdateNecessary
public DataIndexIndex(int bufferSize, String basePath, byte[] temp, DataIndexIndex.IndexStartmode startmode) throws IndexException
bufferSize
- Anzahl der Einträge, die der die der Index im RAM halten sollbasePath
- Verzeichnis, in dem die Indexdatei liegttemp
- Ein temporäres ByteArray, das zum Suchen des currentEntries verwendet wirdstartmode
- DataIndexIndex.IndexStartmode.ERASE_OLD
: alte Indexdatei loeschen, DataIndexIndex.IndexStartmode.APPEND_REUSE_LAST
: anfuegen, letzten Eintrag
weiterverwendenIndexException
- Bei Problemem mit dem Dateizugriffpublic DataIndexIndex(int bufferSize)
bufferSize
- Anzahl der Einträge, die der die der Index im RAM halten sollpublic void updateMax(long newDIMax) throws IndexException
newDIMax
- neuer Wert für DatenIndexIndex-MaxIndexException
- Wenn der neue Wert kleiner als der dazugehörige Min-Wert ist oder wenn keinen currentEntry gibtpublic long getCurrentCID()
public long getCurrentDIMin()
public long getCurrentDIMax()
public int capacity()
public int entries()
public void add(String basePath, byte[] temp, long dIMin, long dIMax, long contId) throws IndexException
basePath
- Verzeichnis, in dem die Index-Datei liegttemp
- Puffer, der beim Einlesen/Schreiben der Index-Datei verwendet wirddIMin
- DatenIndex Min-WertdIMax
- DatenIndex Max-WertcontId
- Container IDIndexException
- Bei Problemem mit der Index-Dateipublic void checkForAdd(String basePath, byte[] temp, long dIMin, long dIMax, long contId) throws IndexException
basePath
- Verzeichnis, in dem die Index-Datei liegttemp
- Puffer, der beim Einlesen/Schreiben der Index-Datei verwendet wirddIMin
- DatenIndex Min-WertdIMax
- DatenIndex Max-WertcontId
- Container IDIndexException
- Bei Problemem mit der Index-Dateipublic IndexResult getContainerID(String basePath, byte[] temp, long dIMin, long dIMax) throws IndexException
basePath
- Verzeichnis, in dem die Index-Datei liegttemp
- Puffer, der beim Einlesen/Schreiben der Index-Datei verwendet wirddTMin
- Min-Wert der ZeitspannedTMax
- Max-Wert der ZeitspanneIndexException
- Bei Problemem mit der IndexDateipublic long getAbsolutDIdxMin(String basePath) throws IndexException
basePath
- Verzeichnis, in dem die Index-Datei liegtIndexException
- Bei Zugriffsproblemen mit der IndexDateipublic void closeIndex(String basePath, byte[] temp) throws IndexException
basePath
- Verzeichnis, in dem die Index-Datei liegttemp
- Puffer, der beim Schreiben der Index-Datei verwendet wirdIndexException
public String toString()
private void currentEntryToBuffer(String basePath, byte[] temp) throws IndexException
IndexException
private void flush(String basePath) throws IndexException
IndexException
private void insertIntoFile(String basePath, byte[] temp) throws IndexException
IndexException
private long binaryFileSearch(RandomAccessFile raf, byte[] temp, long key) throws IndexException, IOException
raf
- Eine Referenz auf die Dateitemp
- Ein Temp Array, zum Einlesen der Datei. Je größer umso besserkey
- der gesuchte Key1IndexException
IOException
private void linearFileSearch(RandomAccessFile raf, byte[] temp, IndexResult ir, long min, long max) throws IndexException
IndexException
private static int locateEntry(byte[] buffer, long[] entry)
private void updateCurrentEntryInFile(String basePath) throws IndexException
IndexException
private long[][] getMaximaFromFile(RandomAccessFile raf, byte[] temp, int fileStart, int fileEnd) throws IOException
raf
- Random Access Filetemp
- Temp. BufferfileStart
- Erstes Byte, ab den gelesen werden sollfileEnd
- Letztes Byte, bis zu dem gelesen werden sollIOException
private int containsKey(byte[] array, int cnt, long key)
private boolean overlap(long firstMin, long firstMax, long secondMin, long secondMax)
private RandomAccessFile ifOpen(String basePath) throws IndexException
IndexException
private void ifClose(RandomAccessFile raf) throws IndexException
IndexException
private void rbInit(int entries)
private void rbLoad(RandomAccessFile raf) throws IndexException
IndexException
public void resize(int newSize, String basePath) throws IndexException
newSize
- basePath
- IndexException
private int rbElementsInbetween(int start, int stop, int ringbufferSize)
private int rbEntries()
private int rbBytePos(int pos)
private int rbCapacity()
private int rbCapacityInBytes()
private int rbEntryLength()
private boolean rbMustBeSaved()
private void rbAddCurrentEntry()
private void rbAppendCurrentEntry()
private void rbInsertElement()
private void rbExtractMaxima()
private void rbMoveEntryRight(int index)
private void rbMoveEntryLeft(int index)
private int rbFindDIMin(long key)
private long rbGetDIMin(int index)
private long rbGetDIMax(int index)
private long rbGetCID(int index)
private long[] rbGetEntry(int index)
private int rbStep(int index)
private int rbStepBack(int index)
private void rbAppendToFile(RandomAccessFile raf) throws Exception
Exception
private void osAppendToFile(OutputStream os) throws Exception
Exception
private long[] rbGetFileAnchor()
private boolean rbHasUnsavedData()
private boolean rbCacheChanged()
private int rbGetFirstUnsaved()
private String rbToString()