public synchronized void getHyperSpaceMeem(AsyncCallback<Meem> callback) {
   if (hyperSpaceMeem == null) {
     synchronized (hyperSpaceMeemCallbacks) {
       hyperSpaceMeemCallbacks.add(callback);
     }
   } else {
     callback.result(hyperSpaceMeem);
   }
 }
Beispiel #2
0
  /**
   * Place an Object into the PigeonHole. If the PigeonHole is full, then wait until it is emptied.
   *
   * @param pigeon Object to be placed in the PigeonHole
   */
  public synchronized void put(T pigeon) {
    if (received) {
      throw new RuntimeException("Pigeons may only be used once!");
    }

    this.received = true;
    this.pigeon = pigeon;
    for (AsyncCallback<T> callback : callbacks) {
      callback.result(pigeon);
    }
    this.notify();
  }
  /**
   * Asynchronous and preferred way to get Hyperspace.
   *
   * @param callback
   */
  public synchronized void getHyperSpace(final AsyncCallback<HyperSpace> callback) {
    if (hyperSpace == null && hyperSpaceMeem != null) {
      ReferenceHelper.getTarget(
          getHyperSpaceMeem(),
          "hyperSpace",
          HyperSpace.class,
          new AsyncCallback<HyperSpace>() {
            public void result(HyperSpace result) {
              hyperSpace = result;
              callback.result(result);
            };

            public void exception(Exception e) {
              callback.exception(e);
            }
          });
    } else {
      callback.result(hyperSpace);
    }
  }
Beispiel #4
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();
              }
            });
      }
    }
  }