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

    public final class ReadOnlySlicedNetworkBuffer
    extends org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
    implements Buffer
    Minimal best-effort read-only sliced 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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf asByteBuf()  
      org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf ensureWritable​(int minWritableBytes)  
      Buffer.DataType getDataType()
      Gets the type of data this buffer represents.
      int getMaxCapacity()
      Returns the maximum size of the buffer, i.e. the capacity of the underlying MemorySegment.
      org.apache.flink.core.memory.MemorySegment getMemorySegment()
      Returns the underlying memory segment.
      int getMemorySegmentOffset()
      This method will be removed in the future.
      ByteBuffer getNioBuffer​(int index, int length)
      Gets a new ByteBuffer instance wrapping this buffer's bytes.
      ByteBuffer getNioBufferReadable()
      Gets a new ByteBuffer instance wrapping this buffer's readable bytes, i.e. between Buffer.getReaderIndex() and Buffer.getSize().
      int getReaderIndex()
      Returns the reader index of this buffer.
      BufferRecycler getRecycler()
      Gets the buffer's recycler.
      int getSize()
      Returns the size of the written data, i.e. the writer index, of this buffer.
      boolean isBuffer()
      Returns whether this buffer represents a buffer or an event.
      boolean isCompressed()  
      boolean isRecycled()
      Returns whether this buffer has been recycled or not.
      boolean isWritable()  
      boolean isWritable​(int numBytes)  
      ByteBuffer nioBuffer​(int index, int length)  
      ReadOnlySlicedNetworkBuffer readOnlySlice()
      Returns a read-only slice of this buffer's readable bytes, i.e. between Buffer.getReaderIndex() and Buffer.getSize().
      ReadOnlySlicedNetworkBuffer readOnlySlice​(int index, int length)
      Returns a read-only slice of this buffer.
      void recycleBuffer()
      Releases this buffer once, i.e. reduces the reference count and recycles the buffer if the reference count reaches 0.
      ReadOnlySlicedNetworkBuffer retainBuffer()
      Retains this buffer for further use, increasing the reference counter by 1.
      void setAllocator​(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator allocator)
      Sets the buffer allocator for use in netty.
      void setCompressed​(boolean isCompressed)
      Tags the buffer as compressed or uncompressed.
      void setDataType​(Buffer.DataType dataType)
      Sets the type of data this buffer represents.
      void setReaderIndex​(int readerIndex)
      Sets the reader index of this buffer.
      void setRecycler​(BufferRecycler bufferRecycler)
      Sets the buffer's recycler.
      void setSize​(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.ByteBuf unwrap()  
      • 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, slice
      • Methods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.AbstractDerivedByteBuf

        internalNioBuffer, isContiguous, refCnt, release, release, retain, retain, touch, touch
      • Methods 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, writeZero
      • Methods inherited from class org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf

        getDoubleLE, getFloatLE, maxFastWritableBytes, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
    • Method Detail

      • unwrap

        public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf unwrap()
        Overrides:
        unwrap in class org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
      • isBuffer

        public boolean isBuffer()
        Description copied from interface: Buffer
        Returns whether this buffer represents a buffer or an event.
        Specified by:
        isBuffer in interface Buffer
        Returns:
        true if this is a real buffer, false if this is 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:
        getMemorySegment in interface Buffer
        Returns:
        the memory segment backing this buffer
      • getMemorySegmentOffset

        public int getMemorySegmentOffset()
        Description copied from interface: Buffer
        This method will be removed in the future. For writing use BufferBuilder.
        Specified by:
        getMemorySegmentOffset in interface Buffer
        Returns:
        the offset where this (potential slice) Buffer's data start in the underlying memory segment.
      • getRecycler

        public BufferRecycler getRecycler()
        Description copied from interface: Buffer
        Gets the buffer's recycler.
        Specified by:
        getRecycler in interface Buffer
        Returns:
        buffer recycler
      • setRecycler

        public void setRecycler​(BufferRecycler bufferRecycler)
        Description copied from interface: Buffer
        Sets 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:
        setRecycler in interface Buffer
        Parameters:
        bufferRecycler - the new buffer recycler
      • recycleBuffer

        public void recycleBuffer()
        Description copied from interface: Buffer
        Releases this buffer once, i.e. reduces the reference count and recycles the buffer if the reference count reaches 0.
        Specified by:
        recycleBuffer in interface Buffer
        See Also:
        Buffer.retainBuffer()
      • isRecycled

        public boolean isRecycled()
        Description copied from interface: Buffer
        Returns whether this buffer has been recycled or not.
        Specified by:
        isRecycled in interface Buffer
        Returns:
        true if already recycled, false otherwise
      • readOnlySlice

        public ReadOnlySlicedNetworkBuffer readOnlySlice​(int index,
                                                         int length)
        Description copied from interface: Buffer
        Returns 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 retained automatically.

        Specified by:
        readOnlySlice in interface Buffer
        Parameters:
        index - the index to start from
        length - the length of the slice
        Returns:
        a read-only sliced buffer
      • getMaxCapacity

        public int getMaxCapacity()
        Description copied from interface: Buffer
        Returns the maximum size of the buffer, i.e. the capacity of the underlying MemorySegment.
        Specified by:
        getMaxCapacity in interface Buffer
        Returns:
        size of the buffer
      • getReaderIndex

        public int getReaderIndex()
        Description copied from interface: Buffer
        Returns the reader index of this buffer.

        This is where readable (unconsumed) bytes start in the backing memory segment.

        Specified by:
        getReaderIndex in interface Buffer
        Returns:
        reader index (from 0 (inclusive) to the size of the backing MemorySegment (inclusive))
      • getSize

        public int getSize()
        Description copied from interface: Buffer
        Returns 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.

        Specified by:
        getSize in interface Buffer
        Returns:
        writer index (from 0 (inclusive) to the size of the backing MemorySegment (inclusive))
      • setSize

        public void setSize​(int writerIndex)
        Description copied from interface: Buffer
        Sets the size of the written data, i.e. the writer index, of this buffer.
        Specified by:
        setSize in interface Buffer
      • nioBuffer

        public ByteBuffer nioBuffer​(int index,
                                    int length)
        Overrides:
        nioBuffer in class org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
      • isWritable

        public boolean isWritable()
        Overrides:
        isWritable in class org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
      • isWritable

        public boolean isWritable​(int numBytes)
        Overrides:
        isWritable in class org.apache.flink.shaded.netty4.io.netty.buffer.ReadOnlyByteBuf
      • ensureWritable

        public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf ensureWritable​(int minWritableBytes)
        Overrides:
        ensureWritable in class org.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: Buffer
        Sets the buffer allocator for use in netty.
        Specified by:
        setAllocator in interface Buffer
        Parameters:
        allocator - netty buffer allocator
      • asByteBuf

        public org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf asByteBuf()
        Specified by:
        asByteBuf in interface Buffer
        Specified by:
        asByteBuf in interface org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufConvertible
        Overrides:
        asByteBuf in class org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf
        Returns:
        self as ByteBuf implementation.
      • isCompressed

        public boolean isCompressed()
        Specified by:
        isCompressed in interface Buffer
        Returns:
        whether the buffer is compressed or not.
      • setCompressed

        public void setCompressed​(boolean isCompressed)
        Description copied from interface: Buffer
        Tags the buffer as compressed or uncompressed.
        Specified by:
        setCompressed in interface Buffer
      • setDataType

        public void setDataType​(Buffer.DataType dataType)
        Description copied from interface: Buffer
        Sets the type of data this buffer represents.
        Specified by:
        setDataType in interface Buffer