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

java.lang.Object
  extended by com.sun.sgs.impl.nio.AttachedFuture<R,A>
Type Parameters:
R - the result type
A - the attachment type
All Implemented Interfaces:
IoFuture<R,A>, Future<R>

public class AttachedFuture<R,A>
extends Object
implements IoFuture<R,A>

An implementation of IoFuture that adds an object attachment to an arbitrary Future.


Constructor Summary
protected AttachedFuture(Future<R> future, A attachment)
          Creates an AttachedFuture from the given future and attachment.
 
Method Summary
 A attach(A ob)
          Attaches the given object to this channel future.
 A attachment()
          Retrieves the current attachment.
 boolean cancel(boolean mayInterruptIfRunning)
          Attempts to cancel execution of the operation.
 R get()
          
 R get(long timeout, TimeUnit unit)
          
 R getNow()
          Retrieves the result of a completed operation.
 boolean isCancelled()
          
 boolean isDone()
          
static
<R,A> AttachedFuture<R,A>
wrap(Future<R> future, A attachment)
          Creates an AttachedFuture from the given future and attachment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttachedFuture

protected AttachedFuture(Future<R> future,
                         A attachment)
Creates an AttachedFuture from the given future and attachment.

Parameters:
future - the Future to wrap
attachment - the initial attachment, or null
Method Detail

wrap

public static <R,A> AttachedFuture<R,A> wrap(Future<R> future,
                                             A attachment)
Creates an AttachedFuture from the given future and attachment. Provided as a static factory method so that the template types can be inferred by the compiler.

Type Parameters:
R - the result type
A - the attachment type
Parameters:
future - the Future to wrap
attachment - the initial attachment, or null
Returns:
a new AttachedFuture

attach

public A attach(A ob)
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:
ob - the object to be attached; may be null
Returns:
the previously-attached object, if any, otherwise null

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

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of the operation.

If the value of mayInterruptIfRunning is true then this method may cancel the operation forcefully by closing the channel. Whether it does close the channel is implementation and operation specific. If the channel is closed then all outstanding operations on the channel complete by throwing ExecutionException with cause AsynchronousCloseException. Where an implementation does not close the channel then the channel may be put into an error state that prevents further operations on the channel. For example, if a read operation is cancelled and the implementation cannot guarantee that no bytes have been read from the channel then it puts the channel into an implementation specific error state. Any subsequent attempt to initiate a read operation on the channel throws an unspecified runtime exception.

This method otherwise behaves exactly as specified by the Future interface.

Specified by:
cancel in interface IoFuture<R,A>
Specified by:
cancel in interface Future<R>
Parameters:
mayInterruptIfRunning - true if the operation can be cancelled forcefully (possibily by closing the channel), false otherwise
Returns:
false if the operation could not be cancelled, true if the operation has been cancelled

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

get

public R get()
      throws InterruptedException,
             ExecutionException

Specified by:
get in interface Future<R>
Throws:
InterruptedException
ExecutionException

get

public R get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException

Specified by:
get in interface Future<R>
Throws:
InterruptedException
ExecutionException
TimeoutException

isCancelled

public boolean isCancelled()

Specified by:
isCancelled in interface Future<R>

isDone

public boolean isDone()

Specified by:
isDone in interface Future<R>

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