Class AbstractByteBufPool<T>

java.lang.Object
org.apache.activemq.artemis.utils.AbstractByteBufPool<T>
Direct Known Subclasses:
SimpleString.ByteBufSimpleStringPool, TypedProperties.StringValue.ByteBufStringValuePool

public abstract class AbstractByteBufPool<T> extends Object
Thread-safe <T> interner.

Differently from String.intern() it contains a fixed amount of entries and when used by concurrent threads it doesn't ensure the uniqueness of the entries ie the same entry could be allocated multiple times by concurrent calls.

  • Field Summary

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

    Constructors
    Constructor
    Description
     
    AbstractByteBufPool(int capacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    canPool(io.netty.buffer.ByteBuf byteBuf, int length)
    Returns true if length's byteBuf content from ByteBuf.readerIndex() can be pooled, false otherwise.
    protected abstract T
    create(io.netty.buffer.ByteBuf byteBuf, int length)
    Create a new entry.
    final T
    getOrCreate(io.netty.buffer.ByteBuf byteBuf)
    Returns a pooled entry if possible, a new one otherwise.
    protected abstract boolean
    isEqual(T entry, io.netty.buffer.ByteBuf byteBuf, int offset, int length)
    Returns true if the entry content is the same of byteBuf at the specified offset and length false otherwise.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AbstractByteBufPool

      public AbstractByteBufPool()
    • AbstractByteBufPool

      public AbstractByteBufPool(int capacity)
  • Method Details

    • canPool

      protected abstract boolean canPool(io.netty.buffer.ByteBuf byteBuf, int length)
      Returns true if length's byteBuf content from ByteBuf.readerIndex() can be pooled, false otherwise.
      Returns:
      true if length's byteBuf content from ByteBuf.readerIndex() can be pooled, false otherwise
    • create

      protected abstract T create(io.netty.buffer.ByteBuf byteBuf, int length)
      Create a new entry.
    • isEqual

      protected abstract boolean isEqual(T entry, io.netty.buffer.ByteBuf byteBuf, int offset, int length)
      Returns true if the entry content is the same of byteBuf at the specified offset and length false otherwise.
      Returns:
      true if the entry content is the same of byteBuf at the specified offset and length false otherwise
    • getOrCreate

      public final T getOrCreate(io.netty.buffer.ByteBuf byteBuf)
      Returns a pooled entry if possible, a new one otherwise.

      The byteBuf's ByteBuf.readerIndex() is incremented by length after it.