Class AbstractPool<I,O>

java.lang.Object
org.apache.activemq.artemis.utils.AbstractPool<I,O>
Direct Known Subclasses:
SimpleString.StringSimpleStringPool

public abstract class AbstractPool<I,O> 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 Details

  • Constructor Details

    • AbstractPool

      public AbstractPool()
    • AbstractPool

      public AbstractPool(int capacity)
  • Method Details

    • create

      protected abstract O create(I value)
      Create a new entry.
    • isEqual

      protected abstract boolean isEqual(O entry, I value)
      Returns true if the entry content is equal to value;.
      Returns:
      true if the entry content is equal to value;
    • hashCode

      protected int hashCode(I value)
    • getOrCreate

      public final O getOrCreate(I value)
      Returns and interned entry if possible, a new one otherwise.

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