Package io.netty.channel.pool
Class FixedChannelPool
java.lang.Object
io.netty.channel.pool.SimpleChannelPool
io.netty.channel.pool.FixedChannelPool
- All Implemented Interfaces:
ChannelPool,Closeable,AutoCloseable
ChannelPool implementation that takes another ChannelPool implementation and enforce a maximum
number of concurrent connections.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate final classstatic enumprivate static final classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprivate final longprivate booleanprivate final EventExecutorprivate final intprivate final intprivate intprivate final Queue<FixedChannelPool.AcquireTask> private final Runnable -
Constructor Summary
ConstructorsConstructorDescriptionFixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections) Creates a new instance using theChannelHealthChecker.ACTIVE.FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires) Creates a new instance using theChannelHealthChecker.ACTIVE.FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires) Creates a new instance.FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck) Creates a new instance.FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, boolean lastRecentUsed) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionAcquire aChannelfrom thisChannelPool.private voidintReturns the number of acquired channels that this pool thinks it has.voidclose()close0()Closes the pool in an async manner.private voidRelease aChannelback to thisChannelPool.private voidprivate voidtooManyOutstanding(Promise<?> promise) Methods inherited from class io.netty.channel.pool.SimpleChannelPool
acquire, bootstrap, connectChannel, handler, healthChecker, offerChannel, pollChannel, release, releaseHealthCheck
-
Field Details
-
executor
-
acquireTimeoutNanos
private final long acquireTimeoutNanos -
timeoutTask
-
pendingAcquireQueue
-
maxConnections
private final int maxConnections -
maxPendingAcquires
private final int maxPendingAcquires -
acquiredChannelCount
-
pendingAcquireCount
private int pendingAcquireCount -
closed
private boolean closed
-
-
Constructor Details
-
FixedChannelPool
Creates a new instance using theChannelHealthChecker.ACTIVE.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionsmaxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill 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 theChannelHealthChecker.ACTIVE.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionsmaxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill 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- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPoolaction- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill 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- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPoolaction- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill 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 totrue.
-
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- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPoolaction- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill 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 totrue.lastRecentUsed-trueChannelselection will be LIFO, iffalseFIFO.
-
-
Method Details
-
acquiredChannelCount
public int acquiredChannelCount()Returns the number of acquired channels that this pool thinks it has. -
acquire
Description copied from interface:ChannelPoolAcquire aChannelfrom thisChannelPool. The givenPromiseis notified once the acquire is successful and failed otherwise. Its important that an acquired is always released to the pool again, even if theChannelis explicitly closed..- Specified by:
acquirein interfaceChannelPool- Overrides:
acquirein classSimpleChannelPool
-
acquire0
-
tooManyOutstanding
-
release
Description copied from interface:ChannelPoolRelease aChannelback to thisChannelPool. The givenPromiseis notified once the release is successful and failed otherwise. When failed theChannelwill automatically closed.- Specified by:
releasein interfaceChannelPool- Overrides:
releasein classSimpleChannelPool
-
decrementAndRunTaskQueue
private void decrementAndRunTaskQueue() -
runTaskQueue
private void runTaskQueue() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannelPool- Specified by:
closein interfaceCloseable- Overrides:
closein classSimpleChannelPool
-
closeAsync
Closes the pool in an async manner.- Overrides:
closeAsyncin classSimpleChannelPool- Returns:
- Future which represents completion of the close task
-
close0
-