Class ReadOnlySlicedNetworkBuffer
- All Implemented Interfaces:
Comparable<org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf>,Buffer,org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufConvertible,org.apache.flink.shaded.netty4.io.netty.util.ReferenceCounted
Buffer implementation wrapping a NetworkBuffer's sub-region based on io.netty.buffer.SlicedByteBuf and
io.netty.buffer.ReadOnlyByteBuf.
BEWARE: We do not guarantee to block every operation that is able to write data but all returned data structures should be handled as if it was!.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.network.buffer.Buffer
Buffer.DataType -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.shaded.netty4.io.netty.buffer.ByteBuforg.apache.flink.shaded.netty4.io.netty.buffer.ByteBufensureWritable(int minWritableBytes) Gets the type of data this buffer represents.intReturns the maximum size of the buffer, i.e. the capacity of the underlyingMemorySegment.org.apache.flink.core.memory.MemorySegmentReturns the underlying memory segment.intThis method will be removed in the future.getNioBuffer(int index, int length) Gets a newByteBufferinstance wrapping this buffer's bytes.Gets a newByteBufferinstance wrapping this buffer's readable bytes, i.e. betweenBuffer.getReaderIndex()andBuffer.getSize().intReturns the reader index of this buffer.Gets the buffer's recycler.intgetSize()Returns the size of the written data, i.e. the writer index, of this buffer.booleanisBuffer()Returns whether this buffer represents a buffer or an event.booleanbooleanReturns whether this buffer has been recycled or not.booleanbooleanisWritable(int numBytes) nioBuffer(int index, int length) Returns a read-only slice of this buffer's readable bytes, i.e. betweenBuffer.getReaderIndex()andBuffer.getSize().readOnlySlice(int index, int length) Returns a read-only slice of this buffer.voidReleases this buffer once, i.e. reduces the reference count and recycles the buffer if the reference count reaches 0.Retains this buffer for further use, increasing the reference counter by 1.voidsetAllocator(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator allocator) Sets the buffer allocator for use in netty.voidsetCompressed(boolean isCompressed) Tags the buffer as compressed or uncompressed.voidsetDataType(Buffer.DataType dataType) Sets the type of data this buffer represents.voidsetReaderIndex(int readerIndex) Sets the reader index of this buffer.voidsetRecycler(BufferRecycler bufferRecycler) Sets the buffer's recycler.voidsetSize(int writerIndex) Sets the size of the written data, i.e. the writer index, of this buffer.org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufunwrap()Methods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
_getByte, _getInt, _getIntLE, _getLong, _getLongLE, _getShort, _getShortLE, _getUnsignedMedium, _getUnsignedMediumLE, _setByte, _setInt, _setIntLE, _setLong, _setLongLE, _setMedium, _setMediumLE, _setShort, _setShortLE, alloc, array, arrayOffset, asReadOnly, capacity, capacity, copy, discardReadBytes, duplicate, ensureWritable, forEachByte, forEachByteDesc, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getInt, getIntLE, getLong, getLongLE, getShort, getShortLE, getUnsignedMedium, getUnsignedMediumLE, hasArray, hasMemoryAddress, isDirect, isReadOnly, memoryAddress, nioBufferCount, nioBuffers, order, setByte, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setInt, setIntLE, setLong, setLongLE, setMedium, setMediumLE, setShort, setShortLE, sliceMethods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.AbstractDerivedByteBuf
internalNioBuffer, isContiguous, refCnt, release, release, retain, retain, touch, touchMethods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.AbstractByteBuf
adjustMarkers, bytesBefore, bytesBefore, bytesBefore, checkDstIndex, checkDstIndex, checkIndex, checkIndex, checkNewCapacity, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardSomeReadBytes, ensureAccessible, equals, forEachByte, forEachByteDesc, getBoolean, getBytes, getBytes, getBytes, getChar, getCharSequence, getDouble, getFloat, getMedium, getMediumLE, getUnsignedByte, getUnsignedInt, getUnsignedIntLE, getUnsignedShort, getUnsignedShortLE, hashCode, indexOf, isReadable, isReadable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, newSwappedByteBuf, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readCharSequence, readDouble, readerIndex, readerIndex, readFloat, readInt, readIntLE, readLong, readLongLE, readMedium, readMediumLE, readRetainedSlice, readShort, readShortLE, readSlice, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedMedium, readUnsignedMediumLE, readUnsignedShort, readUnsignedShortLE, resetReaderIndex, resetWriterIndex, retainedDuplicate, retainedSlice, retainedSlice, setBoolean, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, setZero, skipBytes, slice, toString, toString, toString, trimIndicesToCapacity, writableBytes, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeCharSequence, writeDouble, writeFloat, writeInt, writeIntLE, writeLong, writeLongLE, writeMedium, writeMediumLE, writerIndex, writerIndex, writeShort, writeShortLE, writeZeroMethods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf
getDoubleLE, getFloatLE, maxFastWritableBytes, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLEMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.io.network.buffer.Buffer
readableBytes, refCnt, toDebugString
-
Method Details
-
unwrap
public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf unwrap()- Overrides:
unwrapin classorg.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
-
isBuffer
public boolean isBuffer()Description copied from interface:BufferReturns whether this buffer represents a buffer or an event. -
getMemorySegment
public org.apache.flink.core.memory.MemorySegment getMemorySegment()Returns the underlying memory segment.BEWARE: Although we cannot set the memory segment read-only it should be handled as if it was!.
- Specified by:
getMemorySegmentin interfaceBuffer- Returns:
- the memory segment backing this buffer
-
getMemorySegmentOffset
public int getMemorySegmentOffset()Description copied from interface:BufferThis method will be removed in the future. For writing useBufferBuilder.- Specified by:
getMemorySegmentOffsetin interfaceBuffer- Returns:
- the offset where this (potential slice)
Buffer's data start in the underlying memory segment.
-
getRecycler
Description copied from interface:BufferGets the buffer's recycler.- Specified by:
getRecyclerin interfaceBuffer- Returns:
- buffer recycler
-
setRecycler
Description copied from interface:BufferSets the buffer's recycler.Note that updating the recycler is an unsafe operation and this method cannot guarantee thread safety. It is important for the caller to fully understand the consequences of calling this method. Incorrectly updating the buffer recycler can result in a leak of the buffer due to using a wrong recycler to recycle buffer. Therefore, be careful when calling this method.
- Specified by:
setRecyclerin interfaceBuffer- Parameters:
bufferRecycler- the new buffer recycler
-
recycleBuffer
public void recycleBuffer()Description copied from interface:BufferReleases this buffer once, i.e. reduces the reference count and recycles the buffer if the reference count reaches 0.- Specified by:
recycleBufferin interfaceBuffer- See Also:
-
isRecycled
public boolean isRecycled()Description copied from interface:BufferReturns whether this buffer has been recycled or not.- Specified by:
isRecycledin interfaceBuffer- Returns:
- true if already recycled, false otherwise
-
retainBuffer
Description copied from interface:BufferRetains this buffer for further use, increasing the reference counter by 1.- Specified by:
retainBufferin interfaceBuffer- Returns:
- this instance (for chained calls)
- See Also:
-
readOnlySlice
Description copied from interface:BufferReturns a read-only slice of this buffer's readable bytes, i.e. betweenBuffer.getReaderIndex()andBuffer.getSize().Reader and writer indices as well as markers are not shared. Reference counters are shared but the slice is not
retainedautomatically.- Specified by:
readOnlySlicein interfaceBuffer- Returns:
- a read-only sliced buffer
-
readOnlySlice
Description copied from interface:BufferReturns a read-only slice of this buffer.Reader and writer indices as well as markers are not shared. Reference counters are shared but the slice is not
retainedautomatically.- Specified by:
readOnlySlicein interfaceBuffer- Parameters:
index- the index to start fromlength- the length of the slice- Returns:
- a read-only sliced buffer
-
getMaxCapacity
public int getMaxCapacity()Description copied from interface:BufferReturns the maximum size of the buffer, i.e. the capacity of the underlyingMemorySegment.- Specified by:
getMaxCapacityin interfaceBuffer- Returns:
- size of the buffer
-
getReaderIndex
public int getReaderIndex()Description copied from interface:BufferReturns the reader index of this buffer.This is where readable (unconsumed) bytes start in the backing memory segment.
- Specified by:
getReaderIndexin interfaceBuffer- Returns:
- reader index (from 0 (inclusive) to the size of the backing
MemorySegment(inclusive))
-
setReaderIndex
Description copied from interface:BufferSets the reader index of this buffer.- Specified by:
setReaderIndexin interfaceBuffer- Throws:
IndexOutOfBoundsException- if the index is less than 0 or greater thanBuffer.getSize()
-
getSize
public int getSize()Description copied from interface:BufferReturns the size of the written data, i.e. the writer index, of this buffer.This is where writable bytes start in the backing memory segment.
-
setSize
public void setSize(int writerIndex) Description copied from interface:BufferSets the size of the written data, i.e. the writer index, of this buffer. -
getNioBufferReadable
Description copied from interface:BufferGets a newByteBufferinstance wrapping this buffer's readable bytes, i.e. betweenBuffer.getReaderIndex()andBuffer.getSize().Please note that neither index is updated by the returned buffer.
- Specified by:
getNioBufferReadablein interfaceBuffer- Returns:
- byte buffer sharing the contents of the underlying memory segment
-
getNioBuffer
Description copied from interface:BufferGets a newByteBufferinstance wrapping this buffer's bytes.Please note that neither read nor write index are updated by the returned buffer.
- Specified by:
getNioBufferin interfaceBuffer- Returns:
- byte buffer sharing the contents of the underlying memory segment
- Throws:
IndexOutOfBoundsException- if the indexes are not without the buffer's bounds- See Also:
-
nioBuffer
- Overrides:
nioBufferin classorg.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
-
isWritable
public boolean isWritable()- Overrides:
isWritablein classorg.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
-
isWritable
public boolean isWritable(int numBytes) - Overrides:
isWritablein classorg.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
-
ensureWritable
public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf ensureWritable(int minWritableBytes) - Overrides:
ensureWritablein classorg.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
-
setAllocator
public void setAllocator(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator allocator) Description copied from interface:BufferSets the buffer allocator for use in netty.- Specified by:
setAllocatorin interfaceBuffer- Parameters:
allocator- netty buffer allocator
-
asByteBuf
public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf asByteBuf() -
isCompressed
public boolean isCompressed()- Specified by:
isCompressedin interfaceBuffer- Returns:
- whether the buffer is compressed or not.
-
setCompressed
public void setCompressed(boolean isCompressed) Description copied from interface:BufferTags the buffer as compressed or uncompressed.- Specified by:
setCompressedin interfaceBuffer
-
getDataType
Description copied from interface:BufferGets the type of data this buffer represents.- Specified by:
getDataTypein interfaceBuffer
-
setDataType
Description copied from interface:BufferSets the type of data this buffer represents.- Specified by:
setDataTypein interfaceBuffer
-