Class ExpiringMap<K,V>
java.lang.Object
org.apache.mina.util.ExpiringMap<K,V>
- Type Parameters:
K- The key typeV- The value type
- All Implemented Interfaces:
Map<K,V>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA Thread that monitors anExpiringMapand will remove elements that have passed the threshold.private class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default value, 1 secondstatic final intThe default value, 60 secondsprivate final ConcurrentHashMap<K, ExpiringMap<K, V>.ExpiringObject> private final CopyOnWriteArrayList<ExpirationListener<V>> private final ExpiringMap<K,V>.Expirer private static int -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new instance of ExpiringMap using the default values DEFAULT_TIME_TO_LIVE and DEFAULT_EXPIRATION_INTERVALExpiringMap(int timeToLive) Creates a new instance of ExpiringMap using the supplied time-to-live value and the default value for DEFAULT_EXPIRATION_INTERVALExpiringMap(int timeToLive, int expirationInterval) Creates a new instance of ExpiringMap using the supplied values and aConcurrentHashMapfor the internal data structure.privateExpiringMap(ConcurrentHashMap<K, ExpiringMap<K, V>.ExpiringObject> delegate, CopyOnWriteArrayList<ExpirationListener<V>> expirationListeners, int timeToLive, int expirationInterval) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpirationListener(ExpirationListener<V> listener) Adds a listener in the expiration listenersvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanintGet the interval in which an object will live in the map before it is removed.intinthashCode()booleanisEmpty()keySet()voidvoidremoveExpirationListener(ExpirationListener<V> listener) Removes a listener from the expiration listenersvoidsetExpirationInterval(int expirationInterval) Set the interval in which an object will live in the map before it is removed.voidsetTimeToLive(int timeToLive) Update the value for the time-to-liveintsize()values()Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
DEFAULT_TIME_TO_LIVE
public static final int DEFAULT_TIME_TO_LIVEThe default value, 60 seconds- See Also:
-
DEFAULT_EXPIRATION_INTERVAL
public static final int DEFAULT_EXPIRATION_INTERVALThe default value, 1 second- See Also:
-
expirerCount
private static volatile int expirerCount -
delegate
-
expirationListeners
-
expirer
-
-
Constructor Details
-
ExpiringMap
public ExpiringMap()Creates a new instance of ExpiringMap using the default values DEFAULT_TIME_TO_LIVE and DEFAULT_EXPIRATION_INTERVAL -
ExpiringMap
public ExpiringMap(int timeToLive) Creates a new instance of ExpiringMap using the supplied time-to-live value and the default value for DEFAULT_EXPIRATION_INTERVAL- Parameters:
timeToLive- The time-to-live value (seconds)
-
ExpiringMap
public ExpiringMap(int timeToLive, int expirationInterval) Creates a new instance of ExpiringMap using the supplied values and aConcurrentHashMapfor the internal data structure.- Parameters:
timeToLive- The time-to-live value (seconds)expirationInterval- The time between checks to see if a value should be removed (seconds)
-
ExpiringMap
private ExpiringMap(ConcurrentHashMap<K, ExpiringMap<K, V>.ExpiringObject> delegate, CopyOnWriteArrayList<ExpirationListener<V>> expirationListeners, int timeToLive, int expirationInterval)
-
-
Method Details
-
put
-
get
-
remove
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
size
-
isEmpty
-
clear
-
hashCode
-
keySet
-
equals
-
putAll
-
values
-
entrySet
-
addExpirationListener
Adds a listener in the expiration listeners- Parameters:
listener- The listener to add
-
removeExpirationListener
Removes a listener from the expiration listeners- Parameters:
listener- The listener to remove
-
getExpirer
- Returns:
- The Expirer instance
-
getExpirationInterval
public int getExpirationInterval()Get the interval in which an object will live in the map before it is removed.- Returns:
- The expiration time in second
-
getTimeToLive
public int getTimeToLive()- Returns:
- the Time-to-live value in seconds.
-
setExpirationInterval
public void setExpirationInterval(int expirationInterval) Set the interval in which an object will live in the map before it is removed.- Parameters:
expirationInterval- The expiration time in seconds
-
setTimeToLive
public void setTimeToLive(int timeToLive) Update the value for the time-to-live- Parameters:
timeToLive- The time-to-live (seconds)
-