org.apache.ignite.internal.util.future

## Class GridFutureAdapter<R>

- java.lang.Object
- - org.apache.ignite.internal.util.future.GridFutureAdapter<R>

All Implemented Interfaces:
  IgniteInternalFuture<R>

Direct Known Subclasses:
  ComputeTaskInternalFuture, CountDownFuture, GridCacheFutureAdapter, GridCacheMultiTxFuture, GridCacheQueryFutureAdapter, GridCompoundFuture, GridDhtAssignmentFetchFuture, GridDhtGetSingleFuture, GridDhtPartitionDemander.RebalanceFuture, GridDhtTopologyFutureAdapter, GridEmbeddedFuture, GridNearOptimisticTxPrepareFutureAdapter.KeyLockFuture, GridNioFutureImpl, GridServiceDeploymentFuture, GridWorkerFuture, SchemaOperationClientFuture

    public class GridFutureAdapter<R>
    extends Object
    implements IgniteInternalFuture<R>

Future adapter.

### Constructor Summary

Constructors
Constructor and Description
`GridFutureAdapter()`

### Method Summary

Methods
`boolean` `cancel()` Default no-op implementation that always returns `false`.
`<T> IgniteInternalFuture<T>` `chain(IgniteClosure<? super IgniteInternalFuture<R>,T> doneCb)` Make a chained future to convert result of this future (when complete) into a new format.
`<T> IgniteInternalFuture<T>` `chain(IgniteClosure<? super IgniteInternalFuture<R>,T> doneCb, Executor exec)` Make a chained future to convert result of this future (when complete) into a new format.
`Throwable` `error()`
`R` `get()` Synchronously waits for completion of the computation and returns computation result.
`R` `get(long timeout)` Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.
`R` `get(long timeout, TimeUnit unit)` Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.
`R` `getUninterruptibly()` Synchronously waits for completion of the computation and returns computation result ignoring interrupts.
`void` `ignoreInterrupts()` Determines whether the future will ignore interrupts.
`boolean` `isCancelled()` Returns `true` if this computation was cancelled before it completed normally.
`boolean` `isDone()` Checks if computation is done.
`boolean` `isFailed()`
`void` `listen(IgniteInClosure<? super IgniteInternalFuture<R>> lsnr)` Registers listener closure to be asynchronously notified whenever future completes.
`IgniteLogger` `logger()`
`boolean` `onCancelled()` Callback to notify that future is cancelled.
`boolean` `onDone()` Callback to notify that future is finished with `null` result.
`boolean` `onDone(R res)` Callback to notify that future is finished.
`boolean` `onDone(R res, Throwable err)` Callback to notify that future is finished.
`protected boolean` `onDone(R res, Throwable err, boolean cancel)`
`boolean` `onDone(Throwable err)` Callback to notify that future is finished.
`R` `result()`
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridFutureAdapter

    public GridFutureAdapter()

### Method Detail

#### ignoreInterrupts

    public void ignoreInterrupts()

Determines whether the future will ignore interrupts.

#### error

    public Throwable error()

Specified by:
  `error` in interface `IgniteInternalFuture<R>`
Returns:
  Error value if future has already been completed with error.

#### result

    public R result()

Specified by:
  `result` in interface `IgniteInternalFuture<R>`
Returns:
  Result value if future has already been completed normally.

#### get

    public R get()
          throws IgniteCheckedException

Synchronously waits for completion of the computation and returns computation result.

Specified by:
  `get` in interface `IgniteInternalFuture<R>`
Returns:
  Computation result.
Throws:
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### getUninterruptibly

    public R getUninterruptibly()
                         throws IgniteCheckedException

Synchronously waits for completion of the computation and returns computation result ignoring interrupts.

Specified by:
  `getUninterruptibly` in interface `IgniteInternalFuture<R>`
Returns:
  Computation result.
Throws:
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### get

    public R get(long timeout)
          throws IgniteCheckedException

Synchronously waits for completion of the computation for up to the timeout specified and returns computation result. This method is equivalent to calling `get(long, TimeUnit.MILLISECONDS)`.

Specified by:
  `get` in interface `IgniteInternalFuture<R>`
Parameters:
  `timeout` - The maximum time to wait in milliseconds.
Returns:
  Computation result.
Throws:
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureTimeoutCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was timed out.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### get

    public R get(long timeout,
        TimeUnit unit)
          throws IgniteCheckedException

Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.

Specified by:
  `get` in interface `IgniteInternalFuture<R>`
Parameters:
  `timeout` - The maximum time to wait.
  `unit` - The time unit of the `timeout` argument.
Returns:
  Computation result.
Throws:
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureTimeoutCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was timed out.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### listen

    public void listen(IgniteInClosure<? super IgniteInternalFuture<R>> lsnr)

Registers listener closure to be asynchronously notified whenever future completes.

Specified by:
  `listen` in interface `IgniteInternalFuture<R>`
Parameters:
  `lsnr` - Listener closure to register. If not provided - this method is no-op.

#### chain

    public <T> IgniteInternalFuture<T> chain(IgniteClosure<? super 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:
  `chain` in interface `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> IgniteInternalFuture<T> chain(IgniteClosure<? super 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:
  `chain` in interface `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

    @Nullable
    public IgniteLogger logger()

Returns:
  Logger instance.

#### cancel

    public boolean cancel()
                   throws IgniteCheckedException

Default no-op implementation that always returns `false`. Futures that do support cancellation should override this method and call `onCancelled()` callback explicitly if cancellation indeed did happen.

Specified by:
  `cancel` in interface `IgniteInternalFuture<R>`
Returns:
  `True` if 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:
  `isDone` in interface `IgniteInternalFuture<R>`
Returns:
  `True` if computation is done, `false` otherwise.

#### isFailed

    public boolean isFailed()

Returns:
  `True` if future is completed with exception.

#### isCancelled

    public boolean isCancelled()

Returns `true` if this computation was cancelled before it completed normally.

Specified by:
  `isCancelled` in interface `IgniteInternalFuture<R>`
Returns:
  `True` if this computation was cancelled before it completed normally.

#### onDone

    public final boolean onDone()

Callback to notify that future is finished with `null` result. This method must delegate to `onDone(Object, Throwable)` method.

Returns:
  `True` if result was set by this call.

#### onDone

    public final boolean onDone(@Nullable
                 R res)

Callback to notify that future is finished. This method must delegate to `onDone(Object, Throwable)` method.

Parameters:
  `res` - Result.
Returns:
  `True` if result was set by this call.

#### onDone

    public final boolean onDone(@Nullable
                 Throwable err)

Callback to notify that future is finished. This method must delegate to `onDone(Object, Throwable)` method.

Parameters:
  `err` - Error.
Returns:
  `True` if result was set by this call.

#### onDone

    public boolean onDone(@Nullable
                 R res,
                 @Nullable
                 Throwable err)

Callback to notify that future is finished. Note that if non-`null` exception is passed in the result value will be ignored.

Parameters:
  `res` - Optional result.
  `err` - Optional error.
Returns:
  `True` if result was set by this call.

#### onDone

    protected boolean onDone(@Nullable
                 R res,
                 @Nullable
                 Throwable err,
                 boolean cancel)

Parameters:
  `res` - Result.
  `err` - Error.
  `cancel` - `True` if future is being cancelled.
Returns:
  `True` if result was set by this call.

#### onCancelled

    public boolean onCancelled()

Callback to notify that future is cancelled.

Returns:
  `True` if cancel flag was set by this call.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017