View Javadoc
1   package ca.uhn.hl7v2.concurrent;
2   
3   import java.util.Map;
4   import java.util.concurrent.Future;
5   import java.util.concurrent.TimeUnit;
6   
7   public interface BlockingMap<K, V> extends Map<K, V> {
8   
9   	/**
10  	 * Adds an entry only if there's already a consumer waiting for the value.
11  	 * 
12  	 * @param key key for the entry to be added
13  	 * @param value entry to be added
14  	 * @return true if entry was added and a consumer is already waiting for the
15  	 *         value, false otherwise
16  	 */
17  	boolean give(K key, V value);
18  
19  	/**
20  	 * Waits for an entry for the given key and returns the associated value.
21  	 * May return null if the producer withdraws the entry without providing a
22  	 * value.
23  	 * 
24  	 * @param key key for the entry
25  	 * @return the value of the entry
26  	 * @throws InterruptedException
27  	 */
28  	V take(K key) throws InterruptedException;
29  	
30  	/**
31  	 * Waits for an entry in a background thread.
32  	 * 
33  	 * @param key key for the entry
34  	 * @return Future the result
35       */
36  	Future<V> asyncTake(K key);
37  
38  	/**
39  	 * Waits for the specified amount of time for an entry with the given key
40  	 * and returns the associated value. Returns null if no value was provided
41  	 * within the poll time. May return null if the producer withdraws the entry
42  	 * without providing a value.
43  	 * 
44  	 * @param key key for the entry
45  	 * @param timeout timeout before the methods returns
46  	 * @param unit time unit used in conjunction with timout
47  	 * @return the value of the entry
48  	 * @throws InterruptedException
49  	 */
50  	V poll(K key, long timeout, TimeUnit unit) throws InterruptedException;
51  
52  	/**
53  	 * Polls for an entry in a background thread.
54  	 * 
55  	 * @param key key for the entry
56  	 * @return Future the result
57       */
58  	Future<V> asyncPoll(K key, long timeout, TimeUnit unit);
59  }
60