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 toBufferBuilderand there can be a different thread reading from it usingBufferConsumer.
-
-
Constructor Summary
Constructors Constructor Description BufferConsumer(Buffer buffer, int size)ConstructsBufferConsumerinstance 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 Bufferbuild()voidclose()BufferConsumercopy()Returns a retained copy with separate indexes.BufferConsumercopyWithReaderPosition(int readerPosition)Returns a retained copy with separate indexes and sets the reader position to the given value.Buffer.DataTypegetDataType()intgetWrittenBytes()booleanisBuffer()booleanisDataAvailable()Returns true if there is new data available for reading.booleanisFinished()Checks whether theBufferBuilderhas already been finished.booleanisRecycled()StringtoDebugString(boolean includeHash)
-
-
-
Constructor Detail
-
BufferConsumer
public BufferConsumer(Buffer buffer, int size)
ConstructsBufferConsumerinstance 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 theBufferBuilderhas 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
Buffercontaining the not yet consumed data. ReturnedBuffershares 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 sameMemorySegmenttwice.WARNING: the newly returned
BufferConsumerwill 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 sameMemorySegmenttwice 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:
closein interfaceAutoCloseable- Specified by:
closein 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)
-
-