XNIO version 1.2.0.GA

org.jboss.xnio
Interface IoFuture<T>

Type Parameters:
T - the type of result that this operation produces
All Known Subinterfaces:
FutureConnection<A,T>
All Known Implementing Classes:
AbstractConvertingIoFuture, AbstractFutureConnection, AbstractIoFuture, FailedFutureConnection, FailedIoFuture, FinishedFutureConnection, FinishedIoFuture

public interface IoFuture<T>

The future result of an asynchronous request. Use instances of this interface to retrieve the final status of an asynchronous operation.


Nested Class Summary
static class IoFuture.HandlingNotifier<T,A>
          A base notifier class that calls the designated handler method on notification.
static interface IoFuture.Notifier<T,A>
          A notifier that handles changes in the status of an IoFuture.
static class IoFuture.Status
          The current status of an asynchronous operation.
 
Method Summary
<A> IoFuture<T>
addNotifier(IoFuture.Notifier<T,A> notifier, A attachment)
          Add a notifier to be called when this operation is complete.
 IoFuture.Status await()
          Wait for the operation to complete.
 IoFuture.Status await(long time, TimeUnit timeUnit)
          Wait for the operation to complete, with a timeout.
 IoFuture.Status awaitInterruptibly()
          Wait for the operation to complete.
 IoFuture.Status awaitInterruptibly(long time, TimeUnit timeUnit)
          Wait for the operation to complete, with a timeout.
 IoFuture<T> cancel()
          Cancel an operation.
 T get()
          Get the result of the operation.
 IOException getException()
          Get the failure reason.
 T getInterruptibly()
          Get the result of the operation.
 IoFuture.Status getStatus()
          Get the current status.
 

Method Detail

cancel

IoFuture<T> cancel()
Cancel an operation. The actual cancel may be synchronous or asynchronous.

Returns:
this IoFuture instance

getStatus

IoFuture.Status getStatus()
Get the current status.

Returns:
the current status

await

IoFuture.Status await()
Wait for the operation to complete. This method will block until the status changes from IoFuture.Status.WAITING.

Returns:
the new status

await

IoFuture.Status await(long time,
                      TimeUnit timeUnit)
Wait for the operation to complete, with a timeout. This method will block until the status changes from IoFuture.Status.WAITING, or the given time elapses. If the time elapses before the operation is complete, IoFuture.Status.WAITING is returned.

Parameters:
time - the amount of time to wait
timeUnit - the time unit
Returns:
the new status, or IoFuture.Status.WAITING if the timeout expired

awaitInterruptibly

IoFuture.Status awaitInterruptibly()
                                   throws InterruptedException
Wait for the operation to complete. This method will block until the status changes from IoFuture.Status.WAITING, or the current thread is interrupted.

Returns:
the new status
Throws:
InterruptedException - if the operation is interrupted

awaitInterruptibly

IoFuture.Status awaitInterruptibly(long time,
                                   TimeUnit timeUnit)
                                   throws InterruptedException
Wait for the operation to complete, with a timeout. This method will block until the status changes from IoFuture.Status.WAITING, the given time elapses, or the current thread is interrupted. If the time elapses before the operation is complete, IoFuture.Status.WAITING is returned.

Parameters:
time - the amount of time to wait
timeUnit - the time unit
Returns:
the new status, or IoFuture.Status.WAITING if the timeout expired
Throws:
InterruptedException - if the operation is interrupted

get

T get()
      throws IOException,
             CancellationException
Get the result of the operation. If the operation is not complete, blocks until the operation completes. If the operation fails, or has already failed at the time this method is called, the failure reason is thrown.

Returns:
the result of the operation
Throws:
IOException - if the operation failed
CancellationException - if the operation was cancelled

getInterruptibly

T getInterruptibly()
                   throws IOException,
                          InterruptedException,
                          CancellationException
Get the result of the operation. If the operation is not complete, blocks until the operation completes. If the operation fails, or has already failed at the time this method is called, the failure reason is thrown. If the current thread is interrupted while waiting, an exception is thrown.

Returns:
the result of the operation
Throws:
IOException - if the operation failed
InterruptedException - if the operation is interrupted
CancellationException - if the operation was cancelled

getException

IOException getException()
                         throws IllegalStateException
Get the failure reason.

Returns:
the failure reason
Throws:
IllegalStateException - if the operation did not fail

addNotifier

<A> IoFuture<T> addNotifier(IoFuture.Notifier<T,A> notifier,
                            A attachment)
Add a notifier to be called when this operation is complete. If the operation is already complete, the notifier is called immediately, possibly in the caller's thread. The given attachment is provided to the notifier.

Type Parameters:
A - the attachment type
Parameters:
notifier - the notifier to be called
attachment - the attachment to pass in to the notifier
Returns:
this instance

XNIO version 1.2.0.GA

Copyright © 2008 JBoss, a division of Red Hat, Inc.