org.deckfour.xes.nikefs2
Class NikeFS2LazyRandomAccessStorageImpl

java.lang.Object
  extended by org.deckfour.xes.nikefs2.NikeFS2RandomAccessStorageImpl
      extended by org.deckfour.xes.nikefs2.NikeFS2LazyRandomAccessStorageImpl
All Implemented Interfaces:
DataInput, DataOutput, NikeFS2RandomAccessStorage

public class NikeFS2LazyRandomAccessStorageImpl
extends NikeFS2RandomAccessStorageImpl

Lazy implementation of the random access storage in NikeFS2: Blocks are copied as late as possible (soft copies), while retaining soft links otherwise.

Author:
Christian W. Guenther (christian@deckfour.org)

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deckfour.xes.nikefs2.NikeFS2RandomAccessStorageImpl
NikeFS2RandomAccessStorageImpl.FS2BlockInputStream, NikeFS2RandomAccessStorageImpl.FS2BlockOutputStream, NikeFS2RandomAccessStorageImpl.FS2DataInputStream, NikeFS2RandomAccessStorageImpl.FS2DataOutputStream
 
Field Summary
protected  boolean isSoftCopy
          Whether this instance is still a soft copy (i.e., actually empty).
protected  NikeFS2LazyRandomAccessStorageImpl parent
          Parent storage, containing the original data.
protected  ArrayList<NikeFS2LazyRandomAccessStorageImpl> softCopies
          Child storages, which are soft copies of this instance.
 
Fields inherited from class org.deckfour.xes.nikefs2.NikeFS2RandomAccessStorageImpl
blocks, dataInputStream, dataOutputStream, pointer, size, vfs
 
Constructor Summary
NikeFS2LazyRandomAccessStorageImpl(NikeFS2LazyRandomAccessStorageImpl template)
          Creates a new instance.
NikeFS2LazyRandomAccessStorageImpl(NikeFS2VirtualFileSystem virtualFileSystem)
          Creates a new instance.
 
Method Summary
 void alertSoftCopies()
          This method alerts all child soft copies of this storage to consolidate; called prior to modification of this instance.
 void close()
          Closes the data storage container.
 void consolidateSoftCopy()
          Consolidates this soft copy prior to modification.
 NikeFS2RandomAccessStorage copy()
          Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.
 void deregisterSoftCopy(NikeFS2LazyRandomAccessStorageImpl copycat)
          This method is used by child copies to deregister with their parent.
protected  void finalize()
           
 void registerSoftCopy(NikeFS2LazyRandomAccessStorageImpl copycat)
          This method is used by child copies to register with their parent.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int b)
           
 void writeBytes(String str)
           
 void writeChar(int c)
           
 void writeChars(String str)
           
 void writeDouble(double d)
           
 void writeFloat(float f)
           
 void writeInt(int i)
           
 void writeLong(long l)
           
 void writeShort(int s)
           
 void writeUTF(String str)
           
 
Methods inherited from class org.deckfour.xes.nikefs2.NikeFS2RandomAccessStorageImpl
adjustSize, getFilePointer, length, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, skipBytes, translateToBlockNumber, translateToBlockOffset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected NikeFS2LazyRandomAccessStorageImpl parent
Parent storage, containing the original data.


isSoftCopy

protected boolean isSoftCopy
Whether this instance is still a soft copy (i.e., actually empty).


softCopies

protected ArrayList<NikeFS2LazyRandomAccessStorageImpl> softCopies
Child storages, which are soft copies of this instance.

Constructor Detail

NikeFS2LazyRandomAccessStorageImpl

public NikeFS2LazyRandomAccessStorageImpl(NikeFS2VirtualFileSystem virtualFileSystem)
Creates a new instance.

Parameters:
virtualFileSystem - Virtual file system to store data to.

NikeFS2LazyRandomAccessStorageImpl

public NikeFS2LazyRandomAccessStorageImpl(NikeFS2LazyRandomAccessStorageImpl template)
Creates a new instance.

Parameters:
template - Storage of which this instance is a soft copy.
Method Detail

registerSoftCopy

public void registerSoftCopy(NikeFS2LazyRandomAccessStorageImpl copycat)
This method is used by child copies to register with their parent.

Parameters:
copycat - The child soft copy to register.

deregisterSoftCopy

public void deregisterSoftCopy(NikeFS2LazyRandomAccessStorageImpl copycat)
This method is used by child copies to deregister with their parent.

Parameters:
copycat - The child soft copy to deregister.

alertSoftCopies

public void alertSoftCopies()
                     throws IOException
This method alerts all child soft copies of this storage to consolidate; called prior to modification of this instance. The child soft copies so alerted will detach from this instance consequently.

Throws:
IOException

consolidateSoftCopy

public void consolidateSoftCopy()
                         throws IOException
Consolidates this soft copy prior to modification. This will detach this instance from its parent, creating a true copy of its current data.

Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: NikeFS2RandomAccessStorage
Closes the data storage container. After this method has been invoked, no further access to the represented instance is allowed.

Specified by:
close in interface NikeFS2RandomAccessStorage
Overrides:
close in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

copy

public NikeFS2RandomAccessStorage copy()
                                throws IOException
Description copied from interface: NikeFS2RandomAccessStorage
Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.

Specified by:
copy in interface NikeFS2RandomAccessStorage
Overrides:
copy in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws IOException
Specified by:
writeBoolean in interface DataOutput
Overrides:
writeBoolean in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeByte

public void writeByte(int b)
               throws IOException
Specified by:
writeByte in interface DataOutput
Overrides:
writeByte in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeBytes

public void writeBytes(String str)
                throws IOException
Specified by:
writeBytes in interface DataOutput
Overrides:
writeBytes in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeChar

public void writeChar(int c)
               throws IOException
Specified by:
writeChar in interface DataOutput
Overrides:
writeChar in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeChars

public void writeChars(String str)
                throws IOException
Specified by:
writeChars in interface DataOutput
Overrides:
writeChars in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeDouble

public void writeDouble(double d)
                 throws IOException
Specified by:
writeDouble in interface DataOutput
Overrides:
writeDouble in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeFloat

public void writeFloat(float f)
                throws IOException
Specified by:
writeFloat in interface DataOutput
Overrides:
writeFloat in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeInt

public void writeInt(int i)
              throws IOException
Specified by:
writeInt in interface DataOutput
Overrides:
writeInt in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeLong

public void writeLong(long l)
               throws IOException
Specified by:
writeLong in interface DataOutput
Overrides:
writeLong in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeShort

public void writeShort(int s)
                throws IOException
Specified by:
writeShort in interface DataOutput
Overrides:
writeShort in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

writeUTF

public void writeUTF(String str)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Overrides:
writeUTF in class NikeFS2RandomAccessStorageImpl
Throws:
IOException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable