diff options
Diffstat (limited to 'guava/src/com/google/common/util/concurrent/AbstractFuture.java')
-rw-r--r-- | guava/src/com/google/common/util/concurrent/AbstractFuture.java | 65 |
1 files changed, 14 insertions, 51 deletions
diff --git a/guava/src/com/google/common/util/concurrent/AbstractFuture.java b/guava/src/com/google/common/util/concurrent/AbstractFuture.java index e14a111..bef3d3d 100644 --- a/guava/src/com/google/common/util/concurrent/AbstractFuture.java +++ b/guava/src/com/google/common/util/concurrent/AbstractFuture.java @@ -70,11 +70,6 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { // The execution list to hold our executors. private final ExecutionList executionList = new ExecutionList(); - /** - * Constructor for use by subclasses. - */ - protected AbstractFuture() {} - /* * Improve the documentation of when InterruptedException is thrown. Our * behavior matches the JDK's, but the JDK's documentation is misleading. @@ -128,7 +123,7 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { @Override public boolean cancel(boolean mayInterruptIfRunning) { - if (!sync.cancel(mayInterruptIfRunning)) { + if (!sync.cancel()) { return false; } executionList.execute(); @@ -151,16 +146,6 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { } /** - * Returns true if this future was cancelled with {@code - * mayInterruptIfRunning} set to {@code true}. - * - * @since 14.0 - */ - protected final boolean wasInterrupted() { - return sync.wasInterrupted(); - } - - /** * {@inheritDoc} * * @since 10.0 @@ -216,14 +201,13 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { * private subclass to hold the synchronizer. This synchronizer is used to * implement the blocking and waiting calls as well as to handle state changes * in a thread-safe manner. The current state of the future is held in the - * Sync state, and the lock is released whenever the state changes to - * {@link #COMPLETED}, {@link #CANCELLED}, or {@link #INTERRUPTED} + * Sync state, and the lock is released whenever the state changes to either + * {@link #COMPLETED} or {@link #CANCELLED}. * * <p>To avoid races between threads doing release and acquire, we transition * to the final state in two steps. One thread will successfully CAS from * RUNNING to COMPLETING, that thread will then set the result of the - * computation, and only then transition to COMPLETED, CANCELLED, or - * INTERRUPTED. + * computation, and only then transition to COMPLETED or CANCELLED. * * <p>We don't use the integer argument passed between acquire methods so we * pass around a -1 everywhere. @@ -237,7 +221,6 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { static final int COMPLETING = 1; static final int COMPLETED = 2; static final int CANCELLED = 4; - static final int INTERRUPTED = 8; private V value; private Throwable exception; @@ -309,9 +292,7 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { } case CANCELLED: - case INTERRUPTED: - throw cancellationExceptionWithCause( - "Task was cancelled.", exception); + throw new CancellationException("Task was cancelled."); default: throw new IllegalStateException( @@ -320,25 +301,17 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { } /** - * Checks if the state is {@link #COMPLETED}, {@link #CANCELLED}, or {@link - * INTERRUPTED}. + * Checks if the state is {@link #COMPLETED} or {@link #CANCELLED}. */ boolean isDone() { - return (getState() & (COMPLETED | CANCELLED | INTERRUPTED)) != 0; + return (getState() & (COMPLETED | CANCELLED)) != 0; } /** - * Checks if the state is {@link #CANCELLED} or {@link #INTERRUPTED}. + * Checks if the state is {@link #CANCELLED}. */ boolean isCancelled() { - return (getState() & (CANCELLED | INTERRUPTED)) != 0; - } - - /** - * Checks if the state is {@link #INTERRUPTED}. - */ - boolean wasInterrupted() { - return getState() == INTERRUPTED; + return getState() == CANCELLED; } /** @@ -356,10 +329,10 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { } /** - * Transition to the CANCELLED or INTERRUPTED state. + * Transition to the CANCELLED state. */ - boolean cancel(boolean interrupt) { - return complete(null, null, interrupt ? INTERRUPTED : CANCELLED); + boolean cancel() { + return complete(null, null, CANCELLED); } /** @@ -367,8 +340,7 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { * be set but not both. The {@code finalState} is the state to change to * from {@link #RUNNING}. If the state is not in the RUNNING state we * return {@code false} after waiting for the state to be set to a valid - * final state ({@link #COMPLETED}, {@link #CANCELLED}, or {@link - * #INTERRUPTED}). + * final state ({@link #COMPLETED} or {@link #CANCELLED}). * * @param v the value to set as the result of the computation. * @param t the exception to set as the result of the computation. @@ -381,9 +353,7 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { // If this thread successfully transitioned to COMPLETING, set the value // and exception and then release to the final state. this.value = v; - // Don't actually construct a CancellationException until necessary. - this.exception = ((finalState & (CANCELLED | INTERRUPTED)) != 0) - ? new CancellationException("Future.cancel() was called.") : t; + this.exception = t; releaseShared(finalState); } else if (getState() == COMPLETING) { // If some other thread is currently completing the future, block until @@ -393,11 +363,4 @@ public abstract class AbstractFuture<V> implements ListenableFuture<V> { return doCompletion; } } - - static final CancellationException cancellationExceptionWithCause( - @Nullable String message, @Nullable Throwable cause) { - CancellationException exception = new CancellationException(message); - exception.initCause(cause); - return exception; - } } |