Class FastFixedChannelPool

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

    public class FastFixedChannelPool
    extends FastSimpleChannelPool
    implements ChannelPoolWithStats
    Forked from Netty's FixedChannelPool {ChannelPool} implementation that takes another {ChannelPool} implementation and enforce a maximum number of concurrent connections.
    • Constructor Summary

      Constructors 
      Constructor Description
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections)
      Creates a new instance using the ChannelHealthChecker.ACTIVE.
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)
      Creates a new instance using the ChannelHealthChecker.ACTIVE.
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires)
      Creates a new instance.
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck)
      Creates a new instance.
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)
      Creates a new instance.
      FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, java.util.function.IntSupplier maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)
      Creates a new instance.
    • Field Detail

      • _channelGroup

        protected final io.netty.channel.group.ChannelGroup _channelGroup
    • Constructor Detail

      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    int maxConnections)
        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
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    int maxConnections,
                                    int maxPendingAcquires)
        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
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
        maxPendingAcquires - the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                    io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action,
                                    long acquireTimeoutMillis,
                                    int maxConnections,
                                    int maxPendingAcquires)
        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}
        action - the FixedChannelPool.AcquireTimeoutAction to use or null if non should be used. In this case {@param acquireTimeoutMillis} must be -1.
        acquireTimeoutMillis - the time (in milliseconds) after which an pending acquire must complete or the FixedChannelPool.AcquireTimeoutAction takes place.
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
        maxPendingAcquires - the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                    io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action,
                                    long acquireTimeoutMillis,
                                    int maxConnections,
                                    int maxPendingAcquires,
                                    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}
        action - the FixedChannelPool.AcquireTimeoutAction to use or null if non should be used. In this case acquireTimeoutMillis must be -1.
        acquireTimeoutMillis - the time (in milliseconds) after which an pending acquire must complete or the FixedChannelPool.AcquireTimeoutAction takes place.
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
        maxPendingAcquires - the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
        releaseHealthCheck - will check channel health before offering back if this parameter set to true.
      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                    io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action,
                                    long acquireTimeoutMillis,
                                    int maxConnections,
                                    int maxPendingAcquires,
                                    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}
        action - the FixedChannelPool.AcquireTimeoutAction to use or null if non should be used. In this case acquireTimeoutMillis must be -1.
        acquireTimeoutMillis - the time (in milliseconds) after which an pending acquire must complete or the FixedChannelPool.AcquireTimeoutAction takes place.
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
        maxPendingAcquires - the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
        releaseHealthCheck - will check channel health before offering back if this parameter set to true.
        connectConcurrency - the number of concurrent bootstrap.connect() calls permitted
      • FastFixedChannelPool

        public FastFixedChannelPool​(io.netty.bootstrap.Bootstrap bootstrap,
                                    io.netty.channel.pool.ChannelPoolHandler handler,
                                    io.netty.channel.pool.ChannelHealthChecker healthCheck,
                                    io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action,
                                    long acquireTimeoutMillis,
                                    java.util.function.IntSupplier maxConnections,
                                    int maxPendingAcquires,
                                    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}
        action - the FixedChannelPool.AcquireTimeoutAction to use or null if non should be used. In this case acquireTimeoutMillis must be -1.
        acquireTimeoutMillis - the time (in milliseconds) after which an pending acquire must complete or the FixedChannelPool.AcquireTimeoutAction takes place.
        maxConnections - the number of maximal active connections, once this is reached new tries to acquire a Channel will be delayed until a connection is returned to the pool again.
        maxPendingAcquires - the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
        releaseHealthCheck - will check channel health before offering back if this parameter set to true.
        connectConcurrency - the number of concurrent bootstrap.connect() calls permitted
    • Method Detail

      • isPoolClosed

        public boolean isPoolClosed()
      • setMaxConnections

        public void setMaxConnections​(java.util.function.IntSupplier maxConnections)
      • acquiredChannelCount

        public int acquiredChannelCount()
        Returns the number of acquired channels that this pool thinks it has.
      • 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
        Overrides:
        acquire in class FastSimpleChannelPool
      • 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)
        Initiate establishing a new connection with the provided bootstrap. This implementation attempts to not exceed a preset number of max connections by storing deferred connections that would have caused the number of connections to be exceeded in the _pendingConnect queue. As connections are established, they are added to _channelGroup.
        Overrides:
        connectChannel in class FastSimpleChannelPool
        Parameters:
        bs - Channel Bootstrap
        promise - Promise to complete with result of Bootstrap connect
        Returns:
        the promise
      • 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
        Overrides:
        release in class FastSimpleChannelPool
      • 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
        Overrides:
        close in class FastSimpleChannelPool
      • closeAsync

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