Class QueueBlock


  • public class QueueBlock
    extends Object
    This class represents a block of the queue. Each block is a file in the disk.
    • Constructor Detail

      • QueueBlock

        public QueueBlock​(String queueDirectoryPath,
                          String fileName,
                          long length)
                   throws PersistentQueueException
        This constructor is to be used when creating a new block.
        Parameters:
        queueDirectoryPath - path of the queue directory
        fileName - name of the file
        length - length of the file
        Throws:
        PersistentQueueException - if an error occurs while creating the block.
    • Method Detail

      • initClass

        public static void initClass​(String queueDirectoryPath)
        This method is to be used when initializing the class.
        Parameters:
        queueDirectoryPath - path of the queue directory
      • loadBlock

        public static QueueBlock loadBlock​(String directoryPath,
                                           String fileName)
                                    throws PersistentQueueException
        This method is to be used when loading the next queue block to memory.
        Parameters:
        directoryPath - path of the queue directory
        fileName - name of the file
        Returns:
        QueueBlock next queue block
        Throws:
        PersistentQueueException - if an error occurs while creating the block.
      • canAppend

        public boolean canAppend​(int length)
        Returns if the block can append the given length of data.
        Parameters:
        length - length of the data
        Returns:
        boolean if the block can append the given length of data.
      • hasUnprocessedItems

        public boolean hasUnprocessedItems()
        Returns if the block has unprocessed items.
        Returns:
        boolean if the block has unprocessed items.
      • append

        public boolean append​(byte[] data)
        Appends the given data to the block.
        Parameters:
        data - byte stream to be appended
        Returns:
        boolean if the append operation was successful.
      • consume

        public byte[] consume()
        Consumes the next item in the block.
        Returns:
        byte stream of the next item
      • peekNextItem

        public byte[] peekNextItem()
        Peeks the next item in the block without consuming.
        Returns:
        byte stream of the next item
      • getFileName

        public String getFileName()
        Returns the name of the file relevant to the block.
        Returns:
        name of the block
      • setValuesToDefault

        public void setValuesToDefault()
        Resets the block.