Package io.netty.channel.pool
Class SimpleChannelPool
- java.lang.Object
-
- io.netty.channel.pool.SimpleChannelPool
-
- All Implemented Interfaces:
ChannelPool,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
FixedChannelPool
public class SimpleChannelPool extends java.lang.Object implements ChannelPool
SimpleChannelPoolimplementation which will create newChannels if someone tries to acquire aChannelbut none is in the pool atm. No limit on the maximal concurrentChannels is enforced. This implementation uses LIFO order forChannels in theChannelPool.
-
-
Constructor Summary
Constructors Constructor Description SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler)Creates a new instance using theChannelHealthChecker.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<Channel>acquire()Acquire aChannelfrom thisChannelPool.Future<Channel>acquire(Promise<Channel> promise)Acquire aChannelfrom thisChannelPool.protected Bootstrapbootstrap()Returns theBootstrapthis pool will use to open new connections.voidclose()Future<java.lang.Void>closeAsync()Closes the pool in an async manner.protected ChannelFutureconnectChannel(Bootstrap bs)Bootstrap a newChannel.protected ChannelPoolHandlerhandler()Returns theChannelPoolHandlerthat will be notified for the different pool actions.protected ChannelHealthCheckerhealthChecker()Returns theChannelHealthCheckerthat will be used to check if aChannelis healthy.protected booleanofferChannel(Channel channel)Offer aChannelback to the internal storage.protected ChannelpollChannel()Poll aChannelout of the internal storage to reuse it.Future<java.lang.Void>release(Channel channel)Release aChannelback to thisChannelPool.Future<java.lang.Void>release(Channel channel, Promise<java.lang.Void> promise)Release aChannelback to thisChannelPool.protected booleanreleaseHealthCheck()Indicates whether this pool will check the health of channels before offering them back into the pool.
-
-
-
Constructor Detail
-
SimpleChannelPool
public SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler)
Creates a new instance using theChannelHealthChecker.ACTIVE.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actions
-
SimpleChannelPool
public SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck)
Creates a new instance.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPool
-
SimpleChannelPool
public SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, boolean releaseHealthCheck)
Creates a new instance.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPoolreleaseHealthCheck- will check channel health before offering back if this parameter set totrue; otherwise, channel health is only checked at acquisition time
-
SimpleChannelPool
public SimpleChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, ChannelHealthChecker healthCheck, boolean releaseHealthCheck, boolean lastRecentUsed)
Creates a new instance.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionshealthCheck- theChannelHealthCheckerthat will be used to check if aChannelis still healthy when obtain from theChannelPoolreleaseHealthCheck- will check channel health before offering back if this parameter set totrue; otherwise, channel health is only checked at acquisition timelastRecentUsed-trueChannelselection will be LIFO, iffalseFIFO.
-
-
Method Detail
-
bootstrap
protected Bootstrap bootstrap()
Returns theBootstrapthis pool will use to open new connections.- Returns:
- the
Bootstrapthis pool will use to open new connections
-
handler
protected ChannelPoolHandler handler()
Returns theChannelPoolHandlerthat will be notified for the different pool actions.- Returns:
- the
ChannelPoolHandlerthat will be notified for the different pool actions
-
healthChecker
protected ChannelHealthChecker healthChecker()
Returns theChannelHealthCheckerthat will be used to check if aChannelis healthy.- Returns:
- the
ChannelHealthCheckerthat will be used to check if aChannelis healthy
-
releaseHealthCheck
protected boolean releaseHealthCheck()
Indicates whether this pool will check the health of channels before offering them back into the pool.- Returns:
trueif this pool will check the health of channels before offering them back into the pool, orfalseif channel health is only checked at acquisition time
-
acquire
public final Future<Channel> acquire()
Description copied from interface:ChannelPoolAcquire aChannelfrom thisChannelPool. The returnedFutureis notified once the acquire is successful and failed otherwise. Its important that an acquired is always released to the pool again, even if theChannelis explicitly closed..- Specified by:
acquirein interfaceChannelPool
-
acquire
public Future<Channel> acquire(Promise<Channel> promise)
Description copied from interface:ChannelPoolAcquire aChannelfrom thisChannelPool. The givenPromiseis notified once the acquire is successful and failed otherwise. Its important that an acquired is always released to the pool again, even if theChannelis explicitly closed..- Specified by:
acquirein interfaceChannelPool
-
connectChannel
protected ChannelFuture connectChannel(Bootstrap bs)
Bootstrap a newChannel. The default implementation usesBootstrap.connect(), sub-classes may override this.The
Bootstrapthat is passed in here is cloned viaBootstrap.clone(), so it is safe to modify.
-
release
public final Future<java.lang.Void> release(Channel channel)
Description copied from interface:ChannelPoolRelease aChannelback to thisChannelPool. The returnedFutureis notified once the release is successful and failed otherwise. When failed theChannelwill automatically closed.- Specified by:
releasein interfaceChannelPool
-
release
public Future<java.lang.Void> release(Channel channel, Promise<java.lang.Void> promise)
Description copied from interface:ChannelPoolRelease aChannelback to thisChannelPool. The givenPromiseis notified once the release is successful and failed otherwise. When failed theChannelwill automatically closed.- Specified by:
releasein interfaceChannelPool
-
pollChannel
protected Channel pollChannel()
Poll aChannelout of the internal storage to reuse it. This will returnnullif noChannelis ready to be reused. Sub-classes may overridepollChannel()andofferChannel(Channel). Be aware that implementations of these methods needs to be thread-safe!
-
offerChannel
protected boolean offerChannel(Channel channel)
Offer aChannelback to the internal storage. This will returntrueif theChannelcould be added,falseotherwise. Sub-classes may overridepollChannel()andofferChannel(Channel). Be aware that implementations of these methods needs to be thread-safe!
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceChannelPool- Specified by:
closein interfacejava.io.Closeable
-
closeAsync
public Future<java.lang.Void> closeAsync()
Closes the pool in an async manner.- Returns:
- Future which represents completion of the close task
-
-