Class InternalBlockProvider

java.lang.Object
org.rostore.v2.media.block.InternalBlockProvider
All Implemented Interfaces:
BlockProvider

public class InternalBlockProvider extends Object implements BlockProvider
This instance manages a low-level block operation and creates a new BlockContainer.

This effectively creates a transactional boundary, that needs to be managed.

Code that creates this BlockProvider is responsible to clean it up by calling BlockContainer.close().

It is meant to be only used in the entities that need to manage its own transactional boundary, and do not expect that the BlockContainer will be provided from the outside.

It is usually a major hull-like entity, that manages several other slave-entities that would need a transactional boundaries provided from this overarching one.

  • Method Details

    • getBlockContainer

      public BlockContainer getBlockContainer()
      Provides a block container.

      Used to account the set of blocks that participate in one specific transaction.

      Specified by:
      getBlockContainer in interface BlockProvider
      Returns:
      the block container
    • getBlockAllocator

      public BlockAllocator getBlockAllocator()
      Provides a block allocator

      Used to allocate new blocks from the set of free blocks nad mark them as used.

      Specified by:
      getBlockAllocator in interface BlockProvider
      Returns:
      the block allocator
    • exchangeBlockAllocator

      public void exchangeBlockAllocator(BlockAllocator blockAllocator)
      Exchange a block allocator. Usually should not be excessively used, only in places when the allocator can't be known at the moment of the object creation.
      Parameters:
      blockAllocator -
    • getMedia

      public Media getMedia()
      Provides an associated Media object
      Specified by:
      getMedia in interface BlockProvider
      Returns:
      the media object
    • create

      public static InternalBlockProvider create(BlockAllocator blockAllocator)
      Creates a block provider that contains a new BlockContainer.
      Parameters:
      blockAllocator - the allocator to be used
      Returns:
      an instance of the BlockProvider
    • create

      public static InternalBlockProvider create(Media media)
      Creates a block provider that contains a new BlockContainer.

      Allocator is not set in this one and needs to be associated with exchangeBlockAllocator(BlockAllocator)

      Parameters:
      media - the media object
      Returns:
      an instance of the BlockProvider