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
ChannelPool
implementation that takes anotherChannelPool
implementation and enforce a maximum number of concurrent connections.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FixedChannelPool.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 aChannel
from thisChannelPool
.int
acquiredChannelCount()
Returns the number of acquired channels that this pool thinks it has.void
close()
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 aChannel
back 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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
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 theChannelHealthChecker.ACTIVE
.- Parameters:
bootstrap
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from theChannelPool
action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
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 theFixedChannelPool.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from theChannelPool
action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
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 theFixedChannelPool.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
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 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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from theChannelPool
action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
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 theFixedChannelPool.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
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 totrue
.lastRecentUsed
-true
Channel
selection will be LIFO, iffalse
FIFO.
-
-
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:ChannelPool
Acquire aChannel
from thisChannelPool
. The givenPromise
is notified once the acquire is successful and failed otherwise. Its important that an acquired is always released to the pool again, even if theChannel
is explicitly closed..- Specified by:
acquire
in interfaceChannelPool
- Overrides:
acquire
in classSimpleChannelPool
-
release
public Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
Description copied from interface:ChannelPool
Release aChannel
back to thisChannelPool
. The givenPromise
is notified once the release is successful and failed otherwise. When failed theChannel
will automatically closed.- Specified by:
release
in interfaceChannelPool
- Overrides:
release
in classSimpleChannelPool
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceChannelPool
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classSimpleChannelPool
-
closeAsync
public Future<java.lang.Void> closeAsync()
Closes the pool in an async manner.- Overrides:
closeAsync
in classSimpleChannelPool
- Returns:
- Future which represents completion of the close task
-
-