V
- The result type returned by the future.public class DelegatingListenableFuture<V> extends java.lang.Object implements ListenableFuture<V>
Modifier and Type | Field and Description |
---|---|
protected ListenableFuture<? extends V> |
delegate
Delegate to which all method calls are delegated.
|
Constructor and Description |
---|
DelegatingListenableFuture(ListenableFuture<? extends V> delegate)
Creates a listenable future that delegates all method calls to the
specified listenable future.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addCompletionListener(FutureCompletionListener<? super V> listener)
Registers a completion listener with this future.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
ListenerLockPolicy |
getListenerLockPolicy()
Returns the listener lock-policy used by this future.
|
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
removeCompletionListener(FutureCompletionListener<? super V> listener)
Removes the registration of a completion listener with this future.
|
protected ListenableFuture<? extends V> delegate
public DelegatingListenableFuture(ListenableFuture<? extends V> delegate)
delegate
- listenable future that will receive all method calls that are
made on this listenable future.public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<V>
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<V>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<V>
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<V>
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
get
in interface java.util.concurrent.Future<V>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public boolean addCompletionListener(FutureCompletionListener<? super V> listener)
ListenableFuture
Registers a completion listener with this future. This listener is
notified when the future completes (Future.isDone()
returns
true
). If the future completes before the listener is
registered, the listener is notified immediately while being added.
If the specified listener is already registered with this future, no
action is taken and this method returns false
.
Important note: Typically, the listener is executed by
the thread that sets the future's value. For this reason, it is important
that the listener does not block or perform any long-running operations.
Instead, the listener should delegate any such operation to a different
thread (e.g. using an Executor
). Any violation of this rule might
result in unexpected or unpredictable behavior. In particular, a blocking
listener might cause a dead-lock, which results in the whole application
being stalled indefinitely.
addCompletionListener
in interface ListenableFuture<V>
listener
- listener to be registered with this future.true
if the listener has been added,
false
if it has already been added earlier.public ListenerLockPolicy getListenerLockPolicy()
ListenableFuture
ListenableFuture.removeCompletionListener(FutureCompletionListener)
method when a
listener is removed while a notification of the same listener is in
progress.getListenerLockPolicy
in interface ListenableFuture<V>
public boolean removeCompletionListener(FutureCompletionListener<? super V> listener)
ListenableFuture
Removes the registration of a completion listener with this future. The exact behavior of this method depends on the listener lock-policy used by this future.
If the BLOCK
policy is in effect, the
listener is not going to receive a completion notification after this
method returns. If the IGNORE
policy is
in effect, the listener might still be notified after this method
returns. This may only happen if the future completes before this method
returns. If the REPORT
policy is in
effect, this method throws a ConcurrentNotificationException
if
the listener might still be notified. The listener is still removed,
despite the exception being thrown.
If the specified listener is not currently registered with this future,
no action is taken and this method returns false
.
removeCompletionListener
in interface ListenableFuture<V>
listener
- listener to be unregistered from this future.true
if the listener has been removed,
false
if it has already been removed earlier of if
has never been added.ListenableFuture.getListenerLockPolicy()
Copyright © 2014–2018 aquenos GmbH. All rights reserved.