org.deckfour.xes.nikefs2
Class NikeFS2VirtualFileSystem

java.lang.Object
  extended by org.deckfour.xes.nikefs2.NikeFS2VirtualFileSystem
All Implemented Interfaces:
NikeFS2StorageProvider

public class NikeFS2VirtualFileSystem
extends Object
implements NikeFS2StorageProvider

Virtual file system authority, managing swap files and virtual file abstractions. Implements the storage provider interface for use by file abstractions, and performs cleanup after a shutdown of the host application. This class must be used as a singleton. There is no need for multiple virtual file systems per application. A single VFS instance operates with maximum efficiency, and guarantees that no data corruption or swap loss will occur.

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

Field Summary
protected  List<NikeFS2BlockProvider> blockProviders
          List of block providers, i.e.
protected  int blockSize
          Block size, in bytes, of virtual storage blocks.
protected static NikeFS2VirtualFileSystem instance
          The singleton VFS instance.
protected  int swapFileSize
          Size of swap files which are used to provide blocks.
protected  boolean useLazyCopies
          Flag determining whether to use soft copies for virtual file duplication.
 
Method Summary
 NikeFS2Block allocateBlock()
          Allocates a new virtual storage block from this virtual file system instance.
 int blockSize()
          Returns the block size of this VFS.
 NikeFS2RandomAccessStorage createStorage()
          Creates a new empty random access storage, which is suitable for storing byte sequences and primitive data types.
static NikeFS2VirtualFileSystem instance()
          Singleton access method.
 void setBlockSize(int bytes)
          Sets the block size of the virtual file system.
 void setSwapFileSize(int bytes)
          Sets the swap file size of the virtual file system.
 void setUseLazyCopies(boolean useLazyCopies)
          Sets this VFS's property of whether to use soft copies for virtual file duplication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

protected static NikeFS2VirtualFileSystem instance
The singleton VFS instance.


blockSize

protected int blockSize
Block size, in bytes, of virtual storage blocks. Default value is 2048, i.e. 2kB.


swapFileSize

protected int swapFileSize
Size of swap files which are used to provide blocks. Default is 67108864, i.e. 64 MB.


useLazyCopies

protected boolean useLazyCopies
Flag determining whether to use soft copies for virtual file duplication. This greatly enhances performance with negligible memory penalties, thus the default value is true.


blockProviders

protected List<NikeFS2BlockProvider> blockProviders
List of block providers, i.e. currently used swap files that serve for providing storage blocks to virtual file abstractions.

Method Detail

instance

public static NikeFS2VirtualFileSystem instance()
Singleton access method.

Returns:
The singleton instance.

setUseLazyCopies

public void setUseLazyCopies(boolean useLazyCopies)
Sets this VFS's property of whether to use soft copies for virtual file duplication. This will only affect newly created virtual files.

Parameters:
useLazyCopies - Whether to use soft copies for virtual file duplication.

setSwapFileSize

public void setSwapFileSize(int bytes)
Sets the swap file size of the virtual file system. (used henceforth until successive change).

Parameters:
bytes - Size of swap files, in bytes.

setBlockSize

public void setBlockSize(int bytes)
Sets the block size of the virtual file system. (used henceforth until successive change).

Parameters:
bytes - Size of blocks, in bytes.

createStorage

public NikeFS2RandomAccessStorage createStorage()
                                         throws IOException
Description copied from interface: NikeFS2StorageProvider
Creates a new empty random access storage, which is suitable for storing byte sequences and primitive data types.

Specified by:
createStorage in interface NikeFS2StorageProvider
Returns:
A newly created random access storage.
Throws:
IOException

blockSize

public int blockSize()
Returns the block size of this VFS.

Returns:
The size of virtual storage blocks served by this VFS, in bytes.

allocateBlock

public NikeFS2Block allocateBlock()
                           throws IOException
Allocates a new virtual storage block from this virtual file system instance. If no currently allocated swap file can provide any more storage blocks, a new swap file will be allocated.

Returns:
An empty storage block abstraction.
Throws:
IOException