Class AbstractPool<I,​O>

  • Direct Known Subclasses:
    SimpleString.StringSimpleStringPool

    public abstract class AbstractPool<I,​O>
    extends java.lang.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.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract O create​(I value)
      Create a new entry.
      O getOrCreate​(I value)
      Returns and interned entry if possible, a new one otherwise.
      protected int hashCode​(I value)  
      protected abstract boolean isEqual​(O entry, I value)
      Returns true if the entry content is equal to value;
      • Methods inherited from class java.lang.Object

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

    • Constructor Detail

      • AbstractPool

        public AbstractPool()
      • AbstractPool

        public AbstractPool​(int capacity)
    • Method Detail

      • 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;
      • 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.