Class DefaultChannelPool
- java.lang.Object
-
- org.asynchttpclient.netty.channel.DefaultChannelPool
-
- All Implemented Interfaces:
ChannelPool
public final class DefaultChannelPool extends Object implements ChannelPool
A simple implementation ofChannelPool
based on aConcurrentHashMap
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultChannelPool.PoolLeaseStrategy
-
Constructor Summary
Constructors Constructor Description DefaultChannelPool(Duration maxIdleTime, Duration connectionTtl, io.netty.util.Timer nettyTimer, Duration cleanerPeriod)
DefaultChannelPool(Duration maxIdleTime, Duration connectionTtl, DefaultChannelPool.PoolLeaseStrategy poolLeaseStrategy, io.netty.util.Timer nettyTimer, Duration cleanerPeriod)
DefaultChannelPool(AsyncHttpClientConfig config, io.netty.util.Timer hashedWheelTimer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Destroy all channels that has been cached by this instance.void
flushPartitions(Predicate<Object> predicate)
Flush partitions based on a predicateMap<String,Long>
getIdleChannelCountPerHost()
boolean
isOpen()
Return true if a channel can be cached.boolean
offer(io.netty.channel.Channel channel, Object partitionKey)
Add a channel to the poolio.netty.channel.Channel
poll(Object partitionKey)
Remove the channel associated with the uri.boolean
removeAll(io.netty.channel.Channel channel)
Remove all channels from the cache.
-
-
-
Constructor Detail
-
DefaultChannelPool
public DefaultChannelPool(AsyncHttpClientConfig config, io.netty.util.Timer hashedWheelTimer)
-
DefaultChannelPool
public DefaultChannelPool(Duration maxIdleTime, Duration connectionTtl, io.netty.util.Timer nettyTimer, Duration cleanerPeriod)
-
DefaultChannelPool
public DefaultChannelPool(Duration maxIdleTime, Duration connectionTtl, DefaultChannelPool.PoolLeaseStrategy poolLeaseStrategy, io.netty.util.Timer nettyTimer, Duration cleanerPeriod)
-
-
Method Detail
-
offer
public boolean offer(io.netty.channel.Channel channel, Object partitionKey)
Description copied from interface:ChannelPool
Add a channel to the pool- Specified by:
offer
in interfaceChannelPool
- Parameters:
channel
- an I/O channelpartitionKey
- a key used to retrieve the cached channel- Returns:
- true if added.
-
poll
public io.netty.channel.Channel poll(Object partitionKey)
Description copied from interface:ChannelPool
Remove the channel associated with the uri.- Specified by:
poll
in interfaceChannelPool
- Parameters:
partitionKey
- the partition used when invoking offer- Returns:
- the channel associated with the uri
-
removeAll
public boolean removeAll(io.netty.channel.Channel channel)
Description copied from interface:ChannelPool
Remove all channels from the cache. A channel might have been associated with several uri.- Specified by:
removeAll
in interfaceChannelPool
- Parameters:
channel
- a channel- Returns:
- the true if the channel has been removed
-
isOpen
public boolean isOpen()
Description copied from interface:ChannelPool
Return true if a channel can be cached. A implementation can decide based on some rules to allow caching Calling this method is equivalent of checking the returned value ofChannelPool.offer(Channel, Object)
- Specified by:
isOpen
in interfaceChannelPool
- Returns:
- true if a channel can be cached.
-
destroy
public void destroy()
Description copied from interface:ChannelPool
Destroy all channels that has been cached by this instance.- Specified by:
destroy
in interfaceChannelPool
-
flushPartitions
public void flushPartitions(Predicate<Object> predicate)
Description copied from interface:ChannelPool
Flush partitions based on a predicate- Specified by:
flushPartitions
in interfaceChannelPool
- Parameters:
predicate
- the predicate
-
getIdleChannelCountPerHost
public Map<String,Long> getIdleChannelCountPerHost()
- Specified by:
getIdleChannelCountPerHost
in interfaceChannelPool
- Returns:
- The number of idle channels per host.
-
-