|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gillius.realdb.model.ReliableSequencedBlock<T>
public class ReliableSequencedBlock<T extends org.gillius.realdb.model.SequencedBlock>
ReliableSequencedBlock persists a SequencedBlock in a fail-safe manner such that every write to the block either succeeds entirely, or if it fails, it reverts back to its previous state. This is achieved by writing two alternating copies of the block in the BlockFile.
Method Summary | ||
---|---|---|
static
|
createNew(BlockFile file,
int firstBlock,
int secondBlock,
int size)
Creates a new ReliableSequencedBlock by ignoring existing data on disk and formatting both allocated spaces to all 0's, based on 'size'. |
|
void |
format()
Formats both primary and secondary block space by writing all NUL bytes. |
|
T |
getBlock()
Returns the cached block; either that which was last written, or the block loaded if just loaded, or null if just created. |
|
int |
getNextSeqNum()
Returns the sequence number for the next block to be written. |
|
static
|
load(BlockFile file,
int firstBlock,
int secondBlock,
int size,
org.gillius.realdb.model.SequencedBlockLoader<T> loader)
Creates a new ReliableSequencedBlock by loading the most recent and valid block. |
|
void |
writeBlock(T block)
Writes the given block to the file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T extends org.gillius.realdb.model.SequencedBlock> ReliableSequencedBlock<T> createNew(BlockFile file, int firstBlock, int secondBlock, int size) throws java.io.IOException
SequencedBlock
, data
consisting of all NUL bytes must not be a valid serialized form on disk, and this class uses
that assumption to perform the format.
This means that a newly created/formatted ReliableSequencedBlock will throw an exception when
reloading it, unless writeBlock(SequencedBlock)
is called.
file
- non-null BlockFilefirstBlock
- block index of start of primary spacesecondBlock
- block index of start of secondary spacesize
- maximum size of serialized block, in bytes
java.io.IOException
public static <T extends org.gillius.realdb.model.SequencedBlock> ReliableSequencedBlock<T> load(BlockFile file, int firstBlock, int secondBlock, int size, org.gillius.realdb.model.SequencedBlockLoader<T> loader) throws java.io.IOException, BadFileException
file
- non-null BlockFilefirstBlock
- block index of start of primary spacesecondBlock
- block index of start of secondary spacesize
- maximum size of serialized block, in bytesloader
- loader to deserialize the data
java.io.IOException
- if the file could not be read
BadFileException
- if neither block is validpublic T getBlock()
writeBlock(T)
has ever been called, this method will never return null.
public int getNextSeqNum()
public void format() throws java.io.IOException
SequencedBlock
, data consisting of all NUL bytes must not be a valid serialized form on
disk, and this class uses that assumption to perform the format.
format
in interface Formattable
java.io.IOException
- if an error occurs writing to the data storagepublic void writeBlock(T block) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |