Class ShareableBytes


  • public class ShareableBytes
    extends java.lang.Object
    A wrapper for possibly sharing portions of a single, BufferPools.forNetworking() managed, ByteBuffer; optimised for the case where no sharing is necessary. When sharing is necessary, share() method must be invoked by the owning thread before a ShareableBytes instance can be shared with another thread.
    • Method Detail

      • get

        public java.nio.ByteBuffer get()
      • hasRemaining

        public boolean hasRemaining()
      • remaining

        public int remaining()
      • share

        public ShareableBytes share()
        Ensure this ShareableBytes will use atomic operations for updating its count from now on. The first invocation must occur while the calling thread has exclusive access (though there may be more than one 'owner', these must all either be owned by the calling thread or otherwise not being used)
      • release

        public void release()
      • sliceAndConsume

        public ShareableBytes sliceAndConsume​(int length)
        Create a slice over the next length bytes, consuming them from our buffer, and incrementing the owner count
      • wrap

        public static ShareableBytes wrap​(java.nio.ByteBuffer buffer)