public class SimpleChannelPool extends java.lang.Object implements ChannelPool
ChannelPool implementation which will create new Channels if someone tries to acquire
a Channel but none is in the pool atm. No limit on the maximal concurrent Channels is enforced.
This implementation uses LIFO order for Channels in the ChannelPool.| 构造器和说明 |
|---|
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler)
Creates a new instance using the
ChannelHealthChecker.ACTIVE. |
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler,
ChannelHealthChecker healthCheck)
Creates a new instance.
|
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler,
ChannelHealthChecker healthCheck,
boolean releaseHealthCheck)
Creates a new instance.
|
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler,
ChannelHealthChecker healthCheck,
boolean releaseHealthCheck,
boolean lastRecentUsed)
Creates a new instance.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Future<Channel> |
acquire()
Acquire a
Channel from this ChannelPool. |
Future<Channel> |
acquire(Promise<Channel> promise)
Acquire a
Channel from this ChannelPool. |
protected Bootstrap |
bootstrap()
Returns the
Bootstrap this pool will use to open new connections. |
void |
close() |
Future<java.lang.Void> |
closeAsync()
Closes the pool in an async manner.
|
protected ChannelFuture |
connectChannel(Bootstrap bs)
Bootstrap a new
Channel. |
protected ChannelPoolHandler |
handler()
Returns the
ChannelPoolHandler that will be notified for the different pool actions. |
protected ChannelHealthChecker |
healthChecker()
Returns the
ChannelHealthChecker that will be used to check if a Channel is healthy. |
protected boolean |
offerChannel(Channel channel)
Offer a
Channel back to the internal storage. |
protected Channel |
pollChannel()
Poll a
Channel out of the internal storage to reuse it. |
Future<java.lang.Void> |
release(Channel channel)
Release a
Channel back to this ChannelPool. |
Future<java.lang.Void> |
release(Channel channel,
Promise<java.lang.Void> promise)
Release a
Channel back to this ChannelPool. |
protected boolean |
releaseHealthCheck()
Indicates whether this pool will check the health of channels before offering them back into the pool.
|
public SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler)
ChannelHealthChecker.ACTIVE.bootstrap - the Bootstrap that is used for connectionshandler - the ChannelPoolHandler that will be notified for the different pool actionspublic SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck)
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 healthy when obtain from the ChannelPoolpublic SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, 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 healthy when obtain from the ChannelPoolreleaseHealthCheck - will check channel health before offering back if this parameter set to true;
otherwise, channel health is only checked at acquisition timepublic SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, boolean releaseHealthCheck, boolean lastRecentUsed)
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 healthy when obtain from the ChannelPoolreleaseHealthCheck - will check channel health before offering back if this parameter set to true;
otherwise, channel health is only checked at acquisition timelastRecentUsed - true Channel selection will be LIFO, if false FIFO.protected Bootstrap bootstrap()
Bootstrap this pool will use to open new connections.Bootstrap this pool will use to open new connectionsprotected ChannelPoolHandler handler()
ChannelPoolHandler that will be notified for the different pool actions.ChannelPoolHandler that will be notified for the different pool actionsprotected ChannelHealthChecker healthChecker()
ChannelHealthChecker that will be used to check if a Channel is healthy.ChannelHealthChecker that will be used to check if a Channel is healthyprotected boolean releaseHealthCheck()
true if this pool will check the health of channels before offering them back into the pool, or
false if channel health is only checked at acquisition timepublic final Future<Channel> acquire()
ChannelPoolChannel from this ChannelPool. The returned Future 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 在接口中 ChannelPoolpublic Future<Channel> acquire(Promise<Channel> promise)
ChannelPoolChannel 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 在接口中 ChannelPoolprotected ChannelFuture connectChannel(Bootstrap bs)
Channel. The default implementation uses Bootstrap.connect(), sub-classes may
override this.
The Bootstrap that is passed in here is cloned via Bootstrap.clone(), so it is safe to modify.
public final Future<java.lang.Void> release(Channel channel)
ChannelPoolChannel back to this ChannelPool. The returned Future is notified once
the release is successful and failed otherwise. When failed the Channel will automatically closed.release 在接口中 ChannelPoolpublic Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
ChannelPoolChannel 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 在接口中 ChannelPoolprotected Channel pollChannel()
Channel out of the internal storage to reuse it. This will return null if no
Channel is ready to be reused.
Sub-classes may override pollChannel() and offerChannel(Channel). Be aware that
implementations of these methods needs to be thread-safe!protected boolean offerChannel(Channel channel)
Channel back to the internal storage. This will return true if the Channel
could be added, false otherwise.
Sub-classes may override pollChannel() and offerChannel(Channel). Be aware that
implementations of these methods needs to be thread-safe!public void close()
close 在接口中 ChannelPoolclose 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseablepublic Future<java.lang.Void> closeAsync()