@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>
mClock
Constructor and Description |
---|
NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap,
int minCapacity,
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 void |
closeResourceSync(io.netty.channel.Channel channel)
Similar as above but this guarantees that the resource is closed after the function returns
unless it fails to close.
|
protected io.netty.channel.Channel |
createNewResource()
Creates a netty channel instance.
|
protected boolean |
isHealthy(io.netty.channel.Channel channel)
Checks whether a channel is healthy.
|
protected boolean |
shouldGc(DynamicResourcePool.ResourceInternal<io.netty.channel.Channel> channelResourceInternal) |
public NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap, int minCapacity, int maxCapacity, long gcThresholdMs)
bootstrap
- the netty bootstrap used to create netty channelminCapacity
- the minimum capacity of the poolmaxCapacity
- 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 void closeResourceSync(io.netty.channel.Channel channel)
DynamicResourcePool
closeResourceSync
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 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.