public class SimpleChannelPool extends 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.| Constructor and Description |
|---|
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler)
Creates a new instance using the
ChannelHealthChecker.ACTIVE. |
SimpleChannelPool(Bootstrap bootstrap,
ChannelPoolHandler handler,
ChannelHealthChecker healthCheck)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
Future<Channel> |
acquire()
Acquire a
Channel from this ChannelPool. |
Future<Channel> |
acquire(Promise<Channel> promise)
Acquire a
Channel from this ChannelPool. |
void |
close() |
protected ChannelFuture |
connectChannel(Bootstrap bs)
Bootstrap a new
Channel. |
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<Void> |
release(Channel channel)
Release a
Channel back to this ChannelPool. |
Future<Void> |
release(Channel channel,
Promise<Void> promise)
Release a
Channel back to this ChannelPool. |
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 healty when obtain from the ChannelPoolpublic final Future<Channel> acquire()
ChannelPoolChannel from this ChannelPool. The returned Future is notified once
the acquire is successful and failed otherwise.acquire in interface ChannelPoolpublic Future<Channel> acquire(Promise<Channel> promise)
ChannelPoolChannel from this ChannelPool. The given Promise is notified once
the acquire is successful and failed otherwise.acquire in interface 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<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 in interface ChannelPoolpublic Future<Void> release(Channel channel, Promise<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 in interface 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 in interface ChannelPoolclose in interface Closeableclose in interface AutoCloseableCopyright © 2008–2015 The Netty Project. All rights reserved.