Package org.rostore.v2.fixsize
Class FixSizeEntryBlock<T extends FixSizeEntry>
java.lang.Object
org.rostore.v2.seq.SequenceBlock
org.rostore.v2.fixsize.FixSizeEntryBlock<T>
- Type Parameters:
T
- a class representing the entries
- All Implemented Interfaces:
AutoCloseable
,Closeable
This is an extension of sequence block that maps the block area as
a set of the fixed-sized entries.
All the entries are stored at the beginning of the block, so the used area of block differs from block to block.
Block stores the number of entries that has been added to the block.
The nature of the entries and their size can be different, but once set stays the same in all blocks of the sequence.
The block allows to store an extra header. The header size differentiates between the first block (the header of the first block in the sequence) and the regular block's header. This allow to store additional data before all the entries in the block.
-
Constructor Summary
ConstructorDescriptionFixSizeEntryBlock
(BlockSequence<FixSizeEntryBlock> sequence, int firstHeaderSize, Function<FixSizeEntryBlock<T>, T> entryFactory, EntrySizeListener newEntryNumberListener) -
Method Summary
Modifier and TypeMethodDescriptionint
addEntriesNumber
(int number) Adds number of entries in this blockvoid
Creates a new block after the current one and move to it.A block provider based on the one of associatedBlockSequence
int
Provides a number of entries added to the blockgetEntry()
Provides an associated entry (which contain the real business logic)int
Provides a total entry capacity of the blockint
Provides the header's size of the first blockint
Provides a current header's sizeint
Provides the size of all block's headers except of the first oneboolean
Provides an indication if the current block has free spacevoid
Moves the pointer to invalid index, marks the block as invalid.protected boolean
isUnused()
Provides an indication if current block does not contain any datavoid
moveEntriesFrom
(int sourceSeqIndex, int sourceEntryStartIndex) Moves (appends) all entries starting from the given source block index / source entry index to the last entry in the source block to the end of this block.void
moveTo
(int seqIndex) Sets the current location of block to the specified sequence index.protected void
throwExceptionIfInvalid
(String message) toString()
Methods inherited from class org.rostore.v2.seq.SequenceBlock
clean, close, create, create, delete, getBlock, getBlockSequence, getIndex, getStatus, invalid, isRoot, last, load, next, previous, root, valid
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Constructor Details
-
FixSizeEntryBlock
public FixSizeEntryBlock(BlockSequence<FixSizeEntryBlock> sequence, int firstHeaderSize, Function<FixSizeEntryBlock<T>, T> entryFactory, EntrySizeListener newEntryNumberListener)
-
-
Method Details
-
getBlockProvider
A block provider based on the one of associatedBlockSequence
- Returns:
- the block provider
-
getEntry
Provides an associated entry (which contain the real business logic)- Returns:
- the entry
-
getHeaderSize
public int getHeaderSize()Provides a current header's size- Overrides:
getHeaderSize
in classSequenceBlock
- Returns:
- the size of the header
-
getRegularHeaderSize
public int getRegularHeaderSize()Provides the size of all block's headers except of the first one- Returns:
- regular size of the header in bytes
-
getFirstHeaderSize
public int getFirstHeaderSize()Provides the header's size of the first block- Returns:
- the size in bytes of the first block's header
-
getEntryCapacity
public int getEntryCapacity()Provides a total entry capacity of the block- Returns:
- the number of entries that can fit into one free block
-
throwExceptionIfInvalid
-
addEntriesNumber
public int addEntriesNumber(int number) Adds number of entries in this block- Parameters:
number
- the number of entries to add (if positive) or remove (if negative)- Returns:
- the total number of entries added to the current block
-
getEntriesNumber
public int getEntriesNumber()Provides a number of entries added to the block- Returns:
- number of entries
-
hasFreeSpace
public boolean hasFreeSpace()Provides an indication if the current block has free space- Returns:
true
if there is a free space for at least one additional entry
-
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.
- Overrides:
createNewAfter
in classSequenceBlock
-
isUnused
protected boolean isUnused()Provides an indication if current block does not contain any data- Specified by:
isUnused
in classSequenceBlock
- Returns:
true
if no entries are currently added to block
-
moveEntriesFrom
public void moveEntriesFrom(int sourceSeqIndex, int sourceEntryStartIndex) Moves (appends) all entries starting from the given source block index / source entry index to the last entry in the source block to the end of this block.- Parameters:
sourceSeqIndex
- the source index of the block within the sequencesourceEntryStartIndex
- the index of the first entry to move
-
toString
-
invalidate
public void invalidate()Moves the pointer to invalid index, marks the block as invalid.- Overrides:
invalidate
in classSequenceBlock
-
moveTo
public void moveTo(int seqIndex) Sets the current location of block to the specified sequence index.It also will set the index of entry to the first one.
- Overrides:
moveTo
in classSequenceBlock
- Parameters:
seqIndex
- the relative index in the sequence of the block
-