Class BufferBuilder
java.lang.Object
org.apache.flink.runtime.io.network.buffer.BufferBuilder
- All Implemented Interfaces:
AutoCloseable
Not thread safe class for filling in the content of the
MemorySegment. To access written
data please use BufferConsumer which allows to build Buffer instances from the
written data.-
Constructor Summary
ConstructorsConstructorDescriptionBufferBuilder(org.apache.flink.core.memory.MemorySegment memorySegment, BufferRecycler recycler) -
Method Summary
Modifier and TypeMethodDescriptionintappend(ByteBuffer source) Append as many data as possible fromsource.intappendAndCommit(ByteBuffer source) Same asappend(ByteBuffer)but additionallycommit()the appending.voidclose()voidcommit()Make the change visible to the readers.This method always creates aBufferConsumerstarting from the current writer offset.This method always creates aBufferConsumerstarting from position 0 ofMemorySegment.intfinish()Mark thisBufferBuilderand associatedBufferConsumeras finished - no new data writes will be allowed.intGets the data type of the internal buffer.intintbooleanbooleanisFull()voidsetDataType(Buffer.DataType dataType) Sets the data type of the internal buffer.voidtrim(int newSize) The result capacity can not be greater than allocated memorySegment.
-
Constructor Details
-
BufferBuilder
public BufferBuilder(org.apache.flink.core.memory.MemorySegment memorySegment, BufferRecycler recycler)
-
-
Method Details
-
createBufferConsumer
This method always creates aBufferConsumerstarting from the current writer offset. Data written toBufferBuilderbefore creation ofBufferConsumerwon't be visible for thatBufferConsumer.- Returns:
- created matching instance of
BufferConsumerto thisBufferBuilder.
-
createBufferConsumerFromBeginning
This method always creates aBufferConsumerstarting from position 0 ofMemorySegment.- Returns:
- created matching instance of
BufferConsumerto thisBufferBuilder.
-
getDataType
Gets the data type of the internal buffer. -
setDataType
Sets the data type of the internal buffer. -
appendAndCommit
Same asappend(ByteBuffer)but additionallycommit()the appending. -
append
Append as many data as possible fromsource. Not everything might be copied if there is not enough space in the underlyingMemorySegment- Returns:
- number of copied bytes
-
commit
public void commit()Make the change visible to the readers. This is costly operation (volatile access) thus in case of bulk writes it's better to commit them all together instead one by one. -
finish
public int finish()Mark thisBufferBuilderand associatedBufferConsumeras finished - no new data writes will be allowed.This method should be idempotent to handle failures and task interruptions. Check FLINK-8948 for more details.
- Returns:
- number of written bytes.
-
isFinished
public boolean isFinished() -
isFull
public boolean isFull() -
getWritableBytes
public int getWritableBytes() -
getCommittedBytes
public int getCommittedBytes() -
getMaxCapacity
public int getMaxCapacity() -
trim
public void trim(int newSize) The result capacity can not be greater than allocated memorySegment. It also can not be less than already written data. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-