Class LogBufferElement
- java.lang.Object
-
- org.apache.derby.impl.store.replication.buffer.LogBufferElement
-
class LogBufferElement extends java.lang.ObjectReplicationLogBuffer consists of n LogBufferElements, each of which can store a number of log records in a single byte[].The format of each log record in the LogBufferElement is the same as is written to log file in LogAccessFile:
In addition to adding a chunk of log records to the byte[], the greatestInstant variable is updated for every append so that getLastInstant can be used to get the highest log instant in this LogBufferElement.
(int) total_length (data[].length + optionaldata[].length)
(long) instant
(byte[]) data+optionaldata
(int) total_length
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferdataprivate longgreatestInstantprivate intpositionprivate booleanrecycleMe
-
Constructor Summary
Constructors Modifier Constructor Description protectedLogBufferElement(int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intappendBytes(byte[] b, int offset, int pos, int length)Append a byte[] to this LogBufferElement.protected voidappendLog(long greatestInstant, byte[] log, int logOffset, int logLength)Append a chunk of log records to this LogBufferElement.protected intfreeSize()protected byte[]getData()protected longgetLastInstant()protected voidinit()Resets all variables to default values.protected booleanisRecyclable()protected voidsetRecyclable(boolean r)protected intsize()
-
-
-
Method Detail
-
init
protected void init()
Resets all variables to default values. Should be called before a LogBufferElement is reused.
-
appendLog
protected void appendLog(long greatestInstant, byte[] log, int logOffset, int logLength)Append a chunk of log records to this LogBufferElement.- Parameters:
greatestInstant- the instant of the log record that was added last to this chunk of loglog- the chunk of log recordslogOffset- offset in log to start copy fromlogLength- number of bytes to copy, starting from logOffset
-
getData
protected byte[] getData()
- Returns:
- A byte[] representation of the log records appended to this LogBufferElement
-
getLastInstant
protected long getLastInstant()
- Returns:
- The highest log instant appended to this LogBufferElement
-
freeSize
protected int freeSize()
- Returns:
- Number of unused bytes in this LogBufferElement
-
size
protected int size()
- Returns:
- Number of used bytes in this LogBufferElement
-
isRecyclable
protected boolean isRecyclable()
- Returns:
- true if this LogBufferElement should be reused, i.e. added to freeBuffers after being consumed.
-
setRecyclable
protected void setRecyclable(boolean r)
-
appendBytes
private int appendBytes(byte[] b, int offset, int pos, int length)Append a byte[] to this LogBufferElement.- Parameters:
b- where the bytes are copied fromoffset- offset in b to start copying frompos- the position in this LogBufferElement to start copying tolength- number of bytes to copy from b, starting from offset- Returns:
- new position
-
-