Interface AllocationListener


public interface AllocationListener
An allocation listener being notified for allocation/deallocation

It might be called from multiple threads if the allocator hierarchy shares a listener, in which case, the provider should take care of making the implementation thread-safe.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final AllocationListener
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    onAllocation(long size)
    Called each time a new buffer has been allocated.
    default void
    onChildAdded(BufferAllocator parentAllocator, BufferAllocator childAllocator)
    Called immediately after a child allocator was added to the parent allocator.
    default void
    onChildRemoved(BufferAllocator parentAllocator, BufferAllocator childAllocator)
    Called immediately after a child allocator was removed from the parent allocator.
    default boolean
    Called whenever an allocation failed, giving the caller a chance to create some space in the allocator (either by freeing some resource, or by changing the limit), and, if successful, allowing the allocator to retry the allocation.
    default void
    onPreAllocation(long size)
    Called each time a new buffer has been requested.
    default void
    onRelease(long size)
    Informed each time a buffer is released from allocation.
  • Field Details

  • Method Details

    • onPreAllocation

      default void onPreAllocation(long size)
      Called each time a new buffer has been requested.

      An exception can be safely thrown by this method to terminate the allocation.

      Parameters:
      size - the buffer size being allocated
    • onAllocation

      default void onAllocation(long size)
      Called each time a new buffer has been allocated.

      An exception cannot be thrown by this method.

      Parameters:
      size - the buffer size being allocated
    • onRelease

      default void onRelease(long size)
      Informed each time a buffer is released from allocation.

      An exception cannot be thrown by this method.

      Parameters:
      size - The size of the buffer being released.
    • onFailedAllocation

      default boolean onFailedAllocation(long size, AllocationOutcome outcome)
      Called whenever an allocation failed, giving the caller a chance to create some space in the allocator (either by freeing some resource, or by changing the limit), and, if successful, allowing the allocator to retry the allocation.
      Parameters:
      size - the buffer size that was being allocated
      outcome - the outcome of the failed allocation. Carries information of what failed
      Returns:
      true, if the allocation can be retried; false if the allocation should fail
    • onChildAdded

      default void onChildAdded(BufferAllocator parentAllocator, BufferAllocator childAllocator)
      Called immediately after a child allocator was added to the parent allocator.
      Parameters:
      parentAllocator - The parent allocator to which a child was added
      childAllocator - The child allocator that was just added
    • onChildRemoved

      default void onChildRemoved(BufferAllocator parentAllocator, BufferAllocator childAllocator)
      Called immediately after a child allocator was removed from the parent allocator.
      Parameters:
      parentAllocator - The parent allocator from which a child was removed
      childAllocator - The child allocator that was just removed