XNIO version 1.0.0.GA

org.jboss.xnio
Class AbstractIoFuture<T>

java.lang.Object
  extended by org.jboss.xnio.AbstractIoFuture<T>
Type Parameters:
T - the type of result that this operation produces
All Implemented Interfaces:
IoFuture<T>
Direct Known Subclasses:
FailedIoFuture, FinishedIoFuture

public abstract class AbstractIoFuture<T>
extends Object
implements IoFuture<T>

An abstract base class for IoFuture objects. Used to easily produce implementations.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.xnio.IoFuture
IoFuture.Notifier<T>, IoFuture.Status
 
Constructor Summary
protected AbstractIoFuture()
          Construct a new instance.
 
Method Summary
 void addNotifier(IoFuture.Notifier<T> notifier)
          Add a notifier to be called when this operation is complete.
 IoFuture.Status await()
          Wait for the operation to complete.
 IoFuture.Status await(TimeUnit timeUnit, long time)
          Wait for the operation to complete, with a timeout.
 IoFuture.Status awaitInterruptibly()
          Wait for the operation to complete.
 IoFuture.Status awaitInterruptibly(TimeUnit timeUnit, long time)
          Wait for the operation to complete, with a timeout.
abstract  IoFuture<T> cancel()
          Cancel an operation.
protected  boolean finishCancel()
          Acknowledge the cancellation of this 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.
protected abstract  void runNotifier(IoFuture.Notifier<T> notifier)
          Run a notifier.
protected  boolean setException(IOException exception)
          Set the exception for this operation.
protected  boolean setResult(T result)
          Set the result for this operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIoFuture

protected AbstractIoFuture()
Construct a new instance.

Method Detail

getStatus

public IoFuture.Status getStatus()
Get the current status.

Specified by:
getStatus in interface IoFuture<T>
Returns:
the current status

await

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

Specified by:
await in interface IoFuture<T>
Returns:
the new status

await

public IoFuture.Status await(TimeUnit timeUnit,
                             long time)
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.TIMED_OUT is returned.

Specified by:
await in interface IoFuture<T>
Parameters:
timeUnit - the time unit
time - the amount of time to wait
Returns:
the new status, or IoFuture.Status.TIMED_OUT if the timeout expired

awaitInterruptibly

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

Specified by:
awaitInterruptibly in interface IoFuture<T>
Returns:
the new status
Throws:
InterruptedException - if the operation is interrupted

awaitInterruptibly

public IoFuture.Status awaitInterruptibly(TimeUnit timeUnit,
                                          long time)
                                   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.TIMED_OUT is returned.

Specified by:
awaitInterruptibly in interface IoFuture<T>
Parameters:
timeUnit - the time unit
time - the amount of time to wait
Returns:
the new status, or IoFuture.Status.TIMED_OUT if the timeout expired
Throws:
InterruptedException - if the operation is interrupted

get

public T get()
      throws IOException
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.

Specified by:
get in interface IoFuture<T>
Returns:
the result of the operation
Throws:
IOException - if the operation failed

getInterruptibly

public T getInterruptibly()
                   throws IOException,
                          InterruptedException
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.

Specified by:
getInterruptibly in interface IoFuture<T>
Returns:
the result of the operation
Throws:
IOException - if the operation failed
InterruptedException - if the operation is interrupted

getException

public IOException getException()
                         throws IllegalStateException
Get the failure reason.

Specified by:
getException in interface IoFuture<T>
Returns:
the failure reason
Throws:
IllegalStateException - if the operation did not fail

addNotifier

public void addNotifier(IoFuture.Notifier<T> notifier)
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.

Specified by:
addNotifier in interface IoFuture<T>
Parameters:
notifier - the notifier to be called

setException

protected boolean setException(IOException exception)
Set the exception for this operation. Any threads blocking on this instance will be unblocked.

Parameters:
exception - the exception to set
Returns:
false if the operation was already completed, true otherwise

setResult

protected boolean setResult(T result)
Set the result for this operation. Any threads blocking on this instance will be unblocked.

Parameters:
result - the result to set
Returns:
false if the operation was already completed, true otherwise

finishCancel

protected boolean finishCancel()
Acknowledge the cancellation of this operation.

Returns:
false if the operation was already completed, true otherwise

cancel

public abstract IoFuture<T> cancel()
Cancel an operation. The actual cancel may be synchronous or asynchronous. Implementors will use this method to initiate the cancel; use the finishCancel() method to indicate that the cancel was successful. If cancellation is not supported, this method may be a no-op.

Specified by:
cancel in interface IoFuture<T>
Returns:
this IoFuture instance

runNotifier

protected abstract void runNotifier(IoFuture.Notifier<T> notifier)
Run a notifier. Implementors will run the notifier, preferably in another thread.

Parameters:
notifier - the notifier to run

XNIO version 1.0.0.GA

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