Class BaseFuture<V>
- java.lang.Object
-
- org.elasticsearch.common.util.concurrent.BaseFuture<V>
-
- All Implemented Interfaces:
java.util.concurrent.Future<V>
- Direct Known Subclasses:
AdapterActionFuture,ListenableFuture,PlainTransportFuture
public abstract class BaseFuture<V> extends java.lang.Object implements java.util.concurrent.Future<V>
-
-
Constructor Summary
Constructors Constructor Description BaseFuture()
-
Method Summary
Modifier and Type Method Description protected booleanblockingAllowed()booleancancel(boolean mayInterruptIfRunning)protected voiddone()Vget()Vget(long timeout, java.util.concurrent.TimeUnit unit)protected voidinterruptTask()Subclasses can override this method to implement interruption of the future's computation.booleanisCancelled()booleanisDone()protected booleanset(V value)Subclasses should invoke this method to set the result of the computation tovalue.protected booleansetException(java.lang.Throwable throwable)Subclasses should invoke this method to set the result of the computation to an error,throwable.
-
-
-
Method Detail
-
get
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException
The default
BaseFutureimplementation throwsInterruptedExceptionif the current thread is interrupted before or during the call, even if the value is already available.- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedException- if the current thread was interrupted before or during the call (optional but recommended).java.util.concurrent.CancellationExceptionjava.util.concurrent.TimeoutExceptionjava.util.concurrent.ExecutionException
-
get
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
The default
BaseFutureimplementation throwsInterruptedExceptionif the current thread is interrupted before or during the call, even if the value is already available.- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedException- if the current thread was interrupted before or during the call (optional but recommended).java.util.concurrent.CancellationExceptionjava.util.concurrent.ExecutionException
-
blockingAllowed
protected boolean blockingAllowed()
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<V>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<V>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<V>
-
interruptTask
protected void interruptTask()
Subclasses can override this method to implement interruption of the future's computation. The method is invoked automatically by a successful call tocancel(true).The default implementation does nothing.
- Since:
- 10.0
-
set
protected boolean set(@Nullable V value)
Subclasses should invoke this method to set the result of the computation tovalue. This will set the state of the future toBaseFuture.Sync.COMPLETEDand calldone()if the state was successfully changed.- Parameters:
value- the value that was the result of the task.- Returns:
- true if the state was successfully changed.
-
setException
protected boolean setException(java.lang.Throwable throwable)
Subclasses should invoke this method to set the result of the computation to an error,throwable. This will set the state of the future toBaseFuture.Sync.COMPLETEDand calldone()if the state was successfully changed.- Parameters:
throwable- the exception that the task failed with.- Returns:
- true if the state was successfully changed.
- Throws:
java.lang.Error- if the throwable was anError.
-
done
protected void done()
-
-