Package io.netty.channel.pool
Class AbstractChannelPoolMap<K,P extends ChannelPool>
- java.lang.Object
-
- io.netty.channel.pool.AbstractChannelPoolMap<K,P>
-
- All Implemented Interfaces:
ChannelPoolMap<K,P>,java.io.Closeable,java.lang.AutoCloseable,java.lang.Iterable<java.util.Map.Entry<K,P>>
public abstract class AbstractChannelPoolMap<K,P extends ChannelPool> extends java.lang.Object implements ChannelPoolMap<K,P>, java.lang.Iterable<java.util.Map.Entry<K,P>>, java.io.Closeable
A skeletalChannelPoolMapimplementation. To find the rightChannelPooltheObject.hashCode()andObject.equals(Object)is used.
-
-
Constructor Summary
Constructors Constructor Description AbstractChannelPoolMap()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()booleancontains(K key)Pget(K key)Return theChannelPoolfor thecode.booleanisEmpty()java.util.Iterator<java.util.Map.Entry<K,P>>iterator()protected abstract PnewPool(K key)Called once a newChannelPoolneeds to be created as non exists yet for thekey.private static Future<java.lang.Void>poolCloseAsyncIfSupported(ChannelPool pool)If the pool implementation supports asynchronous close, then use it to avoid a blocking close call in case the ChannelPoolMap operations are called from an EventLoop.booleanremove(K key)Remove theChannelPoolfrom thisAbstractChannelPoolMap.private Future<java.lang.Boolean>removeAsyncIfSupported(K key)Remove theChannelPoolfrom thisAbstractChannelPoolMap.intsize()Returns the number ofChannelPools currently in thisAbstractChannelPoolMap.
-
-
-
Field Detail
-
map
private final java.util.concurrent.ConcurrentMap<K,P extends ChannelPool> map
-
-
Method Detail
-
get
public final P get(K key)
Description copied from interface:ChannelPoolMapReturn theChannelPoolfor thecode. This will never returnnull, but create a newChannelPoolif non exists for they requestedkey. Please note thatnullkeys are not allowed.- Specified by:
getin interfaceChannelPoolMap<K,P extends ChannelPool>
-
remove
public final boolean remove(K key)
Remove theChannelPoolfrom thisAbstractChannelPoolMap. Returnstrueif removed,falseotherwise. If the removed pool extendsSimpleChannelPoolit will be closed asynchronously to avoid blocking in this method. Please note thatnullkeys are not allowed.
-
removeAsyncIfSupported
private Future<java.lang.Boolean> removeAsyncIfSupported(K key)
Remove theChannelPoolfrom thisAbstractChannelPoolMap. Returns a future that comletes with atrueresult if the pool has been removed by this call, otherwise the result isfalse. If the removed pool extendsSimpleChannelPoolit will be closed asynchronously to avoid blocking in this method. The returned future will be completed once this asynchronous pool close operation completes.
-
poolCloseAsyncIfSupported
private static Future<java.lang.Void> poolCloseAsyncIfSupported(ChannelPool pool)
If the pool implementation supports asynchronous close, then use it to avoid a blocking close call in case the ChannelPoolMap operations are called from an EventLoop.- Parameters:
pool- the ChannelPool to be closed
-
iterator
public final java.util.Iterator<java.util.Map.Entry<K,P>> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<K>
-
size
public final int size()
Returns the number ofChannelPools currently in thisAbstractChannelPoolMap.
-
isEmpty
public final boolean isEmpty()
-
contains
public final boolean contains(K key)
Description copied from interface:ChannelPoolMap- Specified by:
containsin interfaceChannelPoolMap<K,P extends ChannelPool>
-
newPool
protected abstract P newPool(K key)
Called once a newChannelPoolneeds to be created as non exists yet for thekey.
-
close
public final void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-