Package org.rostore.v2.seq
Class SequenceBlock
java.lang.Object
org.rostore.v2.seq.SequenceBlock
- All Implemented Interfaces:
AutoCloseable
,Closeable
- Direct Known Subclasses:
FixSizeEntryBlock
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
clean()
void
close()
Closes an underlying sequencestatic <T extends SequenceBlock>
Tcreate
(BlockProvider blockProvider, Function<BlockSequence<T>, T> factory, BlockType blockType) Creates a new block sequence and initialize a sequence block on its basisstatic <T extends SequenceBlock>
Tcreate
(BlockProvider blockProvider, CatalogBlockIndices catalogBlockIndices, Function<BlockSequence<T>, T> factory, BlockType blockType) Creates a new block sequence and initialize a sequence block on its basisvoid
Creates a new block after the current one and move to it.void
delete()
Removes the current block and mark it as free.getBlock()
Get the block this sequence's block internal pointer points toint
The size of the header of the current blockint
getIndex()
Provides the current pointer where it pointsProvides a status of the block sequenceboolean
invalid()
Checks if the pointer points to invalid blockvoid
Moves the pointer to invalid index, marks the block as invalid.boolean
isRoot()
Checks if the current block is the first block of the sequenceprotected abstract boolean
isUnused()
Provides an indication if current block does not contain any datavoid
last()
Moves the pointer to the last used block in the sequence.static <T extends SequenceBlock>
Tload
(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.void
moveTo
(int seqIndex) Moves the pointer to the specific block in the sequencevoid
next()
Moves the pointer to the next block in the sequence.void
previous()
Moves the pointer to the previous block in the sequence.void
root()
Moves the pointer to the root block in the sequence.boolean
valid()
Checks if the pointer points to valid blockMethods 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
-
SequenceBlock
-
-
Method Details
-
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 operationsstartIndex
- the index of the first block in the sequencefactory
- the factory that creates a specific variant of sequence block based on the sequenceblockType
- 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 allocatorBlockProvider.getBlockAllocator()
factory
- the factory that creates a specific variant of sequence block based on the sequenceblockType
- 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 allocatorBlockProvider.getBlockAllocator()
catalogBlockIndices
- the initial set of blocks that will be used by the sequencefactory
- the factory that creates a specific variant of sequence block based on the sequenceblockType
- 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
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getStatus
Provides a status of the block sequence
-