Interface LogWriter
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
DirectWriter
interface LogWriter extends java.lang.AutoCloseableInterface for writing data to a bookkeeper entry log.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Close any held resources.voidflush()Flush all buffered writes to disk.intlogId()Return the ID of the log being written.longposition()The current offset within the log at which the next call to #writeDelimited will start writing.voidposition(long offset)Set the offset within the log at which the next call to #writeDelimited will start writing.intserializedSize(io.netty.buffer.ByteBuf buf)voidwriteAt(long offset, io.netty.buffer.ByteBuf buf)Write the contents of a buffer at a predefined position in the log.intwriteDelimited(io.netty.buffer.ByteBuf buf)Write a delimited buffer the log.
-
-
-
Method Detail
-
logId
int logId()
Return the ID of the log being written.
-
writeAt
void writeAt(long offset, io.netty.buffer.ByteBuf buf) throws java.io.IOExceptionWrite the contents of a buffer at a predefined position in the log. Both the position and the size of the buffer must be page aligned (i.e. to 4096).- Throws:
java.io.IOException
-
writeDelimited
int writeDelimited(io.netty.buffer.ByteBuf buf) throws java.io.IOExceptionWrite a delimited buffer the log. The size of the buffer is first written and then the buffer itself. Note that the returned offset is for the buffer itself, not the size. So, if a buffer is written at the start of the file, the returned offset will be 4, not 0. The returned offset is an int. Consequently, entries can only be written in the first Integer.MAX_VALUE bytes of the file. This is due to how offsets are stored in the index.- Returns:
- the offset of the buffer within the file.
- Throws:
java.io.IOException
-
serializedSize
int serializedSize(io.netty.buffer.ByteBuf buf)
- Returns:
- the number of bytes consumed by the buffer when written with #writeDelimited
-
position
long position() throws java.io.IOExceptionThe current offset within the log at which the next call to #writeDelimited will start writing.- Throws:
java.io.IOException
-
position
void position(long offset) throws java.io.IOExceptionSet the offset within the log at which the next call to #writeDelimited will start writing.- Throws:
java.io.IOException
-
flush
void flush() throws java.io.IOExceptionFlush all buffered writes to disk. This call must ensure that the bytes are actually on disk before returning.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOExceptionClose any held resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
-