Class FixedChannelPool

java.lang.Object
io.netty.channel.pool.SimpleChannelPool
io.netty.channel.pool.FixedChannelPool
All Implemented Interfaces:
ChannelPool, java.io.Closeable, java.lang.AutoCloseable

public class FixedChannelPool extends SimpleChannelPool
ChannelPool implementation that takes another ChannelPool implementation and enforce a maximum number of concurrent connections.
  • Field Details

    • executor

      private final EventExecutor executor
    • acquireTimeoutNanos

      private final long acquireTimeoutNanos
    • timeoutTask

      private final java.lang.Runnable timeoutTask
    • pendingAcquireQueue

      private final java.util.Queue<FixedChannelPool.AcquireTask> pendingAcquireQueue
    • maxConnections

      private final int maxConnections
    • maxPendingAcquires

      private final int maxPendingAcquires
    • acquiredChannelCount

      private final java.util.concurrent.atomic.AtomicInteger acquiredChannelCount
    • pendingAcquireCount

      private int pendingAcquireCount
    • closed

      private boolean closed
  • Constructor Details

    • FixedChannelPool

      public FixedChannelPool(Bootstrap bootstrap, 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.
    • FixedChannelPool

      public FixedChannelPool(Bootstrap bootstrap, 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.
    • FixedChannelPool

      public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, 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 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.
    • FixedChannelPool

      public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, 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 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.
    • FixedChannelPool

      public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, boolean lastRecentUsed)
      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 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.
      lastRecentUsed - true Channel selection will be LIFO, if false FIFO.
  • Method Details

    • acquiredChannelCount

      public int acquiredChannelCount()
      Returns the number of acquired channels that this pool thinks it has.
    • acquire

      public Future<Channel> acquire(Promise<Channel> promise)
      Description copied from interface: ChannelPool
      Acquire a Channel from this ChannelPool. The given Promise 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
      Overrides:
      acquire in class SimpleChannelPool
    • acquire0

      private void acquire0(Promise<Channel> promise)
    • tooManyOutstanding

      private void tooManyOutstanding(Promise<?> promise)
    • release

      public Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
      Description copied from interface: ChannelPool
      Release a Channel back to this ChannelPool. The given Promise is notified once the release is successful and failed otherwise. When failed the Channel will automatically closed.
      Specified by:
      release in interface ChannelPool
      Overrides:
      release in class SimpleChannelPool
    • decrementAndRunTaskQueue

      private void decrementAndRunTaskQueue()
    • runTaskQueue

      private void runTaskQueue()
    • 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
      Overrides:
      close in class SimpleChannelPool
    • closeAsync

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

      private Future<java.lang.Void> close0()