Class SequenceBlock

java.lang.Object
org.rostore.v2.seq.SequenceBlock
All Implemented Interfaces:
AutoCloseable, Closeable
Direct Known Subclasses:
FixSizeEntryBlock

public abstract class SequenceBlock extends Object implements Closeable
Represents a block that is embedded in BlockSequence.

This is wrapper object of the block. To move from one block to another the moveTo(int) is used. The instance of the block is reused, but it points to another block.

  • Constructor Details

    • SequenceBlock

      protected SequenceBlock(BlockSequence blockSequence)
  • Method Details

    • getBlockSequence

      public BlockSequence getBlockSequence()
    • load

      public static <T extends SequenceBlock> T load(BlockProvider blockProvider, long startIndex, Function<BlockSequence<T>,T> factory, BlockType blockType)
      Loads block sequence and initialize a specific kind of sequence block on its basis.
      Type Parameters:
      T - the type of the sequence's block inherited object
      Parameters:
      blockProvider - the block provider be used in the sequence operations
      startIndex - the index of the first block in the sequence
      factory - the factory that creates a specific variant of sequence block based on the sequence
      blockType - the block type of the blocks belonging to the sequence
      Returns:
      a sequence block as created by the factory
    • create

      public static <T extends SequenceBlock> T create(BlockProvider blockProvider, Function<BlockSequence<T>,T> factory, BlockType blockType)
      Creates a new block sequence and initialize a sequence block on its basis
      Type Parameters:
      T - the type of the sequence's block inherited object
      Parameters:
      blockProvider - the block provider be used in the sequence operations, allocation of the blocks for the sequence will also be requested over the associated allocator BlockProvider.getBlockAllocator()
      factory - the factory that creates a specific variant of sequence block based on the sequence
      blockType - the block type of the blocks belonging to the sequence
      Returns:
      a sequence block as created by the factory
    • create

      public static <T extends SequenceBlock> T create(BlockProvider blockProvider, CatalogBlockIndices catalogBlockIndices, Function<BlockSequence<T>,T> factory, BlockType blockType)
      Creates a new block sequence and initialize a sequence block on its basis
      Type Parameters:
      T - the type of the sequence's block inherited object
      Parameters:
      blockProvider - the block provider be used in the sequence operations, allocation of the blocks for the sequence will also be requested over the associated allocator BlockProvider.getBlockAllocator()
      catalogBlockIndices - the initial set of blocks that will be used by the sequence
      factory - the factory that creates a specific variant of sequence block based on the sequence
      blockType - the block type of the blocks belonging to the sequence
      Returns:
      a sequence block as created by the factory
    • getHeaderSize

      public int getHeaderSize()
      The size of the header of the current block
      Returns:
      the size of header in bytes
    • previous

      public void previous()
      Moves the pointer to the previous block in the sequence.
    • next

      public void next()
      Moves the pointer to the next block in the sequence.
    • last

      public void last()
      Moves the pointer to the last used block in the sequence.
    • root

      public void root()
      Moves the pointer to the root block in the sequence.
    • invalidate

      public void invalidate()
      Moves the pointer to invalid index, marks the block as invalid.
    • moveTo

      public void moveTo(int seqIndex)
      Moves the pointer to the specific block in the sequence
      Parameters:
      seqIndex - the relative index in the sequence of the block
    • isRoot

      public boolean isRoot()
      Checks if the current block is the first block of the sequence
      Returns:
      true if the pointer points to the first block
    • getIndex

      public int getIndex()
      Provides the current pointer where it points
      Returns:
      the index in the sequence this sequence block is currently pointing to
    • invalid

      public boolean invalid()
      Checks if the pointer points to invalid block
      Returns:
      true if block is invalid
    • valid

      public boolean valid()
      Checks if the pointer points to valid block
      Returns:
      true if block is valid
    • getBlock

      public Block getBlock()
      Get the block this sequence's block internal pointer points to
      Returns:
      block
    • delete

      public void delete()
      Removes the current block and mark it as free.

      Function deallocates to the sequence's space.

    • 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.

    • isUnused

      protected abstract boolean isUnused()
      Provides an indication if current block does not contain any data
      Returns:
      true if no entries are currently added to block
    • clean

      protected void clean()
    • close

      public void close()
      Closes an underlying sequence
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getStatus

      public Status getStatus()
      Provides a status of the block sequence
      Specified by:
      getStatus in interface Closeable
      Returns:
      the status of the block sequence