Class Netty4ProtonBufferAllocator

java.lang.Object
org.apache.qpid.protonj2.buffer.netty.Netty4ProtonBufferAllocator
All Implemented Interfaces:
AutoCloseable, ProtonBufferAllocator

public final class Netty4ProtonBufferAllocator extends Object implements ProtonBufferAllocator
Proton managed Netty 4 ByteBufAllocator wrapper.
  • Field Details

  • Constructor Details

    • Netty4ProtonBufferAllocator

      public Netty4ProtonBufferAllocator(io.netty.buffer.ByteBufAllocator allocator)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ProtonBufferAllocator
    • allocator

      public io.netty.buffer.ByteBufAllocator allocator()
    • wrap

      public Netty4ToProtonBufferAdapter wrap(io.netty.buffer.ByteBuf buffer)
      Creates a ProtonBuffer wrapper around the given Netty 4 based ByteBuf instance. The method wraps a ByteBuf and assumes ownership of it which means that once the wrapper buffer is closed it will release the ByteBuf which if there are no other references will render the wrapped buffer closed and recyclable if pooled. Care should be take when supplying the buffer to add a reference depending on the source of the buffer.
      Parameters:
      buffer - The buffer instance to wrap.
      Returns:
      A ProtonBuffer instance that wraps the given netty buffer.
    • outputBuffer

      public Netty4ToProtonBufferAdapter outputBuffer(int initialCapacity)
      Description copied from interface: ProtonBufferAllocator
      Create a new output ProtonBuffer instance with the given initial capacity and the implicit growth capacity should be that of the underlying buffer implementations limit. The buffer implementation should support growing the buffer on an as needed basis to allow writes without the user needing to code extra capacity and buffer reallocation checks.

      The returned buffer will be used for frame output from the Proton engine and can be a pooled buffer which the IO handler will then need to release once the buffer has been written.

      Specified by:
      outputBuffer in interface ProtonBufferAllocator
      Parameters:
      initialCapacity - The initial capacity to use when creating the new ProtonBuffer.
      Returns:
      a new ProtonBuffer instance with the given initial capacity.
    • allocate

      public Netty4ToProtonBufferAdapter allocate()
      Description copied from interface: ProtonBufferAllocator
      Create a new ProtonBuffer instance with default initial capacity. The buffer implementation should support growing the buffer on an as needed basis to allow writes without the user needing to code extra capacity and buffer reallocation checks.

      Proton buffers are closable resources and their life-span requires that they be closed upon reaching their determined end of life.

      Specified by:
      allocate in interface ProtonBufferAllocator
      Returns:
      a new ProtonBuffer instance with default initial capacity.
    • allocate

      public Netty4ToProtonBufferAdapter allocate(int initialCapacity)
      Description copied from interface: ProtonBufferAllocator
      Create a new ProtonBuffer instance with the given initial capacity and the implicit growth limit should be that of the underlying buffer implementations maximum capacity limit.

      Proton buffers are closable resources and their life-span requires that they be closed upon reaching their determined end of life.

      Specified by:
      allocate in interface ProtonBufferAllocator
      Parameters:
      initialCapacity - The initial capacity to use when creating the new ProtonBuffer.
      Returns:
      a new ProtonBuffer instance with the given initial capacity.
    • allocateHeapBuffer

      public Netty4ToProtonBufferAdapter allocateHeapBuffer()
      Description copied from interface: ProtonBufferAllocator
      Create a new ProtonBuffer instance with default initial capacity. The buffer implementation should support growing the buffer on an as needed basis to allow writes without the user needing to code extra capacity and buffer reallocation checks. The buffer allocated must be a heap buffer for cases where the buffered resource may not be easily closed and must revert to GC reclaim semantics.

      Proton buffers are closable resources and their life-span requires that they be closed upon reaching their determined end of life.

      Specified by:
      allocateHeapBuffer in interface ProtonBufferAllocator
      Returns:
      a new ProtonBuffer instance with default initial capacity.
    • allocateHeapBuffer

      public Netty4ToProtonBufferAdapter allocateHeapBuffer(int initialCapacity)
      Description copied from interface: ProtonBufferAllocator
      Create a new ProtonBuffer instance with the given initial capacity and the implicit growth limit should be that of the underlying buffer implementations maximum capacity limit. The buffer allocated must be a heap buffer for cases where the buffered resource may not be easily closed and must revert to GC reclaim semantics.

      Proton buffers are closable resources and their life-span requires that they be closed upon reaching their determined end of life.

      Specified by:
      allocateHeapBuffer in interface ProtonBufferAllocator
      Parameters:
      initialCapacity - The initial capacity to use when creating the new ProtonBuffer.
      Returns:
      a new ProtonBuffer instance with the given initial capacity.
    • copy

      public Netty4ToProtonBufferAdapter copy(byte[] array, int offset, int length)
      Description copied from interface: ProtonBufferAllocator
      Create a new ProtonBuffer that copies the given byte array using the provided offset and length values to confine the view of that array.

      The initial capacity of the buffer should be that of the length of the wrapped array. The returned buffer can be expanded using the normal write or expand methods. The write offset of the returned buffer will be set to the capacity.

      Changes to the input buffer after calling this method will not affect the contents of the returned buffer copy.

      Specified by:
      copy in interface ProtonBufferAllocator
      Parameters:
      array - the byte array to copy.
      offset - the offset into the array where the view begins.
      length - the number of bytes in the array to expose
      Returns:
      a new ProtonBuffer that is a copy of the given array.
    • composite

      public ProtonCompositeBuffer composite()
      Description copied from interface: ProtonBufferAllocator
      Creates a new composite buffer instance that uses this allocator to create new backing space when the buffer writes exceed capacity or the ensure writable space API is used. The created buffer will be empty and can be expanded with the normal buffer API or extended with the addition of buffers.
      Specified by:
      composite in interface ProtonBufferAllocator
      Returns:
      a new empty composite buffer instance.
    • composite

      public ProtonCompositeBuffer composite(ProtonBuffer buffer)
      Description copied from interface: ProtonBufferAllocator
      Creates a new composite buffer instance that uses this allocator to create new backing space when the buffer writes exceed capacity or the ensure writable space API is used. The created buffer will be composed of the given sequence of buffers.
      Specified by:
      composite in interface ProtonBufferAllocator
      Parameters:
      buffer - the buffers to compose
      Returns:
      a new composite buffer instance.
    • composite

      public ProtonCompositeBuffer composite(ProtonBuffer[] buffers)
      Description copied from interface: ProtonBufferAllocator
      Creates a new composite buffer instance that uses this allocator to create new backing space when the buffer writes exceed capacity or the ensure writable space API is used. The created buffer will be composed of the given sequence of buffers.
      Specified by:
      composite in interface ProtonBufferAllocator
      Parameters:
      buffers - the array of buffers to compose
      Returns:
      a new composite buffer instance.