org.apache.ignite.internal.util.nio

## Class GridNioFutureImpl<R>

- java.lang.Object
- - java.util.concurrent.locks.AbstractOwnableSynchronizer
  - - java.util.concurrent.locks.AbstractQueuedSynchronizer
    - - org.apache.ignite.internal.util.nio.GridNioFutureImpl<R>

All Implemented Interfaces:
  Serializable, GridNioFuture<R>

Direct Known Subclasses:
  GridNioEmbeddedFuture

    public class GridNioFutureImpl<R>
    extends AbstractQueuedSynchronizer
    implements GridNioFuture<R>

Default future implementation.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

`AbstractQueuedSynchronizer.ConditionObject`

### Field Summary

Fields
`protected long` `endTime`
`protected boolean` `msgThread`
`protected long` `startTime` Future start time.

### Constructor Summary

Constructors
Constructor and Description
`GridNioFutureImpl()`

### Method Summary

Methods
`boolean` `cancel()` Default no-op implementation that always returns `false`.
`protected Throwable` `error()`
`R` `get()` Synchronously waits for completion of the operation and returns operation result.
`R` `get(long timeout)` Synchronously waits for completion of the operation for up to the timeout specified and returns operation result.
`R` `get(long timeout, TimeUnit unit)` Synchronously waits for completion of the operation for up to the timeout specified and returns operation result.
`protected R` `get0(long nanosTimeout)`
`boolean` `isCancelled()` Returns `true` if this operation was cancelled before it completed normally.
`boolean` `isDone()` Checks if operation is done.
`void` `listenAsync(IgniteInClosure<? super GridNioFuture<R>> lsnr)` Registers listener closure to be asynchronously notified whenever future completes.
`boolean` `messageThread()`
`void` `messageThread(boolean msgThread)` Sets flag indicating that message send future was created in thread that was processing a message.
`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.
`boolean` `onDone(Throwable err)` Callback to notify that future is finished.
`protected R` `result()`
`boolean` `skipRecovery()`
`String` `toString()`
`protected int` `tryAcquireShared(int ignore)`
`protected boolean` `tryReleaseShared(int ignore)`

### Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

`acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isHeldExclusively, isQueued, owns, release, releaseShared, setState, tryAcquire, tryAcquireNanos, tryAcquireSharedNanos, tryRelease`

### Methods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer

`getExclusiveOwnerThread, setExclusiveOwnerThread`

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

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

### Field Detail

#### startTime

    protected final long startTime

Future start time.

#### endTime

    protected volatile long endTime

#### msgThread

    protected boolean msgThread

### Constructor Detail

#### GridNioFutureImpl

    public GridNioFutureImpl()

### Method Detail

#### error

    protected Throwable error()

Returns:
  Value of error.

#### result

    protected R result()

Returns:
  Value of result.

#### get

    public R get()
          throws IOException,
                 IgniteCheckedException

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

Specified by:
  `get` in interface `GridNioFuture<R>`
Returns:
  Operation result.
Throws:
  `IOException` - If IOException occurred while performing operation.
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if operation was cancelled.
  `IgniteCheckedException` - If operation failed.

#### get

    public R get(long timeout)
          throws IOException,
                 IgniteCheckedException

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

Specified by:
  `get` in interface `GridNioFuture<R>`
Parameters:
  `timeout` - The maximum time to wait in milliseconds.
Returns:
  Operation result.
Throws:
  `IOException` - If IOException occurred while performing operation.
  `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 operation was cancelled.
  `IgniteCheckedException` - If operation failed.

#### get

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

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

Specified by:
  `get` in interface `GridNioFuture<R>`
Parameters:
  `timeout` - The maximum time to wait.
  `unit` - The time unit of the `timeout` argument.
Returns:
  Operation result.
Throws:
  `IOException` - If IOException occurred while performing operation.
  `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 operation was cancelled.
  `IgniteCheckedException` - If operation failed.

#### get0

    @Nullable
    protected R get0(long nanosTimeout)
              throws InterruptedException,
                     IgniteCheckedException

Parameters:
  `nanosTimeout` - Timeout (nanoseconds).
Returns:
  Result.
Throws:
  `InterruptedException` - If interrupted.
  `IgniteFutureTimeoutCheckedException` - If timeout reached before computation completed.
  `IgniteCheckedException` - If error occurred.

#### 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 `GridNioFuture<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 operation is done.

Specified by:
  `isDone` in interface `GridNioFuture<R>`
Returns:
  `True` if operation is done, `false` otherwise.

#### isCancelled

    public boolean isCancelled()

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

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

#### listenAsync

    public void listenAsync(@Nullable
                   IgniteInClosure<? super GridNioFuture<R>> lsnr)

Registers listener closure to be asynchronously notified whenever future completes.

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

#### messageThread

    public void messageThread(boolean msgThread)

Sets flag indicating that message send future was created in thread that was processing a message.

Specified by:
  `messageThread` in interface `GridNioFuture<R>`
Parameters:
  `msgThread` - `True` if future was created in thread that is processing message.

#### messageThread

    public boolean messageThread()

Specified by:
  `messageThread` in interface `GridNioFuture<R>`
Returns:
  `True` if future was created in thread that was processing message.

#### 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.

#### onCancelled

    public boolean onCancelled()

Callback to notify that future is cancelled.

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

#### tryAcquireShared

    protected final int tryAcquireShared(int ignore)

Overrides:
  `tryAcquireShared` in class `AbstractQueuedSynchronizer`

#### tryReleaseShared

    protected final boolean tryReleaseShared(int ignore)

Overrides:
  `tryReleaseShared` in class `AbstractQueuedSynchronizer`

#### skipRecovery

    public boolean skipRecovery()

Specified by:
  `skipRecovery` in interface `GridNioFuture<R>`
Returns:
  `True` if skip recovery for this operation.

#### toString

    public String toString()

Overrides:
  `toString` in class `AbstractQueuedSynchronizer`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015