Package alluxio.network.netty
Class NettyChannelPool
- java.lang.Object
-
- alluxio.resource.DynamicResourcePool<io.netty.channel.Channel>
-
- alluxio.network.netty.NettyChannelPool
-
- All Implemented Interfaces:
Pool<io.netty.channel.Channel>
,java.io.Closeable
,java.lang.AutoCloseable
@ThreadSafe public final class NettyChannelPool extends DynamicResourcePool<io.netty.channel.Channel>
A pool to manage netty channels. Netty has it own implementation of channel pool but that doesn't fit our needs for several reasons: 1. We need a dynamic pool which can garbage collect idle channels. 2. We need to have control on how channel is created. For example, our channel handler might not be annotated withSharable
. 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class alluxio.resource.DynamicResourcePool
DynamicResourcePool.Options, DynamicResourcePool.ResourceInternal<R>, DynamicResourcePool.SelectionPolicy
-
-
Field Summary
-
Fields inherited from class alluxio.resource.DynamicResourcePool
mClock, mResources, mSelectionPolicy
-
-
Constructor Summary
Constructors Constructor Description NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap, int maxCapacity, long gcThresholdMs)
Creates a netty channel pool instance with a minimum capacity of 1.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
Methods inherited from class alluxio.resource.DynamicResourcePool
acquire, acquire, close, release, size
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface alluxio.resource.Pool
acquireCloseable, acquireCloseable
-
-
-
-
Constructor Detail
-
NettyChannelPool
public NettyChannelPool(io.netty.bootstrap.Bootstrap bootstrap, int maxCapacity, long gcThresholdMs)
Creates a netty channel pool instance with a minimum capacity of 1.- Parameters:
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.
-
-
Method Detail
-
closeResource
protected void closeResource(io.netty.channel.Channel channel)
Description copied from class:DynamicResourcePool
Closes the resource. After this, the resource should not be used. It is not guaranteed that the resource is closed after the function returns.- Specified by:
closeResource
in classDynamicResourcePool<io.netty.channel.Channel>
- Parameters:
channel
- the resource to close
-
createNewResource
protected io.netty.channel.Channel createNewResource() throws java.io.IOException
Creates a netty channel instance.- Specified by:
createNewResource
in classDynamicResourcePool<io.netty.channel.Channel>
- Returns:
- the channel created
- Throws:
java.io.IOException
-
isHealthy
protected boolean isHealthy(io.netty.channel.Channel channel)
Checks whether a channel is healthy.- Specified by:
isHealthy
in classDynamicResourcePool<io.netty.channel.Channel>
- Parameters:
channel
- the channel to check- Returns:
- true if the channel is active (i.e. connected)
-
getMetricCounter
protected com.codahale.metrics.Counter getMetricCounter()
- Specified by:
getMetricCounter
in classDynamicResourcePool<io.netty.channel.Channel>
-
shouldGc
protected boolean shouldGc(DynamicResourcePool.ResourceInternal<io.netty.channel.Channel> channelResourceInternal)
- Specified by:
shouldGc
in classDynamicResourcePool<io.netty.channel.Channel>
- Parameters:
channelResourceInternal
- the resource to check- Returns:
- true if the resource should be garbage collected
-
-