Class BlockContainer
java.lang.Object
org.rostore.v2.media.block.container.BlockContainer
- All Implemented Interfaces:
AutoCloseable
,Closeable
,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 Summary
ConstructorDescriptionBlockContainer
(Media media, int containerId) This should never be used directly UseMedia.newBlockContainer()
instead orInternalBlockProvider.create(BlockAllocator)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close all the blocks and the instance of block container.void
commit()
Operation commits all the active blocks.void
Evicts a block from the current containervoid
evictIfLoaded
(long blockIndex) Checks if the block is loaded within this container, and then evict it.Provides a block to read and writeint
A unique container idgetMedia()
A media object this container belongs toProvides a status of this entityboolean
hasBlock
(long blockIndex) Checks if the block with the given index is in this containerint
size()
The number of blocks in the containerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Constructor Details
-
BlockContainer
This should never be used directly UseMedia.newBlockContainer()
instead orInternalBlockProvider.create(BlockAllocator)
- Parameters:
media
- the parent media objectcontainerId
- a container id
-
-
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
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
Provides a block to read and write- Parameters:
index
- the index of the blockblockType
- a type of the block- Returns:
- the block associated with the container
-
evict
Evicts a block from the current containerNever 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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 interfaceCommittable
-
getStatus
Description copied from interface:Closeable
Provides a status of this entity
-