/** * Completes the future by cancellation. * * @param mayInterruptIfRunning ignored. * @return {@code true} if the future is now cancelled, {@code false} if the future has already been completed. */ @Override public boolean cancel(boolean mayInterruptIfRunning) { boolean result; synchronized (lock) { if (done) { result = false; } else { done = true; this.cancelled = true; lock.notifyAll(); result = true; } } if (result) { notifyListeners(); } return result; }
/** * Completes the future with the supplied value. * * @param value the value (may be {@code null}. * @return {@code true} if the future is now completed, {@code false} if the future has already been completed. */ public boolean set(@Nullable V value) { boolean result; synchronized (lock) { if (done) { result = false; } else { done = true; this.value = value; lock.notifyAll(); result = true; } } if (result) { notifyListeners(); } return result; }
/** * Completes the future with the supplied exception. * * @param throwable the exception. * @return {@code true} if the future is now completed, {@code false} if the future has already been completed. */ public boolean setException(@Nonnull Throwable throwable) { verifyNonnull(throwable); boolean result; synchronized (lock) { if (done) { result = false; } else { done = true; this.throwable = throwable; lock.notifyAll(); result = true; } } if (result) { notifyListeners(); } if (throwable instanceof Error) { throw (Error) throwable; } return result; }