Class DiskStorageFactory


  • public class DiskStorageFactory
    extends java.lang.Object
    A mock-up of a on-disk element proxy factory.
    Author:
    Chris Dennis, Ludovic Orban
    • Field Detail

      • store

        protected volatile DiskStore store
        The store bound to this factory.
    • Constructor Detail

      • DiskStorageFactory

        public DiskStorageFactory​(Ehcache cache,
                                  RegisteredEventListeners cacheEventNotificationService)
        Constructs an disk persistent factory for the given cache and disk path.
        Parameters:
        cache - cache that fronts this factory
    • Method Detail

      • getOnDiskSizeInBytes

        public long getOnDiskSizeInBytes()
        Return this size in bytes of this factory
        Returns:
        this size in bytes of this factory
      • bind

        public void bind​(DiskStore store)
        Bind a store instance to this factory.
        Parameters:
        store - store to bind
      • free

        public void free​(java.util.concurrent.locks.Lock lock,
                         DiskStorageFactory.DiskSubstitute substitute,
                         boolean faultFailure)
        Free any manually managed resources used by this DiskStorageFactory.DiskSubstitute.
        Parameters:
        lock - the lock protecting the DiskSubstitute
        substitute - DiskSubstitute being freed.
        faultFailure - true if this DiskSubstitute should be freed because of a disk failure
      • markUsed

        protected void markUsed​(DiskStorageFactory.DiskMarker marker)
        Mark this on-disk marker as used (hooks into the file space allocation structure).
        Parameters:
        marker - on-disk marker to mark as used
      • shrinkDataFile

        protected void shrinkDataFile()
        Shrink this store's data file down to a minimal size for its contents.
      • shutdown

        protected void shutdown()
                         throws java.io.IOException
        Shuts down this disk factory.

        This shuts down the executor and then waits for its termination, before closing the data file.

        Throws:
        java.io.IOException - if an IO error occurred
      • delete

        protected void delete()
        Deletes the data file for this factory.
      • schedule

        protected <U> java.util.concurrent.Future<U> schedule​(java.util.concurrent.Callable<U> call)
        Schedule to given task on the disk writer executor service.
        Type Parameters:
        U - return type of the callable
        Parameters:
        call - callable to call
        Returns:
        Future representing the return of this call
      • read

        protected Element read​(DiskStorageFactory.DiskMarker marker)
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException
        Read the data at the given marker, and return the associated deserialized Element.
        Parameters:
        marker - marker to read
        Returns:
        deserialized Element
        Throws:
        java.io.IOException - on read error
        java.lang.ClassNotFoundException - on deserialization error
      • write

        protected DiskStorageFactory.DiskMarker write​(Element element)
                                               throws java.io.IOException
        Write the given element to disk, and return the associated marker.
        Parameters:
        element - to write
        Returns:
        marker representing the element
        Throws:
        java.io.IOException - on write error
      • free

        protected void free​(DiskStorageFactory.DiskMarker marker)
        Free the given marker to be used by a subsequent write.
        Parameters:
        marker - marker to be free'd
      • bufferFull

        public boolean bufferFull()
        Return true if the disk write queue is full.
        Returns:
        true if the disk write queue is full.
      • getDataFile

        public java.io.File getDataFile()
        Return a reference to the data file backing this factory.
        Returns:
        a reference to the data file backing this factory.
      • expireElements

        public void expireElements()
        Remove elements created by this factory if they have expired.
      • deleteFile

        protected static void deleteFile​(java.io.File f)
        Attempt to delete the corresponding file and log an error on failure.
        Parameters:
        f - the file to delete
      • create

        public DiskStorageFactory.DiskSubstitute create​(Element element)
                                                 throws java.lang.IllegalArgumentException
        Create a disk substitute for an element
        Parameters:
        element - the element to create a disk substitute for
        Returns:
        The substitute element
        Throws:
        java.lang.IllegalArgumentException - if element cannot be substituted
      • created

        public boolean created​(java.lang.Object object)
        Returns true if this factory created the given object.
        Parameters:
        object - object to check
        Returns:
        true if object created by this factory
      • unbind

        public void unbind()
        Unbinds a store instance from this factory
      • flush

        public java.util.concurrent.Future<java.lang.Void> flush()
        Schedule a flush (index write) for this factory.
        Returns:
        a Future
      • getOnDiskSize

        public int getOnDiskSize()
        Return the number of on-disk elements
        Returns:
        the number of on-disk elements
      • setOnDiskCapacity

        public void setOnDiskCapacity​(int capacity)
        Set the maximum on-disk capacity for this factory.
        Parameters:
        capacity - the maximum on-disk capacity for this factory.
      • getIndexFile

        public java.io.File getIndexFile()
        Return the index file for this store.
        Returns:
        the index file