public abstract class BaseFuture<V>
extends java.lang.Object
implements java.util.concurrent.Future<V>
Constructor and Description |
---|
BaseFuture() |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
protected void |
done() |
V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
protected void |
interruptTask()
Subclasses can override this method to implement interruption of the
future's computation.
|
boolean |
isCancelled() |
boolean |
isDone() |
protected boolean |
set(V value)
Subclasses should invoke this method to set the result of the computation
to
value . |
protected boolean |
setException(java.lang.Throwable throwable)
Subclasses should invoke this method to set the result of the computation
to an error,
throwable . |
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException
The default BaseFuture
implementation throws InterruptedException
if the current thread is interrupted before or during
the call, even if the value is already available.
get
in interface java.util.concurrent.Future<V>
java.lang.InterruptedException
- if the current thread was interrupted before
or during the call (optional but recommended).java.util.concurrent.CancellationException
java.util.concurrent.TimeoutException
java.util.concurrent.ExecutionException
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
The default BaseFuture
implementation throws InterruptedException
if the current thread is interrupted before or during
the call, even if the value is already available.
get
in interface java.util.concurrent.Future<V>
java.lang.InterruptedException
- if the current thread was interrupted before
or during the call (optional but recommended).java.util.concurrent.CancellationException
java.util.concurrent.ExecutionException
public boolean isDone()
isDone
in interface java.util.concurrent.Future<V>
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<V>
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<V>
protected void interruptTask()
cancel(true)
.
The default implementation does nothing.
protected boolean set(@Nullable V value)
value
. This will set the state of the future to
BaseFuture.Sync.COMPLETED
and call done()
if the
state was successfully changed.value
- the value that was the result of the task.protected boolean setException(java.lang.Throwable throwable)
throwable
. This will set the state of the future to
BaseFuture.Sync.COMPLETED
and call done()
if the
state was successfully changed.throwable
- the exception that the task failed with.java.lang.Error
- if the throwable was an Error
.protected void done()