/** * Tries to complete this callback; driver code should call this method once * <em>after</em> the asynchronous operation to detect whether the * asynchronous operation has already completed or not. * * @return whether the attempt to complete was successful. */ public boolean tryComplete() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.COMPLETED)) return true; break; } case SUCCEEDED: case FAILED: { return false; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void succeeded() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.SUCCEEDED)) return; break; } case COMPLETED: { if (state.compareAndSet(current, State.SUCCEEDED)) { resume(); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void succeeded() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.SUCCEEDED)) return; break; } case COMPLETED: { if (state.compareAndSet(current, State.SUCCEEDED)) { resume(); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void succeeded() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.SUCCEEDED)) return; break; } case COMPLETED: { if (state.compareAndSet(current, State.SUCCEEDED)) { resume(); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }
/** * Tries to complete this callback; driver code should call this method once * <em>after</em> the asynchronous operation to detect whether the * asynchronous operation has already completed or not. * * @return whether the attempt to complete was successful. */ public boolean tryComplete() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.COMPLETED)) return true; break; } case SUCCEEDED: case FAILED: { return false; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void failed(Throwable x) { while (true) { State current = state.get(); switch (current) { case IDLE: case COMPLETED: { if (state.compareAndSet(current, State.FAILED)) { abort(x); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }
/** * Tries to complete this callback; driver code should call this method once * <em>after</em> the asynchronous operation to detect whether the * asynchronous operation has already completed or not. * * @return whether the attempt to complete was successful. */ public boolean tryComplete() { while (true) { State current = state.get(); switch (current) { case IDLE: { if (state.compareAndSet(current, State.COMPLETED)) return true; break; } case SUCCEEDED: case FAILED: { return false; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void failed(Throwable x) { while (true) { State current = state.get(); switch (current) { case IDLE: case COMPLETED: { if (state.compareAndSet(current, State.FAILED)) { abort(x); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }
@Override public void failed(Throwable x) { while (true) { State current = state.get(); switch (current) { case IDLE: case COMPLETED: { if (state.compareAndSet(current, State.FAILED)) { abort(x); return; } break; } case FAILED: { return; } default: { throw new IllegalStateException(current.toString()); } } } }