B - the binary representation we're manipulating.StateT - additional information that comes with incoming frames, and must be propagated to
outgoing segments (in the Java driver, this is the ChannelPromise that represents the
outcome of the write).public abstract class SegmentBuilder<B,StateT> extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
SegmentBuilder(PrimitiveCodec<B> primitiveCodec,
FrameCodec<B> frameCodec) |
| Modifier and Type | Method and Description |
|---|---|
void |
addFrame(Frame frame,
StateT frameState)
Adds a new frame.
|
void |
flush()
Signals that we're done adding frames.
|
protected abstract StateT |
mergeStates(List<StateT> frameStates)
When we batch multiple frames into one segment, how frame states are combined to form the
segment's state.
|
protected void |
onLargeFrameSplit(Frame frame,
int frameLength,
int sliceCount)
Invoked whenever a large frame needs to be split into multiple segments.
|
protected void |
onLastSegmentFlushed(int currentPayloadLength,
int currentFrameCount)
Invoked whenever
flush() was called and it produces one last self-contained segment. |
protected void |
onSegmentFull(Frame frame,
int frameLength,
int currentPayloadLength,
int currentFrameCount)
Invoked whenever the current self-contained segment for small frames is full.
|
protected void |
onSmallFrameAdded(Frame frame,
int frameLength,
int currentPayloadLength,
int currentFrameCount)
Invoked whenever a small frame was successfully added to the current self-contained segment,
without bringing it over its size limit.
|
protected abstract void |
processSegment(Segment<B> segment,
StateT segmentState)
What to do whenever a full segment is ready.
|
protected abstract List<StateT> |
splitState(StateT frameState,
int sliceCount)
When we slice one frame into multiple segments, how the frame's state is split into the slice
states.
|
protected SegmentBuilder(PrimitiveCodec<B> primitiveCodec, FrameCodec<B> frameCodec)
protected abstract StateT mergeStates(List<StateT> frameStates)
protected abstract List<StateT> splitState(StateT frameState, int sliceCount)
protected abstract void processSegment(Segment<B> segment, StateT segmentState)
public void addFrame(Frame frame, StateT frameState)
processSegment(Segment, Object) at some point in the future.
The caller must invoke flush() after the last frame.
public void flush()
This must be called after adding the last frame, it will possibly trigger the generation of one last segment.
protected void onLargeFrameSplit(Frame frame, int frameLength, int sliceCount)
frame - the frame that is being split.frameLength - the length of that frame in bytes.sliceCount - the number of slices.protected void onSegmentFull(Frame frame, int frameLength, int currentPayloadLength, int currentFrameCount)
frame - the frame that triggered this action. Note that it will not be included
in the current segment (since adding it would have brought the segment over its maximum
length).frameLength - the length of that frame in bytes.currentPayloadLength - the length of the segment's payload in bytes.currentFrameCount - the number of frames in the segment.protected void onSmallFrameAdded(Frame frame, int frameLength, int currentPayloadLength, int currentFrameCount)
frame - the frame.frameLength - the length of that frame in bytes.currentPayloadLength - the new total length of the segment's payload, after the frame was
added.currentFrameCount - the total number of frames in the payload, after the frame was added.protected void onLastSegmentFlushed(int currentPayloadLength,
int currentFrameCount)
flush() was called and it produces one last self-contained segment.
This is intended for logs in subclasses, the default implementation is empty.currentPayloadLength - the length of the segment's payload in bytes.currentFrameCount - the number of frames in the segment.Copyright © 2017–2022. All rights reserved.