Class FixSizeEntryBlock<T extends FixSizeEntry>

java.lang.Object
org.rostore.v2.seq.SequenceBlock
org.rostore.v2.fixsize.FixSizeEntryBlock<T>
Type Parameters:
T - a class representing the entries
All Implemented Interfaces:
AutoCloseable, Closeable

public class FixSizeEntryBlock<T extends FixSizeEntry> extends SequenceBlock
This is an extension of sequence block that maps the block area as a set of the fixed-sized entries.

All the entries are stored at the beginning of the block, so the used area of block differs from block to block.

Block stores the number of entries that has been added to the block.

The nature of the entries and their size can be different, but once set stays the same in all blocks of the sequence.

The block allows to store an extra header. The header size differentiates between the first block (the header of the first block in the sequence) and the regular block's header. This allow to store additional data before all the entries in the block.

  • Constructor Details

  • Method Details

    • getBlockProvider

      public BlockProvider getBlockProvider()
      A block provider based on the one of associated BlockSequence
      Returns:
      the block provider
    • getEntry

      public T getEntry()
      Provides an associated entry (which contain the real business logic)
      Returns:
      the entry
    • getHeaderSize

      public int getHeaderSize()
      Provides a current header's size
      Overrides:
      getHeaderSize in class SequenceBlock
      Returns:
      the size of the header
    • getRegularHeaderSize

      public int getRegularHeaderSize()
      Provides the size of all block's headers except of the first one
      Returns:
      regular size of the header in bytes
    • getFirstHeaderSize

      public int getFirstHeaderSize()
      Provides the header's size of the first block
      Returns:
      the size in bytes of the first block's header
    • getEntryCapacity

      public int getEntryCapacity()
      Provides a total entry capacity of the block
      Returns:
      the number of entries that can fit into one free block
    • throwExceptionIfInvalid

      protected void throwExceptionIfInvalid(String message)
    • addEntriesNumber

      public int addEntriesNumber(int number)
      Adds number of entries in this block
      Parameters:
      number - the number of entries to add (if positive) or remove (if negative)
      Returns:
      the total number of entries added to the current block
    • getEntriesNumber

      public int getEntriesNumber()
      Provides a number of entries added to the block
      Returns:
      number of entries
    • hasFreeSpace

      public boolean hasFreeSpace()
      Provides an indication if the current block has free space
      Returns:
      true if there is a free space for at least one additional entry
    • createNewAfter

      public void createNewAfter()
      Creates a new block after the current one and move to it.

      Allocation of the free block happens solely from the free blocks already reserved in the sequence.

      Overrides:
      createNewAfter in class SequenceBlock
    • isUnused

      protected boolean isUnused()
      Provides an indication if current block does not contain any data
      Specified by:
      isUnused in class SequenceBlock
      Returns:
      true if no entries are currently added to block
    • moveEntriesFrom

      public void moveEntriesFrom(int sourceSeqIndex, int sourceEntryStartIndex)
      Moves (appends) all entries starting from the given source block index / source entry index to the last entry in the source block to the end of this block.
      Parameters:
      sourceSeqIndex - the source index of the block within the sequence
      sourceEntryStartIndex - the index of the first entry to move
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • invalidate

      public void invalidate()
      Moves the pointer to invalid index, marks the block as invalid.
      Overrides:
      invalidate in class SequenceBlock
    • moveTo

      public void moveTo(int seqIndex)
      Sets the current location of block to the specified sequence index.

      It also will set the index of entry to the first one.

      Overrides:
      moveTo in class SequenceBlock
      Parameters:
      seqIndex - the relative index in the sequence of the block