private void runAsynchronous(ExecutionCallbackNode head, Object result) { while (head != INITIAL_STATE) { runAsynchronous(head.callback, head.executor, result); head = head.next; } }
private void runAsynchronous(ExecutionCallbackNode head, Object result) { while (head != INITIAL_STATE) { runAsynchronous(head.callback, head.executor, result); head = head.next; } }
/** * Sets the result. If {@code result} is an instance of Throwable, this * future will be completed exceptionally. That is, {@link #get} will throw * the exception rather than return it. * * @return true, if this call made this future to complete */ protected boolean setResult(Object result) { for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (STATE.compareAndSet(this, currentState, result)) { done(); notifyThreadsWaitingOnGet(); runAsynchronous((ExecutionCallbackNode) currentState, result); break; } } return true; }
/** * Sets the result. If {@code result} is an instance of Throwable, this * future will be completed exceptionally. That is, {@link #get} will throw * the exception rather than return it. * * @return true, if this call made this future to complete */ protected boolean setResult(Object result) { for (; ; ) { Object currentState = this.state; if (isDoneState(currentState)) { return false; } if (STATE.compareAndSet(this, currentState, result)) { done(); notifyThreadsWaitingOnGet(); runAsynchronous((ExecutionCallbackNode) currentState, result); break; } } return true; }
@Override public void andThen(ExecutionCallback<V> callback, Executor executor) { isNotNull(callback, "callback"); isNotNull(executor, "executor"); for (; ; ) { Object currentState = this.state; if (isCancelledState(currentState)) { return; } if (isDoneState(currentState)) { runAsynchronous(callback, executor, currentState); return; } ExecutionCallbackNode newState = new ExecutionCallbackNode<V>(callback, executor, (ExecutionCallbackNode) currentState); if (STATE.compareAndSet(this, currentState, newState)) { // we have successfully scheduled the callback. return; } // we failed to update the state. This can mean 2 things: // either a result was set, which we'll see when retrying this loop // or a different thread also called andThen, which we'll deal with when we retry the loop. } }
@Override public void andThen(ExecutionCallback<V> callback, Executor executor) { isNotNull(callback, "callback"); isNotNull(executor, "executor"); for (; ; ) { Object currentState = this.state; if (isCancelledState(currentState)) { return; } if (isDoneState(currentState)) { runAsynchronous(callback, executor, currentState); return; } ExecutionCallbackNode newState = new ExecutionCallbackNode<V>(callback, executor, (ExecutionCallbackNode) currentState); if (STATE.compareAndSet(this, currentState, newState)) { // we have successfully scheduled the callback. return; } // we failed to update the state. This can mean 2 things: // either a result was set, which we'll see when retrying this loop // or a different thread also called andThen, which we'll deal with when we retry the loop. } }