コード例 #1
0
 /**
  * Retrieves the response from the queue matching the given key, blocking until it is received.
  *
  * @param k Response
  * @return Response
  * @throws InterruptedException if interrupted while waiting
  */
 public synchronized V take(K k) throws InterruptedException {
   final V v = taken.remove(k);
   if (v != null) {
     return v;
   }
   // Take the laundry out of the machine. If it's ours, leave with it.
   // If it's someone else's, fold it neatly and put it on the pile.
   for (; ; ) {
     final Pair<K, V> pair = queue.take();
     if (pair.left.equals(k)) {
       return pair.right;
     } else {
       taken.put(pair.left, pair.right);
     }
   }
 }