public final class FixedChannelPool extends SimpleChannelPool
ChannelPool
implementation that takes another ChannelPool
implementation and enforce a maximum
number of concurrent connections.Modifier and Type | Class and Description |
---|---|
private class |
FixedChannelPool.AcquireListener |
private class |
FixedChannelPool.AcquireTask |
static class |
FixedChannelPool.AcquireTimeoutAction |
private class |
FixedChannelPool.TimeoutTask |
Modifier and Type | Field and Description |
---|---|
private int |
acquiredChannelCount |
private long |
acquireTimeoutNanos |
private boolean |
closed |
private EventExecutor |
executor |
private static java.lang.IllegalStateException |
FULL_EXCEPTION |
private int |
maxConnections |
private int |
maxPendingAcquires |
private int |
pendingAcquireCount |
private java.util.Queue<FixedChannelPool.AcquireTask> |
pendingAcquireQueue |
private static java.util.concurrent.TimeoutException |
TIMEOUT_EXCEPTION |
private java.lang.Runnable |
timeoutTask |
Constructor and Description |
---|
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,
int maxConnections)
Creates a new instance using the
ChannelHealthChecker.ACTIVE . |
FixedChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler,
int maxConnections,
int maxPendingAcquires)
Creates a new instance using the
ChannelHealthChecker.ACTIVE . |
Modifier and Type | Method and Description |
---|---|
Future<Channel> |
acquire(Promise<Channel> promise)
Acquire a
Channel from this ChannelPool . |
private void |
acquire0(Promise<Channel> promise) |
void |
close() |
private void |
decrementAndRunTaskQueue() |
Future<java.lang.Void> |
release(Channel channel,
Promise<java.lang.Void> promise)
Release a
Channel back to this ChannelPool . |
private void |
runTaskQueue() |
acquire, connectChannel, offerChannel, pollChannel, release
private static final java.lang.IllegalStateException FULL_EXCEPTION
private static final java.util.concurrent.TimeoutException TIMEOUT_EXCEPTION
private final EventExecutor executor
private final long acquireTimeoutNanos
private final java.lang.Runnable timeoutTask
private final java.util.Queue<FixedChannelPool.AcquireTask> pendingAcquireQueue
private final int maxConnections
private final int maxPendingAcquires
private int acquiredChannelCount
private int pendingAcquireCount
private boolean closed
public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections)
ChannelHealthChecker.ACTIVE
.bootstrap
- the Bootstrap
that is used for connectionshandler
- the ChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the numnber of maximal active connections, once this is reached new tries to acquire
a Channel
will be delayed until a connection is returned to the pool again.public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)
ChannelHealthChecker.ACTIVE
.bootstrap
- the Bootstrap
that is used for connectionshandler
- the ChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the numnber of maximal active connections, once this is reached new tries to
acquire a Channel
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.public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires)
bootstrap
- the Bootstrap
that is used for connectionshandler
- the ChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- the ChannelHealthChecker
that will be used to check if a Channel
is
still healty when obtain from the ChannelPool
action
- the FixedChannelPool.AcquireTimeoutAction
to use or null
if non should be used.
In this case must be -1
.acquireTimeoutMillis
- the time (in milliseconds) after which an pending acquire must complete or
the FixedChannelPool.AcquireTimeoutAction
takes place.maxConnections
- the numnber of maximal active connections, once this is reached new tries to
acquire a Channel
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.public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck)
bootstrap
- the Bootstrap
that is used for connectionshandler
- the ChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- the ChannelHealthChecker
that will be used to check if a Channel
is
still healty when obtain from the ChannelPool
action
- the FixedChannelPool.AcquireTimeoutAction
to use or null
if non should be used.
In this case must be -1
.acquireTimeoutMillis
- the time (in milliseconds) after which an pending acquire must complete or
the FixedChannelPool.AcquireTimeoutAction
takes place.maxConnections
- the numnber of maximal active connections, once this is reached new tries to
acquire a Channel
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 to
true
.public Future<Channel> acquire(Promise<Channel> promise)
ChannelPool
Channel
from this ChannelPool
. The given Promise
is notified once
the acquire is successful and failed otherwise.
Its important that an acquired is always released to the pool again, even if the Channel
is explicitly closed..acquire
in interface ChannelPool
acquire
in class SimpleChannelPool
public Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
ChannelPool
Channel
back to this ChannelPool
. The given Promise
is notified once
the release is successful and failed otherwise. When failed the Channel
will automatically closed.release
in interface ChannelPool
release
in class SimpleChannelPool
private void decrementAndRunTaskQueue()
private void runTaskQueue()
public void close()
close
in interface ChannelPool
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class SimpleChannelPool