|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.common.util.concurrent.AbstractFuture<V>
public abstract class AbstractFuture<V>
An abstract implementation of the Future
interface. This class
is an abstraction of FutureTask
to support use
for tasks other than Runnable
s. It uses an
AbstractQueuedSynchronizer
to deal with concurrency issues and
guarantee thread safety. It could be used as a base class to
FutureTask
, or any other implementor of the Future
interface.
This class implements all methods in Future
. Subclasses should
provide a way to set the result of the computation through the protected
methods set(Object)
, setException(Throwable)
, or
cancel()
. If subclasses want to implement cancellation they can
override the cancel(boolean)
method with a real implementation, the
default implementation doesn't support cancellation.
The state changing methods all return a boolean indicating success or failure in changing the future's state. Valid states are running, completed, failed, or cancelled. Because this class does not implement cancellation it is left to the subclass to distinguish between created and running tasks.
Constructor Summary | |
---|---|
AbstractFuture()
|
Method Summary | |
---|---|
protected boolean |
cancel()
Subclasses should invoke this method to mark the future as cancelled. |
boolean |
cancel(boolean mayInterruptIfRunning)
|
protected void |
done()
|
V |
get()
|
V |
get(long timeout,
TimeUnit unit)
|
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(Throwable throwable)
Subclasses should invoke this method to set the result of the computation to an error, throwable . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractFuture()
Method Detail |
---|
public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException
get
in interface Future<V>
InterruptedException
TimeoutException
ExecutionException
public V get() throws InterruptedException, ExecutionException
get
in interface Future<V>
InterruptedException
ExecutionException
public boolean isDone()
isDone
in interface Future<V>
public boolean isCancelled()
isCancelled
in interface Future<V>
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface Future<V>
protected boolean set(V value)
value
. This will set the state of the future to
AbstractFuture.Sync.COMPLETED
and call done()
if the
state was successfully changed.
value
- the value that was the result of the task.
protected boolean setException(Throwable throwable)
throwable
. This will set the state of the future to
AbstractFuture.Sync.COMPLETED
and call done()
if the
state was successfully changed.
throwable
- the exception that the task failed with.
Error
- if the throwable was an Error
.protected final boolean cancel()
AbstractFuture.Sync.CANCELLED
and call done()
if the state was
successfully changed.
protected void done()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |