/** * Set the future result of the executing task. Any {@link IoFutureListener}s are notified of the * * @param value the value returned by the executing task. */ protected final void setResult(V value) { assert !isDone(); synchronized (latch) { result.set(value); latch.countDown(); } for (IoFutureListener<V> listener : listeners) { scheduleResult(listener, value); } listeners.clear(); }
/** * {@inheritDoc} */ @Override @SuppressWarnings({ "unchecked" }) public IoFuture<V> register(IoFutureListener<V> listener) { LOG.debug("registering listener {}", listener); synchronized (latch) { if (!isDone()) { LOG.debug("future is not done, adding listener to listener set"); listeners.add(listener); listener = null; } } if (listener != null) { LOG.debug("future is done calling listener"); Object object = result.get(); if (object instanceof Throwable) { scheduleException(listener, (Throwable) object); } else { scheduleResult(listener, (V) object); } } return this; }