TKey
- - type of the key.TValue
- - type of the value.public class BlockingHashMap<TKey,TValue>
extends java.lang.Object
Values are stored as weak references, and will be automatically removed once they've all been dereferenced.
Constructor and Description |
---|
BlockingHashMap()
Initialize a new map.
|
Modifier and Type | Method and Description |
---|---|
static <TKey,TValue> |
create()
Initialize a new map.
|
TValue |
get(TKey key)
Waits until a value has been associated with the given key, and then retrieves that value.
|
TValue |
get(TKey key,
long timeout,
java.util.concurrent.TimeUnit unit)
Waits until a value has been associated with the given key, and then retrieves that value.
|
TValue |
get(TKey key,
long timeout,
java.util.concurrent.TimeUnit unit,
boolean ignoreInterrupted)
Waits until a value has been associated with the given key, and then retrieves that value.
|
java.util.Set<TKey> |
keys() |
static <TKey,TValue> |
newInvalidCacheLoader()
Retrieve a cache loader that will always throw an exception.
|
TValue |
put(TKey key,
TValue value)
Associate a given key with the given value.
|
TValue |
putIfAbsent(TKey key,
TValue value)
If and only if a key is not present in the map will it be associated with the given value.
|
int |
size() |
java.util.Collection<TValue> |
values() |
public static <TKey,TValue> com.google.common.cache.CacheLoader<TKey,TValue> newInvalidCacheLoader()
public static <TKey,TValue> BlockingHashMap<TKey,TValue> create()
public TValue get(TKey key) throws java.lang.InterruptedException
key
- - the key whose associated value is to be returnedjava.lang.InterruptedException
- If the current thread got interrupted while waiting.public TValue get(TKey key, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
key
- - the key whose associated value is to be returnedtimeout
- - the amount of time to wait until an association has been made.unit
- - unit of timeout.java.lang.InterruptedException
- If the current thread got interrupted while waiting.public TValue get(TKey key, long timeout, java.util.concurrent.TimeUnit unit, boolean ignoreInterrupted) throws java.lang.InterruptedException
If timeout is zero, this method will return immediately if it can't find an socket injector.
key
- - the key whose associated value is to be returnedtimeout
- - the amount of time to wait until an association has been made.unit
- - unit of timeout.ignoreInterrupted
- - TRUE if we should ignore the thread being interrupted, FALSE otherwise.java.lang.InterruptedException
- If the current thread got interrupted while waiting.public TValue put(TKey key, TValue value)
Wakes up any blocking getters on this specific key.
key
- - the key to associate.value
- - the value.public TValue putIfAbsent(TKey key, TValue value)
key
- - the key to associate.value
- - the value to associate.public int size()
public java.util.Collection<TValue> values()
public java.util.Set<TKey> keys()