Class BlockingHashMap<TKey,TValue>
java.lang.Object
com.comphenix.protocol.concurrency.BlockingHashMap<TKey,TValue>
- Type Parameters:
TKey- - type of the key.TValue- - type of the value.
A map that supports blocking on read operations. Null keys are not supported.
Values are stored as weak references, and will be automatically removed once they've all been dereferenced.
- Author:
- Kristian
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <TKey, TValue>
BlockingHashMap<TKey,TValue>create()Initialize a new map.Waits until a value has been associated with the given key, and then retrieves that value.Waits until a value has been associated with the given key, and then retrieves that value.Waits until a value has been associated with the given key, and then retrieves that value.keys()static <TKey, TValue>
com.google.common.cache.CacheLoader<TKey,TValue>Retrieve a cache loader that will always throw an exception.Associate a given key with the given value.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.intsize()values()
-
Constructor Details
-
BlockingHashMap
public BlockingHashMap()Initialize a new map.
-
-
Method Details
-
newInvalidCacheLoader
public static <TKey, TValue> com.google.common.cache.CacheLoader<TKey,TValue> newInvalidCacheLoader()Retrieve a cache loader that will always throw an exception.- Type Parameters:
TKey- Type of the keyTValue- Type of the value- Returns:
- An invalid cache loader.
-
create
Initialize a new map.- Type Parameters:
TKey- Type of the keyTValue- Type of the value- Returns:
- The created map.
-
get
Waits until a value has been associated with the given key, and then retrieves that value.- Parameters:
key- - the key whose associated value is to be returned- Returns:
- The value to which the specified key is mapped.
- Throws:
InterruptedException- If the current thread got interrupted while waiting.
-
get
Waits until a value has been associated with the given key, and then retrieves that value.- Parameters:
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.- Returns:
- The value to which the specified key is mapped, or NULL if the timeout elapsed.
- Throws:
InterruptedException- If the current thread got interrupted while waiting.
-
get
public TValue get(TKey key, long timeout, TimeUnit unit, boolean ignoreInterrupted) throws InterruptedExceptionWaits until a value has been associated with the given key, and then retrieves that value.If timeout is zero, this method will return immediately if it can't find an socket injector.
- Parameters:
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.- Returns:
- The value to which the specified key is mapped, or NULL if the timeout elapsed.
- Throws:
InterruptedException- If the current thread got interrupted while waiting.
-
put
Associate a given key with the given value.Wakes up any blocking getters on this specific key.
- Parameters:
key- - the key to associate.value- - the value.- Returns:
- The previously associated value.
-
putIfAbsent
If and only if a key is not present in the map will it be associated with the given value.- Parameters:
key- - the key to associate.value- - the value to associate.- Returns:
- The previous value this key has been associated with.
-
size
public int size() -
values
-
keys
-