public synchronized void exception(Exception e) { this.exception = e; for (AsyncCallback<T> callback : callbacks) { callback.exception(exception); } notifyAll(); }
/** * 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(); }
public synchronized void getHyperSpaceMeem(AsyncCallback<Meem> callback) { if (hyperSpaceMeem == null) { synchronized (hyperSpaceMeemCallbacks) { hyperSpaceMeemCallbacks.add(callback); } } else { callback.result(hyperSpaceMeem); } }
/** @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(); } }); } } }
/** * 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); } }