Class SimpleChannelPool

  • All Implemented Interfaces:
    ChannelPool, java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    FixedChannelPool

    public class SimpleChannelPool
    extends java.lang.Object
    implements ChannelPool
    Simple ChannelPool implementation which will create new Channels if someone tries to acquire a Channel but none is in the pool atm. No limit on the maximal concurrent Channels is enforced. This implementation uses LIFO order for Channels in the ChannelPool.
    • Method Detail

      • bootstrap

        protected Bootstrap bootstrap()
        Returns the Bootstrap this pool will use to open new connections.
        Returns:
        the Bootstrap this pool will use to open new connections
      • releaseHealthCheck

        protected boolean releaseHealthCheck()
        Indicates whether this pool will check the health of channels before offering them back into the pool.
        Returns:
        true if this pool will check the health of channels before offering them back into the pool, or false if channel health is only checked at acquisition time
      • acquire

        public final Future<Channel> acquire()
        Description copied from interface: ChannelPool
        Acquire a Channel from this ChannelPool. The returned Future is notified once the acquire is successful and failed otherwise. Its important that an acquired is always released to the pool again, even if the Channel is explicitly closed..
        Specified by:
        acquire in interface ChannelPool
      • pollChannel

        protected Channel pollChannel()
        Poll a Channel out of the internal storage to reuse it. This will return null if no Channel is ready to be reused. Sub-classes may override pollChannel() and offerChannel(Channel). Be aware that implementations of these methods needs to be thread-safe!
      • offerChannel

        protected boolean offerChannel​(Channel channel)
        Offer a Channel back to the internal storage. This will return true if the Channel could be added, false otherwise. Sub-classes may override pollChannel() and offerChannel(Channel). Be aware that implementations of these methods needs to be thread-safe!
      • close

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

        public Future<java.lang.Void> closeAsync()
        Closes the pool in an async manner.
        Returns:
        Future which represents completion of the close task