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 private class
FixedChannelPool.AcquireListener
private class
FixedChannelPool.AcquireTask
static class
FixedChannelPool.AcquireTimeoutAction
private static class
FixedChannelPool.AcquireTimeoutException
private class
FixedChannelPool.TimeoutTask
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicInteger
acquiredChannelCount
private long
acquireTimeoutNanos
private boolean
closed
private EventExecutor
executor
private int
maxConnections
private int
maxPendingAcquires
private int
pendingAcquireCount
private java.util.Queue<FixedChannelPool.AcquireTask>
pendingAcquireQueue
private java.lang.Runnable
timeoutTask
-
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
.private void
acquire0(Promise<Channel> promise)
int
acquiredChannelCount()
Returns the number of acquired channels that this pool thinks it has.void
close()
private Future<java.lang.Void>
close0()
Future<java.lang.Void>
closeAsync()
Closes the pool in an async manner.private void
decrementAndRunTaskQueue()
Future<java.lang.Void>
release(Channel channel, Promise<java.lang.Void> promise)
Release aChannel
back to thisChannelPool
.private void
runTaskQueue()
private void
tooManyOutstanding(Promise<?> promise)
-
Methods inherited from class io.netty.channel.pool.SimpleChannelPool
acquire, bootstrap, connectChannel, handler, healthChecker, offerChannel, pollChannel, release, releaseHealthCheck
-
-
-
-
Field Detail
-
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 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
-
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 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 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
-
close0
private Future<java.lang.Void> close0()
-
-