@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(Buffer buffer,
org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition,
int currentReaderPosition) |
BufferConsumer(Buffer buffer,
int size)
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.
|
BufferConsumer |
copyWithReaderPosition(int readerPosition)
Returns a retained copy with separate indexes and sets the reader position to the given
value.
|
Buffer.DataType |
getDataType() |
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() |
String |
toDebugString(boolean includeHash) |
public BufferConsumer(Buffer buffer, int size)
BufferConsumer
instance with static content of a certain size.public BufferConsumer(Buffer buffer, org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition, int currentReaderPosition)
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()
and skip(int)
!
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 BufferConsumer copyWithReaderPosition(int readerPosition)
MemorySegment
twice starting from the
supplied position.readerPosition
- the new reader position. Can be less than the currentReaderPosition
, but may not exceed the current writer's position.public boolean isBuffer()
public Buffer.DataType getDataType()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public boolean isRecycled()
public int getWrittenBytes()
public boolean isDataAvailable()
public String toDebugString(boolean includeHash)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.