Class BufferConsumer
java.lang.Object
org.apache.flink.runtime.io.network.buffer.BufferConsumer
- All Implemented Interfaces:
Closeable,AutoCloseable
Not thread safe class for producing
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 Summary
ConstructorsConstructorDescriptionBufferConsumer(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
Modifier and TypeMethodDescriptionbuild()voidclose()copy()Returns a retained copy with separate indexes.copyWithReaderPosition(int readerPosition) Returns a retained copy with separate indexes and sets the reader position to the given value.intbooleanisBuffer()booleanReturns true if there is new data available for reading.booleanChecks whether theBufferBuilderhas already been finished.booleantoDebugString(boolean includeHash)
-
Constructor Details
-
BufferConsumer
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 Details
-
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
- 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
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
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
-
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
-