com.sun.sgs.impl.nio
Class IoFutureTask<R,A>

java.lang.Object
  extended by java.util.concurrent.FutureTask<R>
      extended by com.sun.sgs.impl.nio.IoFutureTask<R,A>
Type Parameters:
R - the result type
A - the attachment type
All Implemented Interfaces:
IoFuture<R,A>, Runnable, Future<R>, RunnableFuture<R>
Direct Known Subclasses:
DelegatingCompletionHandler

public class IoFutureTask<R,A>
extends FutureTask<R>
implements IoFuture<R,A>

An implementation of IoFuture that adds an object attachment to a FutureTask.


Constructor Summary
IoFutureTask(Callable<R> callable, A attachment)
          Creates an instance of this class for running the specified Callable and including the specified attachment.
 
Method Summary
 A attach(A newAttachment)
          Attaches the given object to this channel future.
 A attachment()
          Retrieves the current attachment.
 R getNow()
          Retrieves the result of a completed operation.
static
<R,A> IoFuture
newInstance(Callable<R> callable, A attachment)
          Creates an instance of this class for running the specified Callable and including the specified attachment.
 
Methods inherited from class java.util.concurrent.FutureTask
cancel, done, get, get, isCancelled, isDone, run, runAndReset, set, setException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.sgs.nio.channels.IoFuture
cancel
 
Methods inherited from interface java.util.concurrent.Future
get, get, isCancelled, isDone
 

Constructor Detail

IoFutureTask

public IoFutureTask(Callable<R> callable,
                    A attachment)
Creates an instance of this class for running the specified Callable and including the specified attachment.

Parameters:
callable - the callable task
attachment - the attachment; may be null
Method Detail

newInstance

public static <R,A> IoFuture newInstance(Callable<R> callable,
                                         A attachment)
Creates an instance of this class for running the specified Callable and including the specified attachment.

Type Parameters:
R - the result type
A - the attachment type
Parameters:
callable - the callable task
attachment - the attachment; may be null
Returns:
a new IoFuture

getNow

public R getNow()
         throws ExecutionException
Retrieves the result of a completed operation.

The method is intended to be invoked from a CompletionHandler to retrieve the result of a completed operation. It is equivalent to invoking the get method to retrieve the result except that the method does not wait for the result.

Specified by:
getNow in interface IoFuture<R,A>
Returns:
the completed result
Throws:
ExecutionException - if the operation threw an exception

attachment

public A attachment()
Retrieves the current attachment.

Specified by:
attachment in interface IoFuture<R,A>
Returns:
the object currently attached to this channel future or null if there is no attachment

attach

public A attach(A newAttachment)
Attaches the given object to this channel future.

An attached object may later be retrieved via the attachment method. Only one object may be attached at a time; invoking this method causes any previous attachment to be discarded. The current attachment may be discarded by attaching null.

Specified by:
attach in interface IoFuture<R,A>
Parameters:
newAttachment - the object to be attached; may be null
Returns:
the previously-attached object, if any, otherwise null

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved