Package ca.uhn.hl7v2.concurrent
Class BlockingHashMap<K,V>
java.lang.Object
ca.uhn.hl7v2.concurrent.BlockingHashMap<K,V>
- Type Parameters:
K-V-
- All Implemented Interfaces:
BlockingMap<K,,V> Map<K,V>
Default Implementation of a
BlockingMap.
Note: While it is not actively prevented that more then one thread waits for an entry, it is not guaranteed that all waiting threads will receive the entry once it became available. Other implementations may choose to count the waiting threads and/or to remove an available value after a grace period.
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPolls for an entry in a background thread.Waits for an entry in a background thread.voidclear()Clears all existing entries.booleancontainsKey(Object key) Returnstrueif an entry with the given key is availablebooleancontainsValue(Object value) entrySet()Returns an available entry without removing it from the mapbooleanAdds an entry only if there's already a consumer waiting for the value.booleanisEmpty()Returns true if no entry is available for consumerskeySet()Returns the keys of available entriesWaits for the specified amount of time for an entry with the given key and returns the associated value.voidRemoves an entry, regardless whether a value has been set or not.intsize()Returns the number of available valuesWaits for an entry for the given key and returns the associated value.values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
BlockingHashMap
public BlockingHashMap() -
BlockingHashMap
-
-
Method Details
-
keySet
Returns the keys of available entries -
get
Returns an available entry without removing it from the map -
containsKey
Returnstrueif an entry with the given key is available- Specified by:
containsKeyin interfaceMap<K,V> - See Also:
-
put
-
give
Description copied from interface:BlockingMapAdds an entry only if there's already a consumer waiting for the value.- Specified by:
givein interfaceBlockingMap<K,V> - Parameters:
key- key for the entry to be addedvalue- entry to be added- Returns:
- true if entry was added and a consumer is already waiting for the value, false otherwise
- See Also:
-
take
Description copied from interface:BlockingMapWaits for an entry for the given key and returns the associated value. May return null if the producer withdraws the entry without providing a value.- Specified by:
takein interfaceBlockingMap<K,V> - Parameters:
key- key for the entry- Returns:
- the value of the entry
- Throws:
InterruptedException
-
asyncTake
Description copied from interface:BlockingMapWaits for an entry in a background thread.- Specified by:
asyncTakein interfaceBlockingMap<K,V> - Parameters:
key- key for the entry- Returns:
- Future the result
-
poll
Description copied from interface:BlockingMapWaits for the specified amount of time for an entry with the given key and returns the associated value. Returns null if no value was provided within the poll time. May return null if the producer withdraws the entry without providing a value.- Specified by:
pollin interfaceBlockingMap<K,V> - Parameters:
key- key for the entrytimeout- timeout before the methods returnsunit- time unit used in conjunction with timout- Returns:
- the value of the entry
- Throws:
InterruptedException
-
asyncPoll
Description copied from interface:BlockingMapPolls for an entry in a background thread.- Specified by:
asyncPollin interfaceBlockingMap<K,V> - Parameters:
key- key for the entry- Returns:
- Future the result
-
isEmpty
Returns true if no entry is available for consumers -
size
Returns the number of available values -
remove
Removes an entry, regardless whether a value has been set or not. Waiting consumers will receive a null value. -
clear
Clears all existing entries. Waiting consumers will receive a null value for each removed entry. -
values
-
entrySet
-
putAll
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-