public class SimpleChannelPool extends java.lang.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 LIFO 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.
|
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.
|
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 . |
protected Bootstrap |
bootstrap()
Returns the
Bootstrap this pool will use to open new connections. |
void |
close() |
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 ChannelPool
public 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 ChannelPool
releaseHealthCheck
- 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 ChannelPool
releaseHealthCheck
- 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()
ChannelPool
Channel
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
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.
Its important that an acquired is always released to the pool again, even if the Channel
is explicitly closed..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<java.lang.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<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
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 java.io.Closeable
close
in interface java.lang.AutoCloseable
Copyright © 2008–2018 The Netty Project. All rights reserved.