public class SimpleNettyChannelPool extends Object implements NettyChannelPool
SimpleChannelPool implementationNettyChannelPool.ReleaseStrategyCHANNEL_POOL, DISCONNECT_ON_RELEASE, NONE| Constructor and Description |
|---|
SimpleNettyChannelPool(NettyChannelFactory channelFactory,
io.netty.channel.pool.ChannelPoolHandler handler)
Creates a new instance using the
ChannelHealthChecker.ACTIVE. |
SimpleNettyChannelPool(NettyChannelFactory channelFactory,
io.netty.channel.pool.ChannelPoolHandler handler,
ChannelHealthChecker healthCheck)
Creates a new instance.
|
SimpleNettyChannelPool(NettyChannelFactory channelFactory,
io.netty.channel.pool.ChannelPoolHandler handler,
ChannelHealthChecker healthCheck,
boolean releaseHealthCheck,
boolean lastRecentUsed,
NettyChannelPool.ReleaseStrategy releaseStrategy)
Creates a new instance.
|
SimpleNettyChannelPool(NettyChannelFactory channelFactory,
io.netty.channel.pool.ChannelPoolHandler handler,
ChannelHealthChecker healthCheck,
boolean releaseHealthCheck,
NettyChannelPool.ReleaseStrategy releaseStrategy)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<io.netty.channel.Channel> |
acquire(InetSocketAddress remoteAddress)
Acquire a
Channel from this NettyChannelPool. |
CompletableFuture<io.netty.channel.Channel> |
acquire(InetSocketAddress remoteAddress,
CompletableFuture<io.netty.channel.Channel> promise)
Acquire a
Channel from this NettyChannelPool. |
void |
close() |
CompletableFuture<Void> |
closeAsync()
Closes the pool in an async manner.
|
NettyChannelFactory |
getChannelFactory()
The underlying
NettyChannelFactory used to create new Channel instances. |
protected ChannelHealthChecker |
getChannelHealthChecker()
Returns the
ChannelHealthChecker that will be used to check if a Channel is healthy. |
io.netty.channel.pool.ChannelPoolHandler |
getChannelPoolHandler()
Returns the
ChannelPoolHandler that will be notified for the different pool actions. |
int |
getSize()
getSize.
|
protected CompletableFuture<io.netty.channel.Channel> |
newChannel(InetSocketAddress remoteAddress)
newChannel.
|
protected boolean |
offerChannel(io.netty.channel.Channel channel)
Offer a
Channel back to the internal storage. |
protected io.netty.channel.Channel |
pollChannel()
Poll a
Channel out of the internal storage to reuse it. |
CompletableFuture<Void> |
release(io.netty.channel.Channel channel)
Release a
Channel back to this NettyChannelPool. |
CompletableFuture<Void> |
release(io.netty.channel.Channel channel,
CompletableFuture<Void> promise)
Release a
Channel back to this NettyChannelPool. |
protected boolean |
releaseHealthCheck()
Indicates whether this pool will check the health of channels before offering them back into the pool.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPool, isPooled, tryReleasepublic SimpleNettyChannelPool(NettyChannelFactory channelFactory, io.netty.channel.pool.ChannelPoolHandler handler)
ChannelHealthChecker.ACTIVE.channelFactory - callback which returns a CompletableFuture, when transitions to a complete state, the future returns a new connected Channelhandler - the ChannelPoolHandler that will be notified for the different pool actionspublic SimpleNettyChannelPool(NettyChannelFactory channelFactory, io.netty.channel.pool.ChannelPoolHandler handler, ChannelHealthChecker healthCheck)
channelFactory - callback which returns a CompletableFuture, when transitions to a complete state, the future returns a new connected Channelhandler - 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 NettyChannelPoolpublic SimpleNettyChannelPool(NettyChannelFactory channelFactory, io.netty.channel.pool.ChannelPoolHandler handler, ChannelHealthChecker healthCheck, boolean releaseHealthCheck, NettyChannelPool.ReleaseStrategy releaseStrategy)
channelFactory - callback which returns a CompletableFuture, when transitions to a complete state, the future returns a new connected Channelhandler - 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 NettyChannelPoolreleaseHealthCheck - will check channel health before offering back if this parameter set to true;
otherwise, channel health is only checked at acquisition timereleaseStrategy - Default strategy to apply during releasepublic SimpleNettyChannelPool(NettyChannelFactory channelFactory, io.netty.channel.pool.ChannelPoolHandler handler, ChannelHealthChecker healthCheck, boolean releaseHealthCheck, boolean lastRecentUsed, NettyChannelPool.ReleaseStrategy releaseStrategy)
channelFactory - callback which returns a CompletableFuture, when transitions to a complete state, the future returns a new connected Channelhandler - 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 NettyChannelPoolreleaseHealthCheck - 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.releaseStrategy - Default strategy to apply during releasepublic NettyChannelFactory getChannelFactory()
NettyChannelFactory used to create new Channel instances.AbstractNettyChannelFactorypublic io.netty.channel.pool.ChannelPoolHandler getChannelPoolHandler()
ChannelPoolHandler that will be notified for the different pool actions.ChannelPoolHandler that will be notified for the different pool actionsprotected ChannelHealthChecker getChannelHealthChecker()
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 timeprotected CompletableFuture<io.netty.channel.Channel> newChannel(InetSocketAddress remoteAddress)
newChannel.
remoteAddress - a InetSocketAddress objectCompletableFuture objectpublic final CompletableFuture<Void> release(io.netty.channel.Channel channel)
Channel back to this NettyChannelPool. The returned Future is notified once
the release is successful and failed otherwise. When failed the Channel will automatically closed.release in interface NettyChannelPoolchannel - a Channel objectCompletableFuture objectpublic final CompletableFuture<io.netty.channel.Channel> acquire(InetSocketAddress remoteAddress)
Channel from this NettyChannelPool. The returned CompletableFuture 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 NettyChannelPoolremoteAddress - The remote address to connect toCompletableFuture objectpublic CompletableFuture<io.netty.channel.Channel> acquire(InetSocketAddress remoteAddress, CompletableFuture<io.netty.channel.Channel> promise)
Channel from this NettyChannelPool. The returned CompletableFuture 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 NettyChannelPoolremoteAddress - The remote address to connect topromise - The CompletableFuture that is notified once the acquire operation is complete.CompletableFuture objectpublic CompletableFuture<Void> release(io.netty.channel.Channel channel, CompletableFuture<Void> promise)
Channel back to this NettyChannelPool. The given Promise is notified once
the release is successful and failed otherwise. When failed the Channel will automatically closed.release in interface NettyChannelPoolchannel - a Channel objectpromise - a CompletableFuture objectCompletableFuture objectpublic int getSize()
getSize.
getSize in interface NettyChannelPoolpublic void close()
close in interface NettyChannelPoolclose in interface Closeableclose in interface AutoCloseableprotected boolean offerChannel(io.netty.channel.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(). Be aware that
implementations of these methods needs to be thread-safe!
channel - a Channel objectpublic CompletableFuture<Void> closeAsync()
protected io.netty.channel.Channel pollChannel()
Channel out of the internal storage to reuse it. This will return null if no
Channel is ready to be reused.
Subclasses may override pollChannel() and offerChannel(). Be aware that
implementations of these methods needs to be thread-safe!
Channel objectCopyright © 2016–2024. All rights reserved.