Package com.linkedin.alpini.netty4.pool
Class EspressoSimpleChannelPool
- java.lang.Object
-
- com.linkedin.alpini.netty4.pool.EspressoSimpleChannelPool
-
- All Implemented Interfaces:
io.netty.channel.pool.ChannelPool
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
EspressoFixedChannelPool
public class EspressoSimpleChannelPool extends java.lang.Object implements io.netty.channel.pool.ChannelPool
Forked from Netty's SimpleChannelPool SimpleChannelPool
implementation which will create newChannel
s if someone tries to acquire aChannel
but none is in the pool atm. No limit on the maximal concurrentChannel
s is enforced. This implementation uses LIFO order forChannel
s in theChannelPool
.
-
-
Constructor Summary
Constructors Constructor Description EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler)
Creates a new instance using theChannelHealthChecker.ACTIVE
.EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck)
Creates a new instance.EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, boolean releaseHealthCheck)
Creates a new instance.EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, 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.Future<io.netty.channel.Channel>
acquire(io.netty.util.concurrent.Promise<io.netty.channel.Channel> promise)
protected io.netty.bootstrap.Bootstrap
bootstrap()
Returns theBootstrap
this pool will use to open new connections.void
close()
protected io.netty.channel.ChannelFuture
connectChannel(io.netty.bootstrap.Bootstrap bs)
Bootstrap a newChannel
.protected int
getAvailableChannels()
Returns the channel queue, which holds the available channels with the pool.protected io.netty.channel.pool.ChannelPoolHandler
handler()
Returns theChannelPoolHandler
that will be notified for the different pool actions.protected io.netty.channel.pool.ChannelHealthChecker
healthChecker()
Returns theChannelHealthChecker
that will be used to check if aChannel
is healthy.protected boolean
offerChannel(io.netty.channel.Channel channel)
Offer aChannel
back to the internal storage.protected io.netty.channel.Channel
pollChannel()
Poll aChannel
out of the internal storage to reuse it.io.netty.util.concurrent.Future<java.lang.Void>
release(io.netty.channel.Channel channel)
io.netty.util.concurrent.Future<java.lang.Void>
release(io.netty.channel.Channel channel, io.netty.util.concurrent.Promise<java.lang.Void> promise)
protected boolean
releaseHealthCheck()
Indicates whether this pool will check the health of channels before offering them back into the pool.
-
-
-
Constructor Detail
-
EspressoSimpleChannelPool
public EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler)
Creates a new instance using theChannelHealthChecker.ACTIVE
.- Parameters:
bootstrap
- theBootstrap
that is used for connectionshandler
- theChannelPoolHandler
that will be notified for the different pool actions
-
EspressoSimpleChannelPool
public EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck)
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 theChannelPool
-
EspressoSimpleChannelPool
public EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, 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 theChannelPool
releaseHealthCheck
- will check channel health before offering back if this parameter set totrue
; otherwise, channel health is only checked at acquisition time
-
EspressoSimpleChannelPool
public EspressoSimpleChannelPool(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.pool.ChannelPoolHandler handler, io.netty.channel.pool.ChannelHealthChecker healthCheck, 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 theChannelPool
releaseHealthCheck
- will check channel health before offering back if this parameter set totrue
; otherwise, channel health is only checked at acquisition timelastRecentUsed
-true
Channel
selection will be LIFO, iffalse
FIFO.
-
-
Method Detail
-
getAvailableChannels
protected int getAvailableChannels()
Returns the channel queue, which holds the available channels with the pool.- Returns:
- Deque
-
bootstrap
protected io.netty.bootstrap.Bootstrap bootstrap()
Returns theBootstrap
this pool will use to open new connections.- Returns:
- the
Bootstrap
this pool will use to open new connections
-
handler
protected io.netty.channel.pool.ChannelPoolHandler handler()
Returns theChannelPoolHandler
that will be notified for the different pool actions.- Returns:
- the
ChannelPoolHandler
that will be notified for the different pool actions
-
healthChecker
protected io.netty.channel.pool.ChannelHealthChecker healthChecker()
Returns theChannelHealthChecker
that will be used to check if aChannel
is healthy.- Returns:
- the
ChannelHealthChecker
that will be used to check if aChannel
is healthy
-
releaseHealthCheck
protected boolean releaseHealthCheck()
Indicates whether this pool will check the health of channels before offering them back into the pool.- Returns:
true
if this pool will check the health of channels before offering them back into the pool, orfalse
if channel health is only checked at acquisition time
-
acquire
public final io.netty.util.concurrent.Future<io.netty.channel.Channel> acquire()
- Specified by:
acquire
in interfaceio.netty.channel.pool.ChannelPool
-
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
-
connectChannel
protected io.netty.channel.ChannelFuture connectChannel(io.netty.bootstrap.Bootstrap bs)
Bootstrap a newChannel
. The default implementation usesBootstrap.connect()
, sub-classes may override this.The
Bootstrap
that is passed in here is cloned viaBootstrap.clone()
, so it is safe to modify.
-
release
public final io.netty.util.concurrent.Future<java.lang.Void> release(io.netty.channel.Channel channel)
- Specified by:
release
in interfaceio.netty.channel.pool.ChannelPool
-
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
-
pollChannel
protected io.netty.channel.Channel pollChannel()
Poll aChannel
out of the internal storage to reuse it. This will returnnull
if noChannel
is 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(io.netty.channel.Channel channel)
Offer aChannel
back to the internal storage. This will returntrue
if theChannel
could be added,false
otherwise. Sub-classes may overridepollChannel()
andofferChannel(Channel)
. Be aware that implementations of these methods needs to be thread-safe!
-
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
-
-