public class SimpleChannelPool extends Object implements ChannelPool
ChannelPool
implementation which will create new Channel
s if someone tries to acquire
a Channel
but none is in the pool atm. No limit on the maximal concurrent Channel
s is enforced.
This implementation uses FIFO order for Channel
s 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 ChannelPool
public final Future<Channel> acquire()
ChannelPool
Channel
from this ChannelPool
. The returned Future
is notified once
the acquire is successful and failed otherwise.acquire
in interface ChannelPool
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.acquire
in interface ChannelPool
protected 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)
ChannelPool
Channel
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 ChannelPool
public Future<Void> release(Channel channel, Promise<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
protected 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 ChannelPool
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2008–2015 The Netty Project. All rights reserved.