@Override public final boolean isDone() { return isDone(state); }
@Override public final boolean isDone() { return isDone(state); }
@Override public String toString() { Object state = getState(); if (isDone(state)) { return "InvocationFuture{invocation=" + invocationToString() + ", value=" + state + '}'; } else { return "InvocationFuture{invocation=" + invocationToString() + ", done=false}"; } }
@Override public String toString() { Object state = getState(); if (isDone(state)) { return "InvocationFuture{invocation=" + invocationToString() + ", value=" + state + '}'; } else { return "InvocationFuture{invocation=" + invocationToString() + ", done=false}"; } }
for (; ; ) { final Object oldState = state; if (isDone(oldState)) { return oldState;
@Override public final V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Object response = registerWaiter(Thread.currentThread(), null); if (response != VOID) { return resolveAndThrowIfException(response); } long deadlineNanos = System.nanoTime() + unit.toNanos(timeout); boolean interrupted = false; try { long timeoutNanos = unit.toNanos(timeout); while (timeoutNanos > 0) { parkNanos(timeoutNanos); timeoutNanos = deadlineNanos - System.nanoTime(); if (isDone()) { return resolveAndThrowIfException(state); } else if (Thread.interrupted()) { interrupted = true; onInterruptDetected(); } } } finally { restoreInterrupt(interrupted); } unregisterWaiter(Thread.currentThread()); throw newTimeoutException(timeout, unit); }
@Override public V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Object response = registerWaiter(Thread.currentThread(), null); if (response != VOID) { return resolveAndThrowIfException(response); } long deadlineNanos = System.nanoTime() + unit.toNanos(timeout); boolean interrupted = false; try { long timeoutNanos = unit.toNanos(timeout); while (timeoutNanos > 0) { parkNanos(timeoutNanos); timeoutNanos = deadlineNanos - System.nanoTime(); if (isDone()) { return resolveAndThrowIfException(state); } else if (Thread.interrupted()) { interrupted = true; onInterruptDetected(); } } } finally { restoreInterrupt(interrupted); } unregisterWaiter(Thread.currentThread()); throw newTimeoutException(timeout, unit); }
for (; ; ) { final Object oldState = state; if (isDone(oldState)) { return oldState;
@Override public V get() throws InterruptedException, ExecutionException { Object response = registerWaiter(Thread.currentThread(), null); if (response != VOID) { // no registration was done since a value is available. return resolveAndThrowIfException(response); } boolean interrupted = false; try { for (; ; ) { park(); if (isDone()) { return resolveAndThrowIfException(state); } else if (Thread.interrupted()) { interrupted = true; onInterruptDetected(); } } } finally { restoreInterrupt(interrupted); } }
@Override public final V get() throws InterruptedException, ExecutionException { Object response = registerWaiter(Thread.currentThread(), null); if (response != VOID) { // no registration was done since a value is available. return resolveAndThrowIfException(response); } boolean interrupted = false; try { for (; ; ) { park(); if (isDone()) { return resolveAndThrowIfException(state); } else if (Thread.interrupted()) { interrupted = true; onInterruptDetected(); } } } finally { restoreInterrupt(interrupted); } }
/** * Can be called multiple times, but only the first answer will lead to the * future getting triggered. All subsequent complete calls are ignored. * * @param value The type of response to offer. * @return <tt>true</tt> if offered response, either a final response or an * internal response, is set/applied, <tt>false</tt> otherwise. If <tt>false</tt> * is returned, that means offered response is ignored because a final response * is already set to this future. */ @Override public final boolean complete(Object value) { for (; ; ) { final Object oldState = state; if (isDone(oldState)) { warnIfSuspiciousDoubleCompletion(oldState, value); return false; } if (compareAndSetState(oldState, value)) { onComplete(); unblockAll(oldState, defaultExecutor); return true; } } }
/** * Can be called multiple times, but only the first answer will lead to the * future getting triggered. All subsequent complete calls are ignored. * * @param value The type of response to offer. * @return <tt>true</tt> if offered response, either a final response or an * internal response, is set/applied, <tt>false</tt> otherwise. If <tt>false</tt> * is returned, that means offered response is ignored because a final response * is already set to this future. */ @Override public final boolean complete(Object value) { for (; ; ) { final Object oldState = state; if (isDone(oldState)) { warnIfSuspiciousDoubleCompletion(oldState, value); return false; } if (compareAndSetState(oldState, value)) { onComplete(); unblockAll(oldState, defaultExecutor); return true; } } }