Example #1
0
 public synchronized void exception(Exception e) {
   this.exception = e;
   for (AsyncCallback<T> callback : callbacks) {
     callback.exception(exception);
   }
   notifyAll();
 }
Example #2
0
  /** @param callback */
  public synchronized void get(final AsyncCallback<T> callback) {

    if (pigeon != null) {
      callback.result(pigeon);
    } else if (exception != null) {
      callback.exception(exception);
    } else {
      this.callbacks.add(callback);

      // check for timeouts
      final Task timeoutTask =
          ThreadManager.spi
              .create()
              .queue(
                  new Runnable() {
                    public void run() {
                      synchronized (PigeonHole.this) {
                        callbacks.remove(callback);
                        callback.exception(new TimeoutException());
                      }
                    }
                  },
                  System.currentTimeMillis() + timeout);
      if (timeoutTask != null) {
        this.callbacks.add(
            new AsyncCallback<T>() {
              public void result(T result) {
                timeoutTask.cancel();
              }

              public void exception(Exception e) {
                timeoutTask.cancel();
              }
            });
      }
    }
  }