Package io.netty.channel.pool
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
ChannelPoolimplementation that takes anotherChannelPoolimplementation and enforce a maximum number of concurrent connections.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFixedChannelPool.AcquireTimeoutAction
-
Constructor Summary
Constructors Constructor Description FixedChannelPool(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<Channel>acquire(Promise<Channel> promise)Acquire aChannelfrom thisChannelPool.intacquiredChannelCount()Returns the number of acquired channels that this pool thinks it has.voidclose()Future<java.lang.Void>closeAsync()Closes the pool in an async manner.Future<java.lang.Void>release(Channel channel, Promise<java.lang.Void> promise)Release aChannelback to thisChannelPool.-
Methods inherited from class io.netty.channel.pool.SimpleChannelPool
acquire, bootstrap, connectChannel, handler, healthChecker, offerChannel, pollChannel, release, releaseHealthCheck
-
-
-
-
Constructor Detail
-
FixedChannelPool
public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections)
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 {@param acquireTimeoutMillis} 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 {@param acquireTimeoutMillis} 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 {@param acquireTimeoutMillis} 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 Detail
-
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: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
-
release
public Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
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
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceChannelPool- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classSimpleChannelPool
-
closeAsync
public Future<java.lang.Void> closeAsync()
Closes the pool in an async manner.- Overrides:
closeAsyncin classSimpleChannelPool- Returns:
- Future which represents completion of the close task
-
-