org.processmining.framework.log.rfb.io
Class VirtualFileSystem

java.lang.Object
  extended by org.processmining.framework.log.rfb.io.VirtualFileSystem
All Implemented Interfaces:
StorageProvider

public class VirtualFileSystem
extends java.lang.Object
implements StorageProvider

This class implements a virtual file system, from which new files, as random access storage containers, can be obtained. These files are only possible to grow, i.e. cannot be compacted other than copying them to a newly allocated file.

The virtual file system creates and manages blocks and their size dynamically, however during the runtime of the virtual machine the amount of memory used by the virtual file system does not decrease, i.e. there is no garbage collection.

Virtual file systems are usually used as singleton, as the file system itself is an abstraction and does not group logical entities of a specific class. However, if you intend to use several, separated virtual file systems, adequate constructors are provided.

The virtual file system makes a best effort, to delete the backing swap files from disk at the moment of garbage collection or, again, at virtual machine shutdown.

Author:
Christian W. Guenther (christian at deckfour dot org)

Nested Class Summary
protected static class VirtualFileSystem.ShutdownHook
          This class implements a shutdown hook, which will clear all swap files from the file system at the moment, at which the JVM shuts down.
 
Field Summary
static int DEFAULT_SWAP_FILE_SIZE
          32 Megabytes default swap file size
protected static VirtualFileSystem instance
          Singleton instance
static java.lang.String SWAP_PREFIX
          Default prefix for swap files
static java.lang.String SWAP_SUFFIX
          Default suffix for swap files
protected  java.io.File swapDir
          Location where to keep swap files.
protected  java.util.ArrayList<BlockDataStorage> swapFiles
          List of allocated swap files.
protected  int swapFileSize
          Size of a swap file.
 
Constructor Summary
VirtualFileSystem()
          Creates a new virtual file system with default settings.
VirtualFileSystem(int aSwapFileSize, java.io.File aSwapDirectory)
          Creates a customized instance of a virtual file system.
 
Method Summary
 StorageBlock allocateBlock(int minSize)
          Allocates a new block from the first free swap file.
 RandomAccessStorage createStorage()
          Creates a new empty random access storage, which is suitable for storing byte sequences and primitive data types.
protected  void finalize()
          Remove swap files when this instance is garbage collected.
 BlockDataStorageInfo[] getSwapFileInfos()
          Returns an array of information containers about each swap file currently used by this virtual file system
 BlockDataStorage[] getSwapFiles()
          Returns an array of current swap files used by this virtual file system
static VirtualFileSystem instance()
          Singleton access method.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SWAP_FILE_SIZE

public static final int DEFAULT_SWAP_FILE_SIZE
32 Megabytes default swap file size

See Also:
Constant Field Values

SWAP_PREFIX

public static final java.lang.String SWAP_PREFIX
Default prefix for swap files

See Also:
Constant Field Values

SWAP_SUFFIX

public static final java.lang.String SWAP_SUFFIX
Default suffix for swap files

See Also:
Constant Field Values

instance

protected static VirtualFileSystem instance
Singleton instance


swapFileSize

protected int swapFileSize
Size of a swap file.


swapDir

protected java.io.File swapDir
Location where to keep swap files.


swapFiles

protected java.util.ArrayList<BlockDataStorage> swapFiles
List of allocated swap files.

Constructor Detail

VirtualFileSystem

public VirtualFileSystem()
Creates a new virtual file system with default settings.


VirtualFileSystem

public VirtualFileSystem(int aSwapFileSize,
                         java.io.File aSwapDirectory)
Creates a customized instance of a virtual file system.

Parameters:
aSwapFileSize - Size of individual swap files in bytes.
aSwapDirectory - Directory where to create and keep the swap files.
Method Detail

instance

public static VirtualFileSystem instance()
Singleton access method.

Returns:
The singleton instance.

createStorage

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

Specified by:
createStorage in interface StorageProvider
Returns:
A newly created random access storage.

getSwapFiles

public BlockDataStorage[] getSwapFiles()
Returns an array of current swap files used by this virtual file system

Returns:
Array of currently used swap files

getSwapFileInfos

public BlockDataStorageInfo[] getSwapFileInfos()
Returns an array of information containers about each swap file currently used by this virtual file system

Returns:
array of information containers, one for each swap file used

allocateBlock

public StorageBlock allocateBlock(int minSize)
                           throws java.io.IOException
Allocates a new block from the first free swap file. The size of the returned block is undefined, but can be inquired from the returned instance. If no block can be allocated from an existing swap file storage, a new one is created.

This method is for use by file metaphors using the virtual file system as storage implementation. It is not intended to allocate blocks, if you intend to use them at a higher level of abstraction (byte buffers, files,...)

Parameters:
minSize - The minimum size of the returned storage block. Can be 0 or negative, in this case the size of the returned block is not checked.
Returns:
A newly allocated block.
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Remove swap files when this instance is garbage collected.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable