public interface DataWriter
extends java.io.Closeable
DataWriter defines the way how data is written to Log, how blocks appear in
the log and how they are removed from the log.
Log blocks can be mutable and immutable. All blocks having length equal to maximum log block size are immutable. In any moment, only one block can be mutable. This has maximum address. DataWriter always writes to a single mutable block, that makes log
appendable.Block,
DataReader,
DataReaderWriterProvider| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears
Log by location specified as a parameter to DataReaderWriterProvider.newReaderWriter(String). |
void |
close()
Closes the data writer.
|
boolean |
isOpen()
Returns
true is the DataWriter is open. |
boolean |
lock(long timeout)
If applicable, tries to acquire writer's lock in specified time.
|
java.lang.String |
lockInfo()
For debugging purposes, returns detailed information about current lock owner.
|
Block |
openOrCreateBlock(long address,
long length)
Open existing block for writing or creates the new one by specified address with specified length.
|
boolean |
release()
Releases writer's lock.
|
void |
removeBlock(long blockAddress,
@NotNull RemoveBlockType rbt)
Removes existing immutable block.
|
void |
sync()
If applicable, forces flush of written data to underlying storage device.
|
void |
syncDirectory()
If applicable, forces flush of changes in directory structure to underlying storage device.
|
void |
truncateBlock(long blockAddress,
long length)
Truncates existing block to specified length.
|
Block |
write(byte[] b,
int off,
int len)
Writes (appends) binary data to
Log. |
boolean isOpen()
true is the DataWriter is open. i.e. there is an incomplete mutable block
having length less than maximum log block size.true is the DataWriter is openBlock write(byte[] b, int off, int len)
Log. Returns new Block instance representing mutable block.void sync()
void syncDirectory()
void close()
Log closes the data writer each time when mutable block
becomes immutable, i.e. reaches its maximum log block size.close in interface java.lang.AutoCloseableclose in interface java.io.Closeablevoid clear()
Log by location specified as a parameter to DataReaderWriterProvider.newReaderWriter(String).
The database becomes empty.Block openOrCreateBlock(long address, long length)
void removeBlock(long blockAddress,
@NotNull
@NotNull RemoveBlockType rbt)
RemoveBlockType rbt is equal to RemoveBlockType.Rename.blockAddress - address of block to removerbt - RemoveBlockType.Rename to rename block instead of removing it.RemoveBlockTypevoid truncateBlock(long blockAddress,
long length)
boolean lock(long timeout)
true.
Successfully acquired lock guarantees that Log cannot be opened in parallel (within same
JVM or not) unless it is released by the writer.timeout - - time to wait for lock acquisitiontrue if the lock is acquiredrelease(),
lockInfo()boolean release()
true if released successfullylock(long)java.lang.String lockInfo()
false, Log throws an ExodusException with the lock info in its message.lock(long)