Class ScatteringStoreDataAccessor

  • All Implemented Interfaces:
    StoreDataAccessor

    public class ScatteringStoreDataAccessor
    extends java.lang.Object
    implements StoreDataAccessor
    An implementation of StoreDataAccessor that scatters the addressible data resource across multiple files in the file system. When one store data resource reaches a certain threshold size, the content 'flows' over to the next file.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ScatteringStoreDataAccessor.FileSlice
      An object that contains information about a file slice.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String file_name
      The name of the file in the file system minus the extension.
      private java.lang.String first_ext
      The extension of the first file in the sliced set.
      private java.lang.Object lock
      A lock when modifying the true_data_size, and slice_list.
      private long max_slice_size
      The maximum size a file slice can grow too before a new slice is created.
      private boolean open
      Set when the store is openned.
      private java.io.File path
      The path of this store in the file system.
      private java.util.ArrayList slice_list
      The list of RandomAccessFile objects for each file that represents a slice of the store.
      private long true_file_length
      The current actual physical size of the store data on disk.
    • Constructor Summary

      Constructors 
      Constructor Description
      ScatteringStoreDataAccessor​(java.io.File path, java.lang.String file_name, java.lang.String first_ext, long max_slice_size)
      Constructs the store data accessor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying data area representation.
      void convertToScatteringStore​(java.io.File f)
      Given a file, this will convert to a scattering file store with files no larger than the maximum slice size.
      private int countStoreFiles()
      Counts the number of files in the file store that represent this store.
      private StoreDataAccessor createSliceDataAccessor​(java.io.File file)
      Creates a StoreDataAccessor object for accessing a given slice.
      boolean delete()
      Deletes the data area resource.
      private long discoverSize()
      Discovers the size of the data resource (doesn't require the file to be open).
      boolean exists()
      Returns true if the resource exists.
      long getSize()
      Returns the current size of the underlying data area.
      void open​(boolean read_only)
      Opens the underlying data area representation.
      void read​(long position, byte[] buf, int off, int len)
      Reads a block of data from the underlying data area at the given position into the byte array at the given offset.
      void setSize​(long length)
      Sets the size of the underlying data area to the given size.
      private java.io.File slicePartFile​(int i)
      Given an index value, this will return a File object for the nth slice in the file system.
      void synch()
      Synchronizes the data area by forcing any data out of the OS buffers onto the disk.
      void write​(long position, byte[] buf, int off, int len)
      Writes a block of data to the underlying data area from the byte array at the given offset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • path

        private final java.io.File path
        The path of this store in the file system.
      • file_name

        private final java.lang.String file_name
        The name of the file in the file system minus the extension.
      • first_ext

        private final java.lang.String first_ext
        The extension of the first file in the sliced set.
      • max_slice_size

        private final long max_slice_size
        The maximum size a file slice can grow too before a new slice is created.
      • slice_list

        private java.util.ArrayList slice_list
        The list of RandomAccessFile objects for each file that represents a slice of the store. (FileSlice objects)
      • true_file_length

        private long true_file_length
        The current actual physical size of the store data on disk.
      • lock

        private final java.lang.Object lock
        A lock when modifying the true_data_size, and slice_list.
      • open

        private boolean open
        Set when the store is openned.
    • Constructor Detail

      • ScatteringStoreDataAccessor

        public ScatteringStoreDataAccessor​(java.io.File path,
                                           java.lang.String file_name,
                                           java.lang.String first_ext,
                                           long max_slice_size)
        Constructs the store data accessor.
    • Method Detail

      • convertToScatteringStore

        public void convertToScatteringStore​(java.io.File f)
                                      throws java.io.IOException
        Given a file, this will convert to a scattering file store with files no larger than the maximum slice size.
        Throws:
        java.io.IOException
      • slicePartFile

        private java.io.File slicePartFile​(int i)
        Given an index value, this will return a File object for the nth slice in the file system. For example, given '4' will return [file name].004, given 1004 will return [file name].1004, etc.
      • countStoreFiles

        private int countStoreFiles()
        Counts the number of files in the file store that represent this store.
      • createSliceDataAccessor

        private StoreDataAccessor createSliceDataAccessor​(java.io.File file)
        Creates a StoreDataAccessor object for accessing a given slice.
      • discoverSize

        private long discoverSize()
                           throws java.io.IOException
        Discovers the size of the data resource (doesn't require the file to be open).
        Throws:
        java.io.IOException
      • open

        public void open​(boolean read_only)
                  throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Opens the underlying data area representation. If the resource doesn't exist then it is created and the size is set to 0.
        Specified by:
        open in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Closes the underlying data area representation.
        Specified by:
        close in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • delete

        public boolean delete()
        Description copied from interface: StoreDataAccessor
        Deletes the data area resource. Returns true if the delete was successful.
        Specified by:
        delete in interface StoreDataAccessor
      • read

        public void read​(long position,
                         byte[] buf,
                         int off,
                         int len)
                  throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Reads a block of data from the underlying data area at the given position into the byte array at the given offset.
        Specified by:
        read in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • write

        public void write​(long position,
                          byte[] buf,
                          int off,
                          int len)
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Writes a block of data to the underlying data area from the byte array at the given offset.
        Specified by:
        write in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • setSize

        public void setSize​(long length)
                     throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Sets the size of the underlying data area to the given size. If the size of the data area is increased, the content between the old size and the new size is implementation defined.
        Specified by:
        setSize in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • getSize

        public long getSize()
                     throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Returns the current size of the underlying data area.
        Specified by:
        getSize in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • synch

        public void synch()
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Synchronizes the data area by forcing any data out of the OS buffers onto the disk.
        Specified by:
        synch in interface StoreDataAccessor
        Throws:
        java.io.IOException