Class InboundChannelBuffer

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public final class InboundChannelBuffer
    extends java.lang.Object
    implements java.lang.AutoCloseable
    This is a channel byte buffer composed internally of 16kb pages. When an entire message has been read and consumed, the release(long) method releases the bytes from the head of the buffer and closes the pages internally. If more space is needed at the end of the buffer ensureCapacity(long) can be called and the buffer will expand using the supplier provided.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int PAGE_SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      InboundChannelBuffer​(java.util.function.IntFunction<Page> pageAllocator)  
    • Method Summary

      Modifier and Type Method Description
      static InboundChannelBuffer allocatingInstance()  
      void close()  
      void ensureCapacity​(long requiredCapacity)  
      long getCapacity()  
      long getIndex()  
      long getRemaining()  
      void incrementIndex​(long delta)  
      void release​(long bytesToRelease)
      This method will release bytes from the head of this buffer.
      Page[] sliceAndRetainPagesTo​(long to)
      This method will return an array of Page representing the bytes from the beginning of this buffer up through the index argument that was passed.
      java.nio.ByteBuffer[] sliceBuffersFrom​(long from)
      This method will return an array of ByteBuffer representing the bytes from the index passed through the end of this buffer.
      java.nio.ByteBuffer[] sliceBuffersTo​(long to)
      This method will return an array of ByteBuffer representing the bytes from the beginning of this buffer up through the index argument that was passed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InboundChannelBuffer

        public InboundChannelBuffer​(java.util.function.IntFunction<Page> pageAllocator)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • ensureCapacity

        public void ensureCapacity​(long requiredCapacity)
      • release

        public void release​(long bytesToRelease)
        This method will release bytes from the head of this buffer. If you release bytes past the current index the index is truncated to zero.
        Parameters:
        bytesToRelease - number of bytes to drop
      • sliceBuffersTo

        public java.nio.ByteBuffer[] sliceBuffersTo​(long to)
        This method will return an array of ByteBuffer representing the bytes from the beginning of this buffer up through the index argument that was passed. The buffers will be duplicates of the internal buffers, so any modifications to the markers Buffer.position(), Buffer.limit(), etc will not modify the this class.
        Parameters:
        to - the index to slice up to
        Returns:
        the byte buffers
      • sliceAndRetainPagesTo

        public Page[] sliceAndRetainPagesTo​(long to)
        This method will return an array of Page representing the bytes from the beginning of this buffer up through the index argument that was passed. The pages and buffers will be duplicates of the internal components, so any modifications to the markers Buffer.position(), Buffer.limit(), etc will not modify the this class. Additionally, this will internally retain the underlying pages, so the pages returned by this method must be closed.
        Parameters:
        to - the index to slice up to
        Returns:
        the pages
      • sliceBuffersFrom

        public java.nio.ByteBuffer[] sliceBuffersFrom​(long from)
        This method will return an array of ByteBuffer representing the bytes from the index passed through the end of this buffer. The buffers will be duplicates of the internal buffers, so any modifications to the markers Buffer.position(), Buffer.limit(), etc will not modify the this class.
        Parameters:
        from - the index to slice from
        Returns:
        the byte buffers
      • incrementIndex

        public void incrementIndex​(long delta)
      • getIndex

        public long getIndex()
      • getCapacity

        public long getCapacity()
      • getRemaining

        public long getRemaining()