V
- The result type returned by the future.public class SimpleListenableFuture<V> extends AbstractListenableFuture<V>
Simple implementation of a ListenableFuture
.
This implementation provides two methods setResult(Object)
and
setExecutionException(Throwable)
which can be used to set the result
or an exception that occurred while trying to compute the result. Calling
these methods will trigger the listeners registered via
AbstractListenableFuture.addCompletionListener(FutureCompletionListener)
which will be called
before the methods return.
completionListenerLock
Constructor and Description |
---|
SimpleListenableFuture()
Creates a future.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
void |
setExecutionException(java.lang.Throwable executionException)
Sets the exception that occurred while executing the job backing this
future.
|
void |
setResult(V result)
Sets the result provided by this future.
|
addCompletionListener, notifyCompletionListener, notifyCompletionListeners, removeCompletionListener
public SimpleListenableFuture()
setExecutionException(Throwable)
or setResult(Object)
has to be called in order to complete the future. After calling either of
these methods, the future will be done.public void setResult(V result)
Sets the result provided by this future. The result is returned when the
get()
or get(long, TimeUnit)
method is called.
Setting the result completes the future and causes the listeners to be
notified. After calling this method, isDone()
is going to return
true
.
result
- result of the future. The result is returned by the
get(...)
methods. This parameter may be
null
.java.lang.IllegalStateException
- if the future has already completed (by calling either
setExecutionException(Throwable)
) or
setResult(Object)
.get()
,
get(long, TimeUnit)
,
isDone()
,
setExecutionException(Throwable)
public void setExecutionException(java.lang.Throwable executionException)
Sets the exception that occurred while executing the job backing this
future. This exception is wrapped in an ExecutionException
and
thrown when the get()
or get(long, TimeUnit)
method is
called.
Setting the exception completes the future and causes the listeners to be
notified. After calling this method, isDone()
is going to return
true
.
executionException
- the exception that caused the execution to fail. This
exception is wrapped in an ExecutionException
and
thrown by the get(...)
methods. This parameter
must not be null
.java.lang.IllegalStateException
- if the future has already completed (by calling either
setExecutionException(Throwable)
) or
setResult(Object)
.java.lang.NullPointerException
- if executionException
is null
.get()
,
get(long, TimeUnit)
,
isDone()
,
setResult(Object)
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
public boolean isDone()
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
Copyright © 2014–2017 aquenos GmbH. All rights reserved.