Class PersistentQueue<T extends Serializable>

  • Type Parameters:
    T - type of the object to be stored in the queue.
    All Implemented Interfaces:
    AutoCloseable

    public class PersistentQueue<T extends Serializable>
    extends Object
    implements AutoCloseable
    This class implements a file based queue which can be used to store objects in serialized form in a persistent manner and consumed later.
    • Constructor Detail

      • PersistentQueue

        public PersistentQueue​(String queueDirectoryPath,
                               long maxDiskSpaceInBytes,
                               long maxBatchSizeInBytes)
                        throws PersistentQueueException
        Constructor of the PersistentQueue class.
        Parameters:
        queueDirectoryPath - path of the queue directory.
        maxDiskSpaceInBytes - maximum disk space that can be used by the queue.
        maxBatchSizeInBytes - maximum size of a single queue block.
        Throws:
        PersistentQueueException - if an error occurs while creating the queue.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Checks if the queue is empty.
        Returns:
        boolean if the queue is empty.
      • isFull

        public boolean isFull()
        Checks if the queue is full.
        Returns:
        boolean if the queue is full.
      • calculateDiskUsage

        public long calculateDiskUsage()
                                throws PersistentQueueException
        Loops through each file in the queue directory and calculates the disk usage of the queue.
        Returns:
        disk usage of the queue.
        Throws:
        PersistentQueueException - if an error occurs while calculating the disk usage.
      • getUsedSpaceFraction

        public float getUsedSpaceFraction()
        Returns the fraction of the disk space used by the queue.
        Returns:
        fraction of the disk space used by the queue.