Class BufferConsumer
- java.lang.Object
-
- org.apache.flink.runtime.io.network.buffer.BufferConsumer
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
@NotThreadSafe public class BufferConsumer extends Object implements Closeable
Not thread safe class for producingBuffer
.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 toBufferBuilder
. Pattern here is simple: one thread writes data toBufferBuilder
and there can be a different thread reading from it usingBufferConsumer
.
-
-
Constructor Summary
Constructors Constructor Description BufferConsumer(Buffer buffer, int size)
ConstructsBufferConsumer
instance with static content of a certain size.BufferConsumer(Buffer buffer, org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition, int currentReaderPosition)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theBufferBuilder
has already been finished.boolean
isRecycled()
String
toDebugString(boolean includeHash)
-
-
-
Constructor Detail
-
BufferConsumer
public BufferConsumer(Buffer buffer, int size)
ConstructsBufferConsumer
instance with static content of a certain size.
-
BufferConsumer
public BufferConsumer(Buffer buffer, org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition, int currentReaderPosition)
-
-
Method Detail
-
isFinished
public boolean isFinished()
Checks whether theBufferBuilder
has already been finished.BEWARE: this method accesses the cached value of the position marker which is only updated after calls to
build()
andskip(int)
!- Returns:
- true if the buffer was finished, false otherwise
-
build
public Buffer build()
- Returns:
- sliced
Buffer
containing the not yet consumed data. ReturnedBuffer
shares the reference counter with the parentBufferConsumer
- in order to recycle memory both of them must be recycled/closed.
-
copy
public BufferConsumer copy()
Returns a retained copy with separate indexes. This allows to read from the sameMemorySegment
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.- Returns:
- a retained copy of self with separate indexes
-
copyWithReaderPosition
public BufferConsumer copyWithReaderPosition(int readerPosition)
Returns a retained copy with separate indexes and sets the reader position to the given value. This allows to read from the sameMemorySegment
twice starting from the supplied position.- Parameters:
readerPosition
- the new reader position. Can be less than thecurrentReaderPosition
, but may not exceed the current writer's position.- Returns:
- a retained copy of self with separate indexes
-
isBuffer
public boolean isBuffer()
-
getDataType
public Buffer.DataType getDataType()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isRecycled
public boolean isRecycled()
-
getWrittenBytes
public int getWrittenBytes()
-
isDataAvailable
public boolean isDataAvailable()
Returns true if there is new data available for reading.
-
toDebugString
public String toDebugString(boolean includeHash)
-
-