@NotThreadSafe public class BufferConsumer extends Object implements Closeable
Buffer.
It reads data written by BufferBuilder.
Although it is not thread safe and can be used only by one single thread, this thread can be different than the
thread using/writing to BufferBuilder. Pattern here is simple: one thread writes data to
BufferBuilder and there can be a different thread reading from it using BufferConsumer.
| Constructor and Description |
|---|
BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
boolean isBuffer)
Constructs
BufferConsumer instance with static content. |
BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition,
int currentReaderPosition)
Constructs
BufferConsumer instance with the initial reader position. |
BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
int size,
boolean isBuffer)
Constructs
BufferConsumer instance with static content of a certain size. |
| Modifier and Type | Method and Description |
|---|---|
Buffer |
build() |
void |
close() |
BufferConsumer |
copy()
Returns a retained copy with separate indexes.
|
int |
getWrittenBytes() |
boolean |
isBuffer() |
boolean |
isDataAvailable()
Returns true if there is new data available for reading.
|
boolean |
isFinished()
Checks whether the
BufferBuilder has already been finished. |
boolean |
isRecycled() |
public BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition,
int currentReaderPosition)
BufferConsumer instance with the initial reader position.public BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
boolean isBuffer)
BufferConsumer instance with static content.public BufferConsumer(org.apache.flink.core.memory.MemorySegment memorySegment,
BufferRecycler recycler,
int size,
boolean isBuffer)
BufferConsumer instance with static content of a certain size.public boolean isFinished()
BufferBuilder has already been finished.
BEWARE: this method accesses the cached value of the position marker which is only updated
after calls to build()!
public Buffer build()
Buffer containing the not yet consumed data. Returned Buffer shares the reference
counter with the parent BufferConsumer - in order to recycle memory both of them must be recycled/closed.public BufferConsumer copy()
MemorySegment twice.
WARNING: the newly returned BufferConsumer will have its reader index copied from the original buffer.
In other words, data already consumed before copying will not be visible to the returned copies.
public boolean isBuffer()
public void close()
close in interface Closeableclose in interface AutoCloseablepublic boolean isRecycled()
public int getWrittenBytes()
public boolean isDataAvailable()
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.