Class FastSimpleChannelPool

  • All Implemented Interfaces:
    io.netty.channel.pool.ChannelPool, java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    FastFixedChannelPool

    public class FastSimpleChannelPool
    extends java.lang.Object
    implements io.netty.channel.pool.ChannelPool
    Forked from Netty's SimpleChannelPool 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 FIFO order for Channels in the ChannelPool.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.netty.util.concurrent.ImmediateEventExecutor _immediateEventExecutor  
    • Constructor Summary

      Constructors 
      Constructor Description
      FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler)
      Creates a new instance using the ChannelHealthChecker.ACTIVE.
      FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck)
      Creates a new instance.
      FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, boolean releaseHealthCheck)
      Creates a new instance.
      FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, boolean releaseHealthCheck, int connectConcurrency)
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire()  
      io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)  
      protected boolean acquireConnectSemaphore()  
      protected boolean addWaiter​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)  
      protected io.netty.bootstrap.Bootstrap bootstrap()
      Returns the Bootstrap this pool will use to open new connections.
      protected io.netty.util.concurrent.Future<io.netty.channel.Channel> bootstrapChannel​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)  
      void close()  
      protected static io.netty.channel.ChannelFuture closeChannel​(io.netty.channel.Channel channel)  
      protected io.netty.util.concurrent.Future<io.netty.channel.Channel> connectChannel​(io.netty.bootstrap.Bootstrap bs, io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
      Bootstrap a new Channel.
      protected int connectInProgress()  
      protected int getAvailableChannels()
      Counts the number of idle channels available within the pool.
      protected io.netty.channel.pool.ChannelPoolHandler handler()
      Returns the ChannelPoolHandler that will be notified for the different pool actions.
      protected io.netty.channel.pool.ChannelHealthChecker healthChecker()
      Returns the ChannelHealthChecker that will be used to check if a Channel is healthy.
      protected boolean offerChannel​(io.netty.channel.Channel channel)
      Offer a Channel back to the internal storage.
      protected void onConnect​(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)  
      protected io.netty.channel.Channel pollChannel()
      Poll a Channel out of the internal storage to reuse it.
      io.netty.util.concurrent.Future<java.lang.Void> release​(io.netty.channel.Channel channel)  
      io.netty.util.concurrent.Future<java.lang.Void> release​(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<java.lang.Void> promise)  
      protected void releaseConnectSemaphore()  
      protected boolean releaseHealthCheck()
      Indicates whether this pool will check the health of channels before offering them back into the pool.
      • Methods inherited from class java.lang.Object

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

      • _immediateEventExecutor

        protected final io.netty.util.concurrent.ImmediateEventExecutor _immediateEventExecutor
    • Constructor Detail

      • FastSimpleChannelPool

        public FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                     io.netty.channel.pool.ChannelPoolHandler handler)
        Creates a new instance using the ChannelHealthChecker.ACTIVE.
        Parameters:
        bootstrap - the Bootstrap that is used for connections
        handler - the ChannelPoolHandler that will be notified for the different pool actions
      • FastSimpleChannelPool

        public FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                     io.netty.channel.pool.ChannelPoolHandler handler,
                                     io.netty.channel.pool.ChannelHealthChecker healthCheck)
        Creates a new instance.
        Parameters:
        bootstrap - the Bootstrap that is used for connections
        handler - the ChannelPoolHandler that will be notified for the different pool actions
        healthCheck - the ChannelHealthChecker that will be used to check if a Channel is still healthy when obtain from the ChannelPool
      • FastSimpleChannelPool

        public FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                     io.netty.channel.pool.ChannelPoolHandler handler,
                                     io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                     boolean releaseHealthCheck)
        Creates a new instance.
        Parameters:
        bootstrap - the Bootstrap that is used for connections
        handler - the ChannelPoolHandler that will be notified for the different pool actions
        healthCheck - the ChannelHealthChecker that will be used to check if a Channel is still healthy when obtain from the ChannelPool
        releaseHealthCheck - will check channel health before offering back if this parameter set to true; otherwise, channel health is only checked at acquisition time
      • FastSimpleChannelPool

        public FastSimpleChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                     io.netty.channel.pool.ChannelPoolHandler handler,
                                     io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                     boolean releaseHealthCheck,
                                     int connectConcurrency)
        Creates a new instance.
        Parameters:
        bootstrap - the Bootstrap that is used for connections
        handler - the ChannelPoolHandler that will be notified for the different pool actions
        healthCheck - the ChannelHealthChecker that will be used to check if a Channel is still healthy when obtain from the ChannelPool
        releaseHealthCheck - will check channel health before offering back if this parameter set to true; otherwise, channel health is only checked at acquisition time
        connectConcurrency - the number of concurrent bootstrap.connect() calls permitted
    • Method Detail

      • getAvailableChannels

        protected int getAvailableChannels()
        Counts the number of idle channels available within the pool.
        Returns:
        available channels
      • bootstrap

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

        protected io.netty.channel.pool.ChannelPoolHandler handler()
        Returns the ChannelPoolHandler that will be notified for the different pool actions.
        Returns:
        the ChannelPoolHandler that will be notified for the different pool actions
      • healthChecker

        protected io.netty.channel.pool.ChannelHealthChecker healthChecker()
        Returns the ChannelHealthChecker that will be used to check if a Channel is healthy.
        Returns:
        the ChannelHealthChecker that will be used to check if a Channel is healthy
      • 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 io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire()
        Specified by:
        acquire in interface io.netty.channel.pool.ChannelPool
      • acquire

        public io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
        Specified by:
        acquire in interface io.netty.channel.pool.ChannelPool
      • connectInProgress

        protected final int connectInProgress()
      • acquireConnectSemaphore

        protected boolean acquireConnectSemaphore()
      • bootstrapChannel

        protected io.netty.util.concurrent.Future<io.netty.channel.Channel> bootstrapChannel​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
                                                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • onConnect

        protected void onConnect​(io.netty.channel.Channel channel,
                                 io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
      • releaseConnectSemaphore

        protected final void releaseConnectSemaphore()
      • connectChannel

        protected io.netty.util.concurrent.Future<io.netty.channel.Channel> connectChannel​(io.netty.bootstrap.Bootstrap bs,
                                                                                           io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
        Bootstrap a new Channel. The default implementation uses Bootstrap.connect(), sub-classes may override this.

        The Bootstrap that is passed in here is cloned via Bootstrap.clone(), so it is safe to modify.

        Returns:
      • release

        public final io.netty.util.concurrent.Future<java.lang.Void> release​(io.netty.channel.Channel channel)
        Specified by:
        release in interface io.netty.channel.pool.ChannelPool
      • release

        public io.netty.util.concurrent.Future<java.lang.Void> release​(io.netty.channel.Channel channel,
                                                                       io.netty.util.concurrent.Promise<java.lang.Void> promise)
        Specified by:
        release in interface io.netty.channel.pool.ChannelPool
      • closeChannel

        protected static io.netty.channel.ChannelFuture closeChannel​(io.netty.channel.Channel channel)
      • pollChannel

        protected io.netty.channel.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!
      • addWaiter

        protected boolean addWaiter​(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
      • offerChannel

        protected boolean offerChannel​(io.netty.channel.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 io.netty.channel.pool.ChannelPool
        Specified by:
        close in interface java.io.Closeable