Class MappedPhysicalBlocks

java.lang.Object
org.rostore.v2.media.block.MappedPhysicalBlocks

public class MappedPhysicalBlocks extends Object
This is a container of all active physical blocks in the ro-store.

It manages a cache of the blocks, so that different processes would get the access to the same instances of the blocks.

When the blocks are not used by any processes they still be preserved in the cache until the time provided in MediaProperties.getCloseUnusedBlocksAfterMillis() is expired.

This passive caching is only applied for the non-data blocks, the blocks which type is not BlockType.DATA.

This is a major hub of blocks in the Media and this class manages the concurrent access and is internally is thread safe.

A great precaution should be paid to the synchronized blocks in its implementation.

  • Constructor Details

    • MappedPhysicalBlocks

      public MappedPhysicalBlocks(Media media)
      Creates an object
      Parameters:
      media - the media it should be used in
  • Method Details

    • size

      public int size()
      The total size of passively cached blocks and the actively used that are currently managed by this instance.
      Returns:
      a number of blocks currently in the memory
    • get

      public Block get(BlockContainer blockContainer, long index, BlockType blockType)
      Creates a BlockContainer private Block. If the block is not in use or in cache, it is get loaded from the persistence layer.
      Parameters:
      blockContainer - the container the block should be associated with
      index - the index of the block
      blockType - the type of the block
      Returns:
      a block that can be used in the container
    • remove

      public void remove(BlockContainer blockContainer, long index)
    • closeExpired

      public void closeExpired()
    • closeUnused

      public void closeUnused()