Example #1
0
 /**
  * Queues error that will be thrown in any waiting thread or any thread that attempts to wait on
  * this future hereafter.
  *
  * @param e the error
  */
 public void error(Throwable e) {
   lock();
   try {
     pendingEx = chainer.chain(e);
     cond.signalAll();
   } finally {
     unlock();
   }
 }
Example #2
0
 /**
  * Wait for {@code timeout} duration for this future's value to be set.
  *
  * @param timeout the timeout
  * @param unit time unit for the timeout
  * @return the value
  * @throws T in case another thread informs the future of an error meanwhile, or the timeout
  *     expires
  */
 public V get(long timeout, TimeUnit unit) throws T {
   lock();
   try {
     if (pendingEx != null) throw pendingEx;
     if (val != null) return val;
     log.debug("Awaiting <<{}>>", name);
     while (val == null && pendingEx == null)
       if (timeout == 0) cond.await();
       else if (!cond.await(timeout, unit))
         throw chainer.chain(new TimeoutException("Timeout expired"));
     if (pendingEx != null) {
       log.error("<<{}>> woke to: {}", name, pendingEx.toString());
       throw pendingEx;
     }
     return val;
   } catch (InterruptedException ie) {
     throw chainer.chain(ie);
   } finally {
     unlock();
   }
 }