public class SegmentBufferWriter extends Object
The common usage pattern is:
SegmentBufferWriter writer = ...
writer.prepare(...) // allocate buffer
writer.writeXYZ(...)
The behaviour of this class is undefined should the pre-allocated buffer be
overrun be calling any of the write methods.
Instances of this class are not thread safe. See also the class comment of
SegmentWriter.
| Modifier and Type | Class and Description |
|---|---|
static interface |
WriteOperationHandler.WriteOperation
A
WriteOperation encapsulates an operation on a SegmentWriter. |
| Constructor and Description |
|---|
SegmentBufferWriter(SegmentStore store,
com.google.common.base.Supplier<Integer> segmentCounter,
SegmentReader reader,
String wid,
int generation) |
| Modifier and Type | Method and Description |
|---|---|
RecordId |
execute(WriteOperationHandler.WriteOperation writeOperation)
Execute the passed
writeOperation by passing it a SegmentBufferWriter. |
void |
flush()
Adds a segment header to the buffer and writes a segment to the segment
store.
|
RecordId |
prepare(RecordType type,
int size,
Collection<RecordId> ids)
Before writing a record (which are written backwards, from the end of the
file to the beginning), this method is called, to ensure there is enough
space.
|
void |
writeByte(byte value) |
void |
writeBytes(byte[] data,
int offset,
int length) |
void |
writeInt(int value) |
void |
writeLong(long value) |
void |
writeRecordId(RecordId recordId)
Write a record id, and marks the record id as referenced (removes it from
the unreferenced set).
|
void |
writeRecordId(RecordId recordId,
boolean reference)
Write a record ID.
|
void |
writeShort(short value) |
public SegmentBufferWriter(@Nonnull SegmentStore store, @Nonnull com.google.common.base.Supplier<Integer> segmentCounter, @Nonnull SegmentReader reader, @CheckForNull String wid, int generation)
@Nonnull public RecordId execute(@Nonnull WriteOperationHandler.WriteOperation writeOperation) throws IOException
writeOperation by passing it a SegmentBufferWriter.writeOperation - WriteOperationHandler.WriteOperation to executeRecordId that resulted from persisting the changes.IOExceptionpublic void writeByte(byte value)
public void writeShort(short value)
public void writeInt(int value)
public void writeLong(long value)
public void writeRecordId(RecordId recordId)
recordId - the record idpublic void writeRecordId(RecordId recordId, boolean reference)
recordId - the record ID.reference - true if this record ID is a reference, false otherwise.public void writeBytes(byte[] data,
int offset,
int length)
public void flush()
throws IOException
IOExceptionpublic RecordId prepare(RecordType type, int size, Collection<RecordId> ids) throws IOException
This method does not actually write into the segment, just allocates the space (flushing the segment if needed and starting a new one), and sets the write position (records are written from the end to the beginning, but within a record from left to right).
type - the record type (only used for root records)size - the size of the record, excluding the size used for the
record idsids - the record idsIOExceptionCopyright © 2012-2017 The Apache Software Foundation. All Rights Reserved.