Package com.linkedin.alpini.netty4.pool
Class FastFixedChannelPool
- java.lang.Object
-
- com.linkedin.alpini.netty4.pool.FastSimpleChannelPool
-
- com.linkedin.alpini.netty4.pool.FastFixedChannelPool
-
- All Implemented Interfaces:
ChannelPoolWithStats,io.netty.channel.pool.ChannelPool,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
FixedFastChannelPoolImpl
public class FastFixedChannelPool extends FastSimpleChannelPool implements ChannelPoolWithStats
Forked from Netty's FixedChannelPool {ChannelPool} implementation that takes another {ChannelPool} implementation and enforce a maximum number of concurrent connections.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFastFixedChannelPool.PoolChannelGroup
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.group.ChannelGroup_channelGroup-
Fields inherited from class com.linkedin.alpini.netty4.pool.FastSimpleChannelPool
_immediateEventExecutor
-
-
Constructor Summary
Constructors Constructor Description FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections)Creates a new instance using theChannelHealthChecker.ACTIVE.FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)Creates a new instance using theChannelHealthChecker.ACTIVE.FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires)Creates a new instance.FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck)Creates a new instance.FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)Creates a new instance.FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, java.util.function.IntSupplier maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.netty.util.concurrent.Future<io.netty.channel.Channel>acquire(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)intacquiredChannelCount()Returns the number of acquired channels that this pool thinks it has.voidclose()io.netty.util.concurrent.Future<java.lang.Void>closeAsync()Closes the pool in an async manner.protected io.netty.util.concurrent.Future<io.netty.channel.Channel>connectChannel(io.netty.bootstrap.Bootstrap bs, io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)Initiate establishing a new connection with the provided bootstrap.intgetAcquiredChannelCount()intgetMaxConnections()intgetMaxPendingAcquires()intgetPendingAcquireCount()booleanisClosed()booleanisPoolClosed()java.lang.Stringname()protected FastFixedChannelPool.PoolChannelGroupnewPoolChannelGroup()io.netty.util.concurrent.Future<java.lang.Void>release(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<java.lang.Void> promise)voidsetMaxConnections(java.util.function.IntSupplier maxConnections)-
Methods inherited from class com.linkedin.alpini.netty4.pool.FastSimpleChannelPool
acquire, acquireConnectSemaphore, addWaiter, bootstrap, bootstrapChannel, closeChannel, connectInProgress, getAvailableChannels, handler, healthChecker, offerChannel, onConnect, pollChannel, release, releaseConnectSemaphore, releaseHealthCheck
-
-
-
-
Constructor Detail
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections)Creates a new instance using theChannelHealthChecker.ACTIVE.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionsmaxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)Creates a new instance using theChannelHealthChecker.ACTIVE.- Parameters:
bootstrap- theBootstrapthat is used for connectionshandler- theChannelPoolHandlerthat will be notified for the different pool actionsmaxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.maxPendingAcquires- the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires)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 the {ChannelPool}action- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case {@param acquireTimeoutMillis} must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.maxPendingAcquires- the maximum number of pending acquires. Once this is exceed acquire tries will be failed.
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, 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 the {ChannelPool}action- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case acquireTimeoutMillis must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.maxPendingAcquires- the maximum number of pending acquires. Once this is exceed acquire tries will be failed.releaseHealthCheck- will check channel health before offering back if this parameter set totrue.
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, int maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)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 the {ChannelPool}action- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case acquireTimeoutMillis must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.maxPendingAcquires- the maximum number of pending acquires. Once this is exceed acquire tries will be failed.releaseHealthCheck- will check channel health before offering back if this parameter set totrue.connectConcurrency- the number of concurrent bootstrap.connect() calls permitted
-
FastFixedChannelPool
public FastFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, io.netty.channel.pool.FixedChannelPool.AcquireTimeoutAction action, long acquireTimeoutMillis, java.util.function.IntSupplier maxConnections, int maxPendingAcquires, boolean releaseHealthCheck, int connectConcurrency)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 the {ChannelPool}action- theFixedChannelPool.AcquireTimeoutActionto use ornullif non should be used. In this case acquireTimeoutMillis must be-1.acquireTimeoutMillis- the time (in milliseconds) after which an pending acquire must complete or theFixedChannelPool.AcquireTimeoutActiontakes place.maxConnections- the number of maximal active connections, once this is reached new tries to acquire aChannelwill be delayed until a connection is returned to the pool again.maxPendingAcquires- the maximum number of pending acquires. Once this is exceed acquire tries will be failed.releaseHealthCheck- will check channel health before offering back if this parameter set totrue.connectConcurrency- the number of concurrent bootstrap.connect() calls permitted
-
-
Method Detail
-
isPoolClosed
public boolean isPoolClosed()
-
name
public java.lang.String name()
- Specified by:
namein interfaceChannelPoolWithStats
-
setMaxConnections
public void setMaxConnections(java.util.function.IntSupplier maxConnections)
-
newPoolChannelGroup
protected FastFixedChannelPool.PoolChannelGroup newPoolChannelGroup()
-
acquiredChannelCount
public int acquiredChannelCount()
Returns the number of acquired channels that this pool thinks it has.
-
acquire
public io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
- Specified by:
acquirein interfaceio.netty.channel.pool.ChannelPool- Overrides:
acquirein classFastSimpleChannelPool
-
connectChannel
protected io.netty.util.concurrent.Future<io.netty.channel.Channel> connectChannel(io.netty.bootstrap.Bootstrap bs, io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)Initiate establishing a new connection with the provided bootstrap. This implementation attempts to not exceed a preset number of max connections by storing deferred connections that would have caused the number of connections to be exceeded in the _pendingConnect queue. As connections are established, they are added to _channelGroup.- Overrides:
connectChannelin classFastSimpleChannelPool- Parameters:
bs- Channel Bootstrappromise- Promise to complete with result of Bootstrap connect- Returns:
- the promise
-
release
public io.netty.util.concurrent.Future<java.lang.Void> release(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<java.lang.Void> promise)- Specified by:
releasein interfaceio.netty.channel.pool.ChannelPool- Overrides:
releasein classFastSimpleChannelPool
-
getMaxConnections
public int getMaxConnections()
- Specified by:
getMaxConnectionsin interfaceChannelPoolWithStats
-
getMaxPendingAcquires
public int getMaxPendingAcquires()
- Specified by:
getMaxPendingAcquiresin interfaceChannelPoolWithStats
-
getAcquiredChannelCount
public int getAcquiredChannelCount()
- Specified by:
getAcquiredChannelCountin interfaceChannelPoolWithStats
-
getPendingAcquireCount
public int getPendingAcquireCount()
- Specified by:
getPendingAcquireCountin interfaceChannelPoolWithStats
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceChannelPoolWithStats
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceio.netty.channel.pool.ChannelPool- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classFastSimpleChannelPool
-
closeAsync
public io.netty.util.concurrent.Future<java.lang.Void> closeAsync()
Closes the pool in an async manner.- Returns:
- Future which represents completion of the close task
-
-