Class GridFutureAdapter<R>
java.lang.Object
org.apache.ignite.internal.util.future.GridFutureAdapter<R>
- All Implemented Interfaces:
org.apache.ignite.internal.IgniteInternalFuture<R>
- Direct Known Subclasses:
CountDownFuture,GridCompoundFuture
public class GridFutureAdapter<R>
extends Object
implements org.apache.ignite.internal.IgniteInternalFuture<R>
Future adapter.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Default no-op implementation that always returnsfalse.<T> org.apache.ignite.internal.IgniteInternalFuture<T>chain(IgniteClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>, T> doneCb) Make a chained future to convert result of this future (when complete) into a new format.<T> org.apache.ignite.internal.IgniteInternalFuture<T>chain(IgniteClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>, T> doneCb, Executor exec) Make a chained future to convert result of this future (when complete) into a new format.error()get()Synchronously waits for completion of the computation and returns computation result.get(long timeout) Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.Synchronously waits for completion of the computation and returns computation result ignoring interrupts.voidDetermines whether the future will ignore interrupts while waiting for result inget()methods.booleanReturnstrueif this computation was cancelled before it completed normally.booleanisDone()Checks if computation is done.booleanisFailed()voidlisten(IgniteInClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>> lsnr) Registers listener closure to be asynchronously notified whenever future completes.logger()booleanCallback to notify that future is cancelled.final booleanonDone()Callback to notify that future is finished withnullresult.final booleanCallback to notify that future is finished.final booleanCallback to notify that future is finished.booleanCallback to notify that future is finished.protected booleanvoidreset()Resets future for subsequent reuse.result()toString()
-
Constructor Details
-
GridFutureAdapter
public GridFutureAdapter()
-
-
Method Details
-
ignoreInterrupts
public void ignoreInterrupts()Determines whether the future will ignore interrupts while waiting for result inget()methods. This call should happen before subsequentget()in order to have guaranteed effect. -
error
- Specified by:
errorin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
- Error value if future has already been completed with error.
-
result
- Specified by:
resultin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
- Result value if future has already been completed normally.
-
get
Synchronously waits for completion of the computation and returns computation result.- Specified by:
getin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
- Computation result.
- Throws:
org.apache.ignite.internal.IgniteInterruptedCheckedException- Subclass ofIgniteCheckedExceptionthrown if the wait was interrupted.org.apache.ignite.internal.IgniteFutureCancelledCheckedException- Subclass ofIgniteCheckedExceptionthrows if computation was cancelled.IgniteCheckedException- If computation failed.
-
getUninterruptibly
Synchronously waits for completion of the computation and returns computation result ignoring interrupts.- Specified by:
getUninterruptiblyin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
- Computation result.
- Throws:
org.apache.ignite.internal.IgniteFutureCancelledCheckedException- Subclass ofIgniteCheckedExceptionthrows if computation was cancelled.IgniteCheckedException- If computation failed.
-
get
Synchronously waits for completion of the computation for up to the timeout specified and returns computation result. This method is equivalent to callingget(long, TimeUnit.MILLISECONDS).- Specified by:
getin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Parameters:
timeout- The maximum time to wait in milliseconds.- Returns:
- Computation result.
- Throws:
org.apache.ignite.internal.IgniteInterruptedCheckedException- Subclass ofIgniteCheckedExceptionthrown if the wait was interrupted.org.apache.ignite.internal.IgniteFutureTimeoutCheckedException- Subclass ofIgniteCheckedExceptionthrown if the wait was timed out.org.apache.ignite.internal.IgniteFutureCancelledCheckedException- Subclass ofIgniteCheckedExceptionthrows if computation was cancelled.IgniteCheckedException- If computation failed.
-
get
Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.- Specified by:
getin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Parameters:
timeout- The maximum time to wait.unit- The time unit of thetimeoutargument.- Returns:
- Computation result.
- Throws:
org.apache.ignite.internal.IgniteInterruptedCheckedException- Subclass ofIgniteCheckedExceptionthrown if the wait was interrupted.org.apache.ignite.internal.IgniteFutureTimeoutCheckedException- Subclass ofIgniteCheckedExceptionthrown if the wait was timed out.org.apache.ignite.internal.IgniteFutureCancelledCheckedException- Subclass ofIgniteCheckedExceptionthrows if computation was cancelled.IgniteCheckedException- If computation failed.
-
listen
public void listen(IgniteInClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>> lsnr) Registers listener closure to be asynchronously notified whenever future completes.- Specified by:
listenin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Parameters:
lsnr- Listener closure to register. If not provided - this method is no-op.
-
chain
public <T> org.apache.ignite.internal.IgniteInternalFuture<T> chain(IgniteClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>, T> doneCb) Make a chained future to convert result of this future (when complete) into a new format. It is guaranteed that done callback will be called only ONCE.- Specified by:
chainin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Parameters:
doneCb- Done callback that is applied to this future when it finishes to produce chained future result.- Returns:
- Chained future that finishes after this future completes and done callback is called.
-
chain
public <T> org.apache.ignite.internal.IgniteInternalFuture<T> chain(IgniteClosure<? super org.apache.ignite.internal.IgniteInternalFuture<R>, T> doneCb, Executor exec) Make a chained future to convert result of this future (when complete) into a new format. It is guaranteed that done callback will be called only ONCE.- Specified by:
chainin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Parameters:
doneCb- Done callback that is applied to this future when it finishes to produce chained future result.exec- Executor to run callback.- Returns:
- Chained future that finishes after this future completes and done callback is called.
-
logger
- Returns:
- Logger instance.
-
cancel
Default no-op implementation that always returnsfalse. Futures that do support cancellation should override this method and callonCancelled()callback explicitly if cancellation indeed did happen.- Specified by:
cancelin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
Trueif future was canceled (i.e. was not finished prior to this call).- Throws:
IgniteCheckedException- If cancellation failed.
-
isDone
public boolean isDone()Checks if computation is done.- Specified by:
isDonein interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
Trueif computation is done,falseotherwise.
-
isFailed
public boolean isFailed()- Returns:
Trueif future is completed with exception.
-
isCancelled
public boolean isCancelled()Returnstrueif this computation was cancelled before it completed normally.- Specified by:
isCancelledin interfaceorg.apache.ignite.internal.IgniteInternalFuture<R>- Returns:
Trueif this computation was cancelled before it completed normally.
-
onDone
public final boolean onDone()Callback to notify that future is finished withnullresult. This method must delegate toonDone(Object, Throwable)method.- Returns:
Trueif result was set by this call.
-
onDone
Callback to notify that future is finished. This method must delegate toonDone(Object, Throwable)method.- Parameters:
res- Result.- Returns:
Trueif result was set by this call.
-
onDone
Callback to notify that future is finished. This method must delegate toonDone(Object, Throwable)method.- Parameters:
err- Error.- Returns:
Trueif result was set by this call.
-
onDone
Callback to notify that future is finished. Note that if non-nullexception is passed in the result value will be ignored.- Parameters:
res- Optional result.err- Optional error.- Returns:
Trueif result was set by this call.
-
onDone
- Parameters:
res- Result.err- Error.cancel-Trueif future is being cancelled.- Returns:
Trueif result was set by this call.
-
reset
public void reset()Resets future for subsequent reuse. -
onCancelled
public boolean onCancelled()Callback to notify that future is cancelled.- Returns:
Trueif cancel flag was set by this call.
-
toString
-