Class BlockContainer

java.lang.Object
org.rostore.v2.media.block.container.BlockContainer
All Implemented Interfaces:
AutoCloseable, Closeable, Committable

public class BlockContainer extends Object implements Committable
Specifies a set of blocks in the current transaction.

All the blocks that has been made available through this object will stay permanently in memory, until this block container is closed.

Commit operation will flush all the blocks from the container, and mark all as disposable, and remove them from the container.

The blocks will be cached on the higher level, so if the container will request them again it probably get it from this cache.

The user of this class should not preserve the instance of the blocks after committing the block container.

Container contains its own internal cache of all blocks, so it is smart just to use the block indices if required, the block objects should rather be requested by getBlock(long, BlockType)

See also BlockProvider

  • Constructor Details

  • Method Details

    • hasBlock

      public boolean hasBlock(long blockIndex)
      Checks if the block with the given index is in this container
      Parameters:
      blockIndex - the block index
      Returns:
      true if the block is already opened in this container
    • getMedia

      public Media getMedia()
      A media object this container belongs to
      Returns:
      the media object
    • getContainerId

      public int getContainerId()
      A unique container id
      Returns:
      the id
    • size

      public int size()
      The number of blocks in the container
      Returns:
      number of opened blocks
    • getBlock

      public Block getBlock(long index, BlockType blockType)
      Provides a block to read and write
      Parameters:
      index - the index of the block
      blockType - a type of the block
      Returns:
      the block associated with the container
    • evict

      public void evict(Block block)
      Evicts a block from the current container

      Never use this function directly.

      Parameters:
      block - the block to evict
    • evictIfLoaded

      public void evictIfLoaded(long blockIndex)
      Checks if the block is loaded within this container, and then evict it.
      Parameters:
      blockIndex - the block index to evice
    • close

      public void close()
      Close all the blocks and the instance of block container.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • commit

      public void commit()
      Operation commits all the active blocks. It will mark the block to be garbage-collected, the data from the associated physical block will be flushed to the persistent storage.
      Specified by:
      commit in interface Committable
    • getStatus

      public Status getStatus()
      Description copied from interface: Closeable
      Provides a status of this entity
      Specified by:
      getStatus in interface Closeable
      Returns:
      the status