K
- the type of keys maintained by this mapV
- the type of mapped valuespublic interface ConcurrentMapWithTimedEviction<K,V> extends ConcurrentMap<K,V>
ConcurrentMap
that supports timed entry
eviction. It provides overloaded put, putIfAbsent, and
replace methods with one additional parameter, evictMs,
which is the time in ms during which the entry can stay in the map
(time-to-live).Modifier and Type | Method and Description |
---|---|
V |
put(K key,
V value,
long evictMs)
Associates the specified value with the specified key in this map for the
specified duration (optional operation).
|
V |
putIfAbsent(K key,
V value,
long evictMs)
If the specified key is not already associated with a value, associate it
with the given value for the specified duration.
|
V |
replace(K key,
V value,
long evictMs)
Replaces the entry for a key only if currently mapped to some value, for
the specified duration.
|
boolean |
replace(K key,
V oldValue,
V newValue,
long evictMs)
Replaces the entry for a key only if currently mapped to a given value,
for the specified duration.
|
putIfAbsent, remove, replace, replace
V put(K key, V value, long evictMs)
m.containsKey(k)
would return
true.)key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyevictMs
- the time in ms during which the entry can stay in the map
(time-to-live). When this time has elapsed, the entry will be
evicted from the map automatically. A value of 0 for this
argument means "forever", i.e. put(key, value, 0) is
equivalent to put(key, value).UnsupportedOperationException
- if the put operation is not supported by this mapClassCastException
- if the class of the specified key or value prevents it from
being stored in this mapNullPointerException
- if the specified key or value is null and this map does not
permit null keys or valuesIllegalArgumentException
- if some property of the specified key or value prevents it
from being stored in this map, or if evictMs is negativeV putIfAbsent(K key, V value, long evictMs)
if (!map.containsKey(key)) return map.put(key, value, evictMs); else return map.get(key);except that the action is performed atomically.
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyevictMs
- the time in ms during which the entry can stay in the map
(time-to-live). When this time has elapsed, the entry will be
evicted from the map automatically. A value of 0 for this
argument means "forever", i.e.
putIfAbsent(key, value, 0) is equivalent to
putIfAbsent(key, value).UnsupportedOperationException
- if the put operation is not supported by this mapClassCastException
- if the class of the specified key or value prevents it from
being stored in this mapNullPointerException
- if the specified key or value is null, and this map does not
permit null keys or valuesIllegalArgumentException
- if some property of the specified key or value prevents it
from being stored in this map, or if evictMs is negativeV replace(K key, V value, long evictMs)
if (map.containsKey(key)) { return map.put(key, value, evictMs); } else return null;except that the action is performed atomically.
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keyevictMs
- the time in ms during which the entry can stay in the map
(time-to-live). When this time has elapsed, the entry will be
evicted from the map automatically. A value of 0 for this
argument means "forever", i.e. replace(key, value, 0)
is equivalent to replace(key, value).UnsupportedOperationException
- if the put operation is not supported by this mapClassCastException
- if the class of the specified key or value prevents it from
being stored in this mapNullPointerException
- if the specified key or value is null, and this map does not
permit null keys or valuesIllegalArgumentException
- if some property of the specified key or value prevents it
from being stored in this map, or if evictMs is negativeboolean replace(K key, V oldValue, V newValue, long evictMs)
if (map.containsKey(key) && map.get(key).equals(oldValue)) { map.put(key, newValue, evictMs); return true; } else return false;except that the action is performed atomically.
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keyevictMs
- the time in ms during which the entry can stay in the map
(time-to-live). When this time has elapsed, the entry will be
evicted from the map automatically. A value of 0 for this
argument means "forever", i.e.
replace(key, oldValue, newValue, 0) is equivalent to
put(key, oldValue, newValue).UnsupportedOperationException
- if the put operation is not supported by this mapClassCastException
- if the class of a specified key or value prevents it from
being stored in this mapNullPointerException
- if a specified key or value is null, and this map does not
permit null keys or valuesIllegalArgumentException
- if some property of a specified key or value prevents it from
being stored in this map, or if evictMs is negativeCopyright © 2012–2016. All rights reserved.