com.faunos.skwish.sys.mgr
Class UnitDir

java.lang.Object
  extended by com.faunos.skwish.sys.mgr.UnitDir

public class UnitDir
extends Object

A directory on the file system containing a unit of work data. The work data may include an [offset] index file, an entry [contents] file (which together make a BaseSegment), and a deleted ID file.

Author:
Babak Farhang
See Also:
FileConventions

Nested Class Summary
 class UnitDir.Seg
          A BaseSegment backed with files in the enclosing instance's directory.
 
Constructor Summary
UnitDir(File dir)
           
 
Method Summary
 boolean equals(Object obj)
          Equality semantics are based on the directory location of the instance.
 File getDeleteSetFile()
          Returns the detete-set file.
 File getDir()
          Returns the directory this unit lives in.
 File getEntryFile()
          Returns the entry file.
 File getIndexFile()
          Returns the index file.
 String getName()
          Returns the name of the directory this unit lives in.
 int getUnitNumber()
           
 int getUsageCount()
          Returns the usage count.
 boolean hasDeleteSet()
          Determines whether the delete-set file exists.
 int hashCode()
          Returns a suitable hash code as per the general contract of java.lang.Object.
 boolean hasSegment()
          Determines whether the instance has a segment.
static void initInstance(File committedDir)
          Creates an initial empty segment in the given "committed" directory.
 boolean isPurgeable()
          Determines whether this unit is purgeable.
 boolean isPurged()
          Determines whether this unit has been purged.
 boolean isSegmentPurged()
          Determines whether the segment files have been purged (deleted).
 FileBackedDeleteSet loadDeleteSet()
          Loads the delete-set in this unit, if any, and returns it in read-write mode; returns null if there is no delete-set file.
 FileBackedDeleteSet loadDeleteSet(boolean readOnly)
          Loads the delete-set in this unit, if any, and returns it in the specified read/write mode; returns null if there is no delete-set file.
 UnitDir.Seg loadSegment()
          Loads and returns an existing BaseSegment from this directory, if it exists; or null, if not found.
 boolean purge()
          Purges (deletes) this entire unit directory provided it is purgeable.
 void purgeDeleteSet()
          Purges (deletes) the delete-set file.
 void purgeSegment()
          Purges (deletes) the segment files in the correct order.
 String toString()
           
static UnitDir writeNewInstance(File parentDir, int unitNumber)
          Creates and returns a new unit in the given parent directory.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitDir

public UnitDir(File dir)
Method Detail

getDir

public File getDir()
Returns the directory this unit lives in.


getName

public String getName()
Returns the name of the directory this unit lives in.


getUsageCount

public int getUsageCount()
Returns the usage count. Used to track lingering users of this units segment after it becomes eligible for purging.


getIndexFile

public File getIndexFile()
Returns the index file.

See Also:
FileConventions.INDEX_FILE

getEntryFile

public File getEntryFile()
Returns the entry file.

See Also:
FileConventions.ENTRY_FILE

getDeleteSetFile

public File getDeleteSetFile()
Returns the detete-set file.

See Also:
FileConventions.DELETE_SET_FILE

purgeSegment

public void purgeSegment()
Purges (deletes) the segment files in the correct order.


isSegmentPurged

public boolean isSegmentPurged()
Determines whether the segment files have been purged (deleted). (The instance may never have had a segment.)


hasSegment

public boolean hasSegment()
Determines whether the instance has a segment.


purgeDeleteSet

public void purgeDeleteSet()
Purges (deletes) the delete-set file.


hasDeleteSet

public boolean hasDeleteSet()
Determines whether the delete-set file exists.


isPurgeable

public boolean isPurgeable()
Determines whether this unit is purgeable. An instance is purgeable if it neither has a segment, nor delete-set.


purge

public boolean purge()
Purges (deletes) this entire unit directory provided it is purgeable.

Returns:
true, if and only if this instance was purgeable, and has not been already purged

isPurged

public boolean isPurged()
Determines whether this unit has been purged. A unit is purged once its directory no longer exists on the file system.


loadSegment

public UnitDir.Seg loadSegment()
                        throws IOException
Loads and returns an existing BaseSegment from this directory, if it exists; or null, if not found.

Throws:
IOException

loadDeleteSet

public FileBackedDeleteSet loadDeleteSet()
                                  throws IOException
Loads the delete-set in this unit, if any, and returns it in read-write mode; returns null if there is no delete-set file.

Throws:
IOException

loadDeleteSet

public FileBackedDeleteSet loadDeleteSet(boolean readOnly)
                                  throws IOException
Loads the delete-set in this unit, if any, and returns it in the specified read/write mode; returns null if there is no delete-set file.

Parameters:
readOnly - true, if the delete-set is to be returned in read-only mode; false, if to be returned in read-write mode.
Throws:
IOException

equals

public boolean equals(Object obj)
Equality semantics are based on the directory location of the instance.

Overrides:
equals in class Object
Returns:
true, if and only if the other object is an instance of this class and its directory is the same as this one.

hashCode

public int hashCode()
Returns a suitable hash code as per the general contract of java.lang.Object.

Overrides:
hashCode in class Object
See Also:
equals(Object)

toString

public String toString()
Overrides:
toString in class Object

writeNewInstance

public static UnitDir writeNewInstance(File parentDir,
                                       int unitNumber)
                                throws IOException
Creates and returns a new unit in the given parent directory.

Parameters:
parentDir - the parent directory in which the instance will be created; must be an existing directory
unitNumber - the unit number associated with numbered naming convention for unit directories
Throws:
IOException
See Also:
FileConventions.toUnitDirname(int)

initInstance

public static void initInstance(File committedDir)
                         throws IOException
Creates an initial empty segment in the given "committed" directory. The segment files are closed on return.

Throws:
IOException

getUnitNumber

public int getUnitNumber()


SourceForge.net Logo