de.bsvrz.ars.ars.persistence
Class ContainerBackupIndex.ContainerBackupIndexImplementation

java.lang.Object
  extended by de.bsvrz.ars.ars.persistence.ContainerBackupIndex.ContainerBackupIndexImplementation
Enclosing class:
ContainerBackupIndex

private static final class ContainerBackupIndex.ContainerBackupIndexImplementation
extends Object

Eigentliche Implementierung des ContainerBackupIndex. wird von der ContainerBackupIndex-Klasse gekapselt um einen sicheren Referenzzähler zu ermöglichen. Zu den Zwecken der Threadsicherheit wird für jede ContainerBackupIndex-Datei maximal eine Instanz erzeugt und verwaltet. Jede Instanz kann von mehreren ContainerBackupIndex-Objekten verwendet werden. Zu diesem Zweck implementiert diese Klasse einen Referenzzähler.


Nested Class Summary
private static class ContainerBackupIndex.ContainerBackupIndexImplementation.IndexEntry
          Hilfsklasse die einen einzelnen Dateneintrag speichert.
 
Field Summary
private  File _file
           
private  Object _fileLock
           
private static HashMap<File,ContainerBackupIndex.ContainerBackupIndexImplementation> _openFiles
          Aus Synchronitätsgründen muss sichergestellt sein, dass wenn eine Indexdatei an zwei verschiedenen Stellen gleichzeitig angefragt wird, beide Threads das selbe Objekt erhalten.
private  int _referenceCount
          Anzahl der Referenzen
private static int CONTAINER_DELETED_FROM_INDEX
          Markiert einen ungültigen Index-Eintrag.
private static int CONTAINER_TO_SAVE
          Legt fest, dass der Container im Index geschlossen ist und gesichert werden kann (z.B.
private static int CURRENT_FILE_VERSION
           
private static int ENTRY_SIZE
           
private static int HEADER_MEDIUM_ID_SIZE
           
private static int HEADER_NUM_GAPS_SIZE
           
private static int HEADER_NUM_SORTED_ENTRIES_SIZE
           
private static int HEADER_POS_MEDIUM_ID
           
private static int HEADER_POS_NUM_GAPS
           
private static int HEADER_POS_NUM_SORTED_ENTRIES
           
private static int HEADER_SIZE
           
private static int HEADER_VERSION_SIZE
           
private static int SIZE_BYTE
           
private static int SIZE_INTEGER
           
private static int SIZE_LONG
           
 
Constructor Summary
private ContainerBackupIndex.ContainerBackupIndexImplementation(File file)
           
 
Method Summary
private  void addReference()
           
 void appendContainerID(long containerID)
          Fügt einen Container hinzu
static ContainerBackupIndex.ContainerBackupIndexImplementation createNewContainerBackupIndex(File path)
          Erstellt eine neuen, leeren ContainerBackupIndexImplementation im angegebenen Verzeichnis.
static boolean deleteContainerBackupIndex(File path)
          Löscht einen ContainerBackupIndex aus dem angegeben Verzeichnis
static ContainerBackupIndex.ContainerBackupIndexImplementation getContainerBackupIndex(File path)
          Gibt eine ContainerBackupIndexImplementation aus einem angegebenen Verzeichnis zurück
static ContainerBackupIndex.ContainerBackupIndexImplementation getContainerBackupIndex(String path)
          Gibt eine ContainerBackupIndexImplementation aus einem angegebenen Verzeichnis zurück
 List<Long> getContainerIDs()
          Gibt alle ContainerIDs im Index zurück
private static ContainerBackupIndex.ContainerBackupIndexImplementation getInstance(File file)
          Holt zu einer angegebenen Datei eine ContainerBackupIndexImplementation-Instanz.
 int getMaxMedienID()
           
 boolean removeContainerID(long containerID, int mediumID)
          Entfernt eine ContainerID aus dem Index
private  boolean removeContainerIDFast(long containerID, RandomAccessFile randomAccessFile, int numOfSortedEntries, int numOfGaps)
          Markiert einen Container-Eintrag als ungültig
private  boolean removeContainerIDInSortedArea(long containerID, RandomAccessFile randomAccessFile, int numOfSortedEntries, int numOfGaps)
          Löscht einen Container-Eintrag aus dem sortierten Bereich
private  boolean removeContainerIDInUnsortedArea(long containerID, RandomAccessFile randomAccessFile, int numOfSortedEntries, int numOfGaps)
          Löscht einen Container-Eintrag aus dem unsortierten Bereich
private  boolean removeContainerIDWithRebuild(long containerIdToRemove, RandomAccessFile randomAccessFile)
          Löscht einen Container-Eintrag aus der Datei und sortiert dabei den kompletten Datenbereich neu
private  void removeReference()
           
private  void reset()
          Entfernt alle Daten aus der ContainerBackupIndexImplementation
 void setMaxMedienID(int mediumID)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CURRENT_FILE_VERSION

private static final int CURRENT_FILE_VERSION
See Also:
Constant Field Values

_file

private File _file

_fileLock

private final Object _fileLock

CONTAINER_TO_SAVE

private static final int CONTAINER_TO_SAVE
Legt fest, dass der Container im Index geschlossen ist und gesichert werden kann (z.B. wenn die Parametrierung es verlangt)

See Also:
Constant Field Values

CONTAINER_DELETED_FROM_INDEX

private static final int CONTAINER_DELETED_FROM_INDEX
Markiert einen ungültigen Index-Eintrag. Wenn ein Container aus dem Index gelöscht wird, wird er zunächst mit diesem Flag markiert Erst wenn die Anzahl der ungültigen Einträge einen bestimmten Wert überschreitet, wird die gesamte Datei neu geschrieben/komprimiert.

See Also:
Constant Field Values

_openFiles

private static final HashMap<File,ContainerBackupIndex.ContainerBackupIndexImplementation> _openFiles
Aus Synchronitätsgründen muss sichergestellt sein, dass wenn eine Indexdatei an zwei verschiedenen Stellen gleichzeitig angefragt wird, beide Threads das selbe Objekt erhalten. Daher werden hier die offenen Indexdateien verwaltet.


_referenceCount

private int _referenceCount
Anzahl der Referenzen


SIZE_INTEGER

private static final int SIZE_INTEGER
See Also:
Constant Field Values

SIZE_BYTE

private static final int SIZE_BYTE
See Also:
Constant Field Values

SIZE_LONG

private static final int SIZE_LONG
See Also:
Constant Field Values

HEADER_VERSION_SIZE

private static final int HEADER_VERSION_SIZE
See Also:
Constant Field Values

HEADER_MEDIUM_ID_SIZE

private static final int HEADER_MEDIUM_ID_SIZE
See Also:
Constant Field Values

HEADER_NUM_SORTED_ENTRIES_SIZE

private static final int HEADER_NUM_SORTED_ENTRIES_SIZE
See Also:
Constant Field Values

HEADER_NUM_GAPS_SIZE

private static final int HEADER_NUM_GAPS_SIZE
See Also:
Constant Field Values

HEADER_POS_MEDIUM_ID

private static final int HEADER_POS_MEDIUM_ID
See Also:
Constant Field Values

HEADER_POS_NUM_SORTED_ENTRIES

private static final int HEADER_POS_NUM_SORTED_ENTRIES
See Also:
Constant Field Values

HEADER_POS_NUM_GAPS

private static final int HEADER_POS_NUM_GAPS
See Also:
Constant Field Values

HEADER_SIZE

private static final int HEADER_SIZE
See Also:
Constant Field Values

ENTRY_SIZE

private static final int ENTRY_SIZE
See Also:
Constant Field Values
Constructor Detail

ContainerBackupIndex.ContainerBackupIndexImplementation

private ContainerBackupIndex.ContainerBackupIndexImplementation(File file)
Method Detail

addReference

private void addReference()

removeReference

private void removeReference()

getContainerBackupIndex

public static ContainerBackupIndex.ContainerBackupIndexImplementation getContainerBackupIndex(File path)
Gibt eine ContainerBackupIndexImplementation aus einem angegebenen Verzeichnis zurück

Parameters:
path - Verzeichnis
Returns:
ein ContainerBackupIndex oder null falls er noch nicht existiert

getContainerBackupIndex

public static ContainerBackupIndex.ContainerBackupIndexImplementation getContainerBackupIndex(String path)
Gibt eine ContainerBackupIndexImplementation aus einem angegebenen Verzeichnis zurück

Parameters:
path - Verzeichnis
Returns:
ein ContainerBackupIndex oder null falls er noch nicht existiert

getInstance

private static ContainerBackupIndex.ContainerBackupIndexImplementation getInstance(File file)
Holt zu einer angegebenen Datei eine ContainerBackupIndexImplementation-Instanz. Entweder aus der _openFiles-HashMap oder es wird ein neues Objekt erstellt

Parameters:
file - Datei
Returns:
die ContainerBackupIndexImplementation

createNewContainerBackupIndex

public static ContainerBackupIndex.ContainerBackupIndexImplementation createNewContainerBackupIndex(File path)
                                                                                             throws IOException
Erstellt eine neuen, leeren ContainerBackupIndexImplementation im angegebenen Verzeichnis. Ein eventuell bereits vorhandener wird überschrieben.

Parameters:
path - Verzeichnis
Returns:
der neue ContainerBackupIndex
Throws:
IOException - IO-Fehler

deleteContainerBackupIndex

public static boolean deleteContainerBackupIndex(File path)
Löscht einen ContainerBackupIndex aus dem angegeben Verzeichnis

Parameters:
path - Verzeichnis
Returns:
true wenn das Löschen erfolgreich war und die Datei vorher existierte

reset

private void reset()
            throws IOException
Entfernt alle Daten aus der ContainerBackupIndexImplementation

Throws:
IOException - IO-Fehler

appendContainerID

public void appendContainerID(long containerID)
                       throws IOException
Fügt einen Container hinzu

Parameters:
containerID - Container-ID
Throws:
IOException - IO-Fehler

removeContainerID

public boolean removeContainerID(long containerID,
                                 int mediumID)
                          throws IOException
Entfernt eine ContainerID aus dem Index

Parameters:
containerID - ContainerID die zu entfernen ist.
mediumID - MediumID im Header, die evtl. erhöht werden muss
Returns:
True falls erfolgreich, false falls nicht gefunden
Throws:
IOException - IO-Fehler

getMaxMedienID

public int getMaxMedienID()
                   throws IOException
Throws:
IOException

setMaxMedienID

public void setMaxMedienID(int mediumID)
                    throws IOException
Throws:
IOException

removeContainerIDFast

private boolean removeContainerIDFast(long containerID,
                                      RandomAccessFile randomAccessFile,
                                      int numOfSortedEntries,
                                      int numOfGaps)
                               throws IOException
Markiert einen Container-Eintrag als ungültig

Parameters:
containerID - ContainerID
randomAccessFile - geöffnete Datei
numOfSortedEntries - Anzahl Sortierte Einträge
numOfGaps - Anzahl ungültige Einträge
Returns:
True wenn der Container gelöscht wurde
Throws:
IOException - IO-Fehler

removeContainerIDInSortedArea

private boolean removeContainerIDInSortedArea(long containerID,
                                              RandomAccessFile randomAccessFile,
                                              int numOfSortedEntries,
                                              int numOfGaps)
                                       throws IOException
Löscht einen Container-Eintrag aus dem sortierten Bereich

Parameters:
containerID - ContainerID
randomAccessFile - geöffnete Datei
numOfSortedEntries - Anzahl Sortierte Einträge
numOfGaps - Anzahl ungültige Einträge
Returns:
True wenn der Container gelöscht wurde
Throws:
IOException - IO-Fehler

removeContainerIDInUnsortedArea

private boolean removeContainerIDInUnsortedArea(long containerID,
                                                RandomAccessFile randomAccessFile,
                                                int numOfSortedEntries,
                                                int numOfGaps)
                                         throws IOException
Löscht einen Container-Eintrag aus dem unsortierten Bereich

Parameters:
containerID - ContainerID
randomAccessFile - geöffnete Datei
numOfSortedEntries - Anzahl Sortierte Einträge
numOfGaps - Anzahl ungültige Einträge
Returns:
True wenn der Container gelöscht wurde
Throws:
IOException - IO-Fehler

removeContainerIDWithRebuild

private boolean removeContainerIDWithRebuild(long containerIdToRemove,
                                             RandomAccessFile randomAccessFile)
                                      throws IOException
Löscht einen Container-Eintrag aus der Datei und sortiert dabei den kompletten Datenbereich neu

Parameters:
containerIdToRemove - ContainerID
randomAccessFile - geöffnete Datei
Returns:
True wenn der Container gelöscht wurde
Throws:
IOException - IO-Fehler

toString

public String toString()
Overrides:
toString in class Object

getContainerIDs

public List<Long> getContainerIDs()
                           throws IOException
Gibt alle ContainerIDs im Index zurück

Returns:
Liste mit ContainerIDs
Throws:
IOException - IO-Fehler