Package com.linkedin.alpini.netty4.pool
Class EspressoFixedChannelPool
- java.lang.Object
-
- com.linkedin.alpini.netty4.pool.EspressoSimpleChannelPool
-
- com.linkedin.alpini.netty4.pool.EspressoFixedChannelPool
-
- All Implemented Interfaces:
ChannelPoolWithStats
,io.netty.channel.pool.ChannelPool
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
FixedChannelPoolImpl
public class EspressoFixedChannelPool extends EspressoSimpleChannelPool implements ChannelPoolWithStats
Forked from Netty's FixedChannelPool {ChannelPool} implementation that takes another {ChannelPool} implementation and enforce a maximum number of concurrent connections.
-
-
Constructor Summary
Constructors Constructor Description EspressoFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections)
Creates a new instance using theChannelHealthChecker.ACTIVE
.EspressoFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)
Creates a new instance using theChannelHealthChecker.ACTIVE
.EspressoFixedChannelPool(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.EspressoFixedChannelPool(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.EspressoFixedChannelPool(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, boolean lastRecentUsed)
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)
int
acquiredChannelCount()
Returns the number of acquired channels that this pool thinks it has.void
close()
io.netty.util.concurrent.Future<java.lang.Void>
closeAsync()
Closes the pool in an async manner.int
getAcquiredChannelCount()
int
getMaxConnections()
int
getMaxPendingAcquires()
int
getPendingAcquireCount()
void
incrementAcquiredChannelCount()
boolean
isClosed()
boolean
isPoolClosed()
java.lang.String
name()
io.netty.util.concurrent.Future<java.lang.Void>
release(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<java.lang.Void> promise)
-
Methods inherited from class com.linkedin.alpini.netty4.pool.EspressoSimpleChannelPool
acquire, bootstrap, connectChannel, getAvailableChannels, handler, healthChecker, offerChannel, pollChannel, release, releaseHealthCheck
-
-
-
-
Constructor Detail
-
EspressoFixedChannelPool
public EspressoFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections)
Creates a new instance using theChannelHealthChecker.ACTIVE
.- Parameters:
bootstrap
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
will be delayed until a connection is returned to the pool again.
-
EspressoFixedChannelPool
public EspressoFixedChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, int maxConnections, int maxPendingAcquires)
Creates a new instance using theChannelHealthChecker.ACTIVE
.- Parameters:
bootstrap
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionsmaxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
will 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.
-
EspressoFixedChannelPool
public EspressoFixedChannelPool(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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from the {ChannelPool}action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
if 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.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
will 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.
-
EspressoFixedChannelPool
public EspressoFixedChannelPool(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
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from the {ChannelPool}action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
if 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.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
will 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
.
-
EspressoFixedChannelPool
public EspressoFixedChannelPool(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, boolean lastRecentUsed)
Creates a new instance.- Parameters:
bootstrap
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actionshealthCheck
- theChannelHealthChecker
that will be used to check if aChannel
is still healthy when obtain from the {ChannelPool}action
- theFixedChannelPool.AcquireTimeoutAction
to use ornull
if 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.AcquireTimeoutAction
takes place.maxConnections
- the number of maximal active connections, once this is reached new tries to acquire aChannel
will 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
.lastRecentUsed
-true
Channel
selection will be LIFO, iffalse
FIFO.
-
-
Method Detail
-
isPoolClosed
public boolean isPoolClosed()
-
name
public java.lang.String name()
- Specified by:
name
in interfaceChannelPoolWithStats
-
acquiredChannelCount
public int acquiredChannelCount()
Returns the number of acquired channels that this pool thinks it has.
-
incrementAcquiredChannelCount
public void incrementAcquiredChannelCount()
-
acquire
public io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
- Specified by:
acquire
in interfaceio.netty.channel.pool.ChannelPool
- Overrides:
acquire
in classEspressoSimpleChannelPool
-
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:
release
in interfaceio.netty.channel.pool.ChannelPool
- Overrides:
release
in classEspressoSimpleChannelPool
-
getMaxConnections
public int getMaxConnections()
- Specified by:
getMaxConnections
in interfaceChannelPoolWithStats
-
getMaxPendingAcquires
public int getMaxPendingAcquires()
- Specified by:
getMaxPendingAcquires
in interfaceChannelPoolWithStats
-
getAcquiredChannelCount
public int getAcquiredChannelCount()
- Specified by:
getAcquiredChannelCount
in interfaceChannelPoolWithStats
-
getPendingAcquireCount
public int getPendingAcquireCount()
- Specified by:
getPendingAcquireCount
in interfaceChannelPoolWithStats
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceChannelPoolWithStats
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceio.netty.channel.pool.ChannelPool
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classEspressoSimpleChannelPool
-
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
-
-