@ThreadSafe public final class NettyChannelPool extends DynamicResourcePool<io.netty.channel.Channel>
Sharable
. So we need to deep copy handlers when creating new
channels.
3. Netty channel pool interface is async which is not necessary for our usecase.DynamicResourcePool.Options, DynamicResourcePool.ResourceInternal<R>, DynamicResourcePool.SelectionPolicy
mClock, mResources, mSelectionPolicy
Constructor and Description |
---|
NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap,
int maxCapacity,
long gcThresholdMs)
Creates a netty channel pool instance with a minimum capacity of 1.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeResource(io.netty.channel.Channel channel)
Closes the resource.
|
protected io.netty.channel.Channel |
createNewResource()
Creates a netty channel instance.
|
protected com.codahale.metrics.Counter |
getMetricCounter() |
protected boolean |
isHealthy(io.netty.channel.Channel channel)
Checks whether a channel is healthy.
|
protected boolean |
shouldGc(DynamicResourcePool.ResourceInternal<io.netty.channel.Channel> channelResourceInternal) |
acquire, acquire, close, release, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
acquireCloseable, acquireCloseable
public NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap, int maxCapacity, long gcThresholdMs)
bootstrap
- the netty bootstrap used to create netty channelmaxCapacity
- the maximum capacity of the poolgcThresholdMs
- when a channel is older than this threshold and the pool's capacity
is above the minimum capacity(1), it is closed and removed from the pool.protected void closeResource(io.netty.channel.Channel channel)
DynamicResourcePool
closeResource
in class DynamicResourcePool<io.netty.channel.Channel>
channel
- the resource to closeprotected io.netty.channel.Channel createNewResource() throws IOException
createNewResource
in class DynamicResourcePool<io.netty.channel.Channel>
IOException
protected boolean isHealthy(io.netty.channel.Channel channel)
isHealthy
in class DynamicResourcePool<io.netty.channel.Channel>
channel
- the channel to checkprotected com.codahale.metrics.Counter getMetricCounter()
getMetricCounter
in class DynamicResourcePool<io.netty.channel.Channel>
protected boolean shouldGc(DynamicResourcePool.ResourceInternal<io.netty.channel.Channel> channelResourceInternal)
shouldGc
in class DynamicResourcePool<io.netty.channel.Channel>
channelResourceInternal
- the resource to checkCopyright © 2023. All Rights Reserved.