Class AbstractChannelPoolMap<K,​P extends ChannelPool>

  • All Implemented Interfaces:
    ChannelPoolMap<K,​P>, java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<java.util.Map.Entry<K,​P>>

    public abstract class AbstractChannelPoolMap<K,​P extends ChannelPool>
    extends java.lang.Object
    implements ChannelPoolMap<K,​P>, java.lang.Iterable<java.util.Map.Entry<K,​P>>, java.io.Closeable
    A skeletal ChannelPoolMap implementation. To find the right ChannelPool the Object.hashCode() and Object.equals(Object) is used.
    • Field Detail

      • map

        private final java.util.concurrent.ConcurrentMap<K,​P extends ChannelPool> map
    • Constructor Detail

      • AbstractChannelPoolMap

        public AbstractChannelPoolMap()
    • Method Detail

      • get

        public final P get​(K key)
        Description copied from interface: ChannelPoolMap
        Return the ChannelPool for the code. This will never return null, but create a new ChannelPool if non exists for they requested key. Please note that null keys are not allowed.
        Specified by:
        get in interface ChannelPoolMap<K,​P extends ChannelPool>
      • remove

        public final boolean remove​(K key)
        Remove the ChannelPool from this AbstractChannelPoolMap. Returns true if removed, false otherwise. If the removed pool extends SimpleChannelPool it will be closed asynchronously to avoid blocking in this method. Please note that null keys are not allowed.
      • removeAsyncIfSupported

        private Future<java.lang.Boolean> removeAsyncIfSupported​(K key)
        Remove the ChannelPool from this AbstractChannelPoolMap. Returns a future that comletes with a true result if the pool has been removed by this call, otherwise the result is false. If the removed pool extends SimpleChannelPool it will be closed asynchronously to avoid blocking in this method. The returned future will be completed once this asynchronous pool close operation completes.
      • poolCloseAsyncIfSupported

        private static Future<java.lang.Void> poolCloseAsyncIfSupported​(ChannelPool pool)
        If the pool implementation supports asynchronous close, then use it to avoid a blocking close call in case the ChannelPoolMap operations are called from an EventLoop.
        Parameters:
        pool - the ChannelPool to be closed
      • iterator

        public final java.util.Iterator<java.util.Map.Entry<K,​P>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<K>
      • isEmpty

        public final boolean isEmpty()
        Returns true if the AbstractChannelPoolMap is empty, otherwise false.
      • newPool

        protected abstract P newPool​(K key)
        Called once a new ChannelPool needs to be created as non exists yet for the key.
      • close

        public final void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable