Class NikeFS2VirtualFileSystem

  • All Implemented Interfaces:
    NikeFS2StorageProvider

    public class NikeFS2VirtualFileSystem
    extends java.lang.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 Detail

      • 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 java.util.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.
      • 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 java.io.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:
        java.io.IOException