ch.bind.philib.util
K - type parameter for the map's keys.V - type parameter for the map's values.public final class SimpleTimeoutMap<K,V> extends Object implements TimeoutMap<K,V>
TimeoutMap which uses the TreeMap and HashMap from
java.util for
internal data management. This implementation is threadsafe.TimeoutMap| Constructor and Description |
|---|
SimpleTimeoutMap() |
| Modifier and Type | Method and Description |
|---|---|
long |
_getTimeToNextTimeoutNs(long nowNs) |
void |
clear()
removes all key-value pairs from this map.
|
boolean |
containsKey(K key)
Check for the existence of a key.
|
V |
get(K key)
Searches a value by its key
|
long |
getTimeToNextTimeout() |
boolean |
isEmpty() |
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.
|
V |
put(long timeout,
K key,
V value)
Add a key-value pair with an associated timeout to the map.
|
V |
remove(K key)
removes an entry by it's key
|
int |
size()
query the number of entries in this map.
|
public V put(long timeout, K key, V value)
TimeoutMapput in interface TimeoutMap<K,V>timeout - the timeout for this key-value pair (in milliseconds)key - -value - -null if none.public V get(K key)
TimeoutMapget in interface TimeoutMap<K,V>null if the key does not exist.public V remove(K key)
TimeoutMapremove in interface TimeoutMap<K,V>key - the key for which an entry must be removed.null if there was no entry for this key in that map, otherwise the value of the removed entry.public Map.Entry<K,V> pollTimeoutNow()
TimeoutMappollTimeoutNow in interface TimeoutMap<K,V>null if there is no timed-out entry in this map. otherwise the oldest timed-out entry.public List<Map.Entry<K,V>> pollAllTimeoutNow()
TimeoutMappollAllTimeoutNow in interface TimeoutMap<K,V>Collections.EMPTY_LIST if there is are no timed out entries in this map.public Map.Entry<K,V> pollTimeoutBlocking() throws InterruptedException
TimeoutMappollTimeoutBlocking in interface TimeoutMap<K,V>null if there is no timed-out entry in this map within the given duration. otherwise the oldest
timed-out entry.InterruptedExceptionpublic Map.Entry<K,V> pollTimeoutBlocking(long duration, TimeUnit timeUnit) throws InterruptedException
TimeoutMappollTimeoutBlocking in interface TimeoutMap<K,V>null if there is no timed-out entry in this map within the given duration. otherwise the oldest
timed-out entry.InterruptedExceptionpublic void clear()
TimeoutMapclear in interface TimeoutMap<K,V>public int size()
TimeoutMapsize in interface TimeoutMap<K,V>public boolean isEmpty()
isEmpty in interface TimeoutMap<K,V>true if this map is empty, false otherwise.public boolean containsKey(K key)
TimeoutMapcontainsKey in interface TimeoutMap<K,V>key - -true if there is an entry identified by that key in this map, false otherwise.public long getTimeToNextTimeout()
getTimeToNextTimeout in interface TimeoutMap<K,V>Long.MAX_VALUE if 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.public long _getTimeToNextTimeoutNs(long nowNs)
Copyright © 2014. All Rights Reserved.