-
- Type Parameters:
K- type parameter for the map's keys.V- type parameter for the map's values.
- All Known Implementing Classes:
SimpleTimeoutMap
public interface TimeoutMap<K,V>A map which additionaly to normal map operations allows the user to supply a timeout. The oldest timed-out entry in the map can be found through the non-blockingpollTimeoutNow()method or two blocking methods:pollTimeoutBlocking()andpollTimeoutBlocking(long, TimeUnit).- Author:
- Philipp Meinen
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclear()removes all key-value pairs from this map.booleancontainsKey(K key)Check for the existence of a key.Vget(K key)Searches a value by its keylonggetTimeToNextTimeout()booleanisEmpty()List<Map.Entry<K,V>>pollAllTimeoutNow()Nonblocking poll for all timed out entries, based on the time of the invocation of this method.Map.Entry<K,V>pollTimeoutBlocking()Blocking poll for the next entry which is timed out.Map.Entry<K,V>pollTimeoutBlocking(long duration, TimeUnit timeUnit)Blocking poll for the next entry which is timed out.Map.Entry<K,V>pollTimeoutNow()Nonblocking poll for the next entry which is timed out, based on the time of the invocation of this method.Vput(long timeout, K key, V value)Add a key-value pair with an associated timeout to the map.Vremove(K key)removes an entry by it's keyintsize()query the number of entries in this map.
-
-
-
Method Detail
-
put
V put(long timeout, K key, V value)
Add a key-value pair with an associated timeout to the map. The resulting timeout-timestamp is the current time plus the supplied timeout.- Parameters:
timeout- the timeout for this key-value pair (in milliseconds)key- -value- -- Returns:
- the value which was previously associated with the given key or
nullif none.
-
get
V get(K key)
Searches a value by its key- Parameters:
key-- Returns:
nullif the key does not exist.
-
remove
V remove(K key)
removes an entry by it's key- Parameters:
key- the key for which an entry must be removed.- Returns:
nullif there was no entry for this key in that map, otherwise the value of the removed entry.
-
pollTimeoutNow
Map.Entry<K,V> pollTimeoutNow()
Nonblocking poll for the next entry which is timed out, based on the time of the invocation of this method.- Returns:
nullif there is no timed-out entry in this map. otherwise the oldest timed-out entry.
-
pollAllTimeoutNow
List<Map.Entry<K,V>> pollAllTimeoutNow()
Nonblocking poll for all timed out entries, based on the time of the invocation of this method.- Returns:
Collections.EMPTY_LISTif there is are no timed out entries in this map.
-
pollTimeoutBlocking
Map.Entry<K,V> pollTimeoutBlocking() throws InterruptedException
Blocking poll for the next entry which is timed out.- Returns:
nullif there is no timed-out entry in this map within the given duration. otherwise the oldest timed-out entry.- Throws:
InterruptedException
-
pollTimeoutBlocking
Map.Entry<K,V> pollTimeoutBlocking(long duration, TimeUnit timeUnit) throws InterruptedException
Blocking poll for the next entry which is timed out. The parameters duration and timeUnit define for how long the method must wait for a timeout to occur.- Returns:
nullif there is no timed-out entry in this map within the given duration. otherwise the oldest timed-out entry.- Throws:
InterruptedException
-
clear
void clear()
removes all key-value pairs from this map.
-
size
int size()
query the number of entries in this map.- Returns:
- the number of entries in this map.
-
isEmpty
boolean isEmpty()
- Returns:
trueif this map is empty,falseotherwise.
-
containsKey
boolean containsKey(K key)
Check for the existence of a key.- Parameters:
key- -- Returns:
trueif there is an entry identified by that key in this map,false otherwise.
-
getTimeToNextTimeout
long getTimeToNextTimeout()
- Returns:
Long.MAX_VALUEif the TimeoutMap is empty. Otherwise the time until the next entry times out (in milliseconds since the epoch). A return value of zero indicates that there is at least one entry which has already timed out.
-
-