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 class
private final class
static enum
private static final class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicInteger
private final long
private boolean
private final EventExecutor
private final int
private final int
private int
private 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 aChannel
from thisChannelPool
.private void
int
Returns the number of acquired channels that this pool thinks it has.void
close()
close0()
Closes the pool in an async manner.private void
Release aChannel
back to thisChannelPool
.private void
private void
tooManyOutstanding
(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
- 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 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 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 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 Details
-
acquiredChannelCount
public int acquiredChannelCount()Returns the number of acquired channels that this pool thinks it has. -
acquire
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
-
acquire0
-
tooManyOutstanding
-
release
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
-
decrementAndRunTaskQueue
private void decrementAndRunTaskQueue() -
runTaskQueue
private void runTaskQueue() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannelPool
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classSimpleChannelPool
-
closeAsync
Closes the pool in an async manner.- Overrides:
closeAsync
in classSimpleChannelPool
- Returns:
- Future which represents completion of the close task
-
close0
-