Class AbstractByteBufPool<T>

  • Direct Known Subclasses:
    SimpleString.ByteBufSimpleStringPool, TypedProperties.StringValue.ByteBufStringValuePool

    public abstract class AbstractByteBufPool<T>
    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 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.
      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 Detail

    • Constructor Detail

      • AbstractByteBufPool

        public AbstractByteBufPool()
      • AbstractByteBufPool

        public AbstractByteBufPool​(int capacity)
    • Method Detail

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