@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(MemorySegment memorySegment,
BufferRecycler recycler,
boolean isBuffer)
Constructs
BufferConsumer instance with static content. |
BufferConsumer(MemorySegment memorySegment,
BufferRecycler recycler,
org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition)
Constructs
BufferConsumer instance with content that can be changed by BufferBuilder . |
Modifier and Type | Method and Description |
---|---|
Buffer |
build() |
void |
close() |
BufferConsumer |
copy()
Returns a retained copy with separate indexes.
|
int |
getWrittenBytes() |
boolean |
isBuffer() |
boolean |
isFinished()
Checks whether the
BufferBuilder has already been finished. |
boolean |
isRecycled() |
public BufferConsumer(MemorySegment memorySegment, BufferRecycler recycler, org.apache.flink.runtime.io.network.buffer.BufferBuilder.PositionMarker currentWriterPosition)
BufferConsumer
instance with content that can be changed by BufferBuilder
.public BufferConsumer(MemorySegment memorySegment, BufferRecycler recycler, boolean isBuffer)
BufferConsumer
instance with static content.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 Closeable
close
in interface AutoCloseable
public boolean isRecycled()
public int getWrittenBytes()
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.