com.sun.sgs.impl.nio
Class Reactor.ReactiveAsyncKey

java.lang.Object
  extended by com.sun.sgs.impl.nio.Reactor.ReactiveAsyncKey
All Implemented Interfaces:
AsyncKey, Closeable, Executor
Enclosing class:
Reactor

 class Reactor.ReactiveAsyncKey
extends Object
implements AsyncKey

Provides support for initiating asynchronous IO operations on an underlying reactive channel registered with this Reactor.

See Also:
AsyncKey

Field Summary
(package private)  SelectionKey key
          The SelectionKey representing the underlying channel's registration with this Reactor's Selector.
 
Constructor Summary
Reactor.ReactiveAsyncKey(SelectionKey key)
          Creates a new instance that wraps the given selector key.
 
Method Summary
 SelectableChannel channel()
          Returns the underlying SelectableChannel for this key.
 void close()
          Closes this key's underlying channel.
<R,A> IoFuture<R,A>
execute(int op, A attachment, CompletionHandler<R,? super A> handler, long timeout, TimeUnit unit, Callable<R> callable)
          Initiates the given operation asynchronously on the underlying channel, and returns a future representing the result.
 void execute(Runnable command)
          Executes the given command according to the execution policy determined by this key and channel group.
 boolean isOpPending(int op)
          Returns whether the given operation is pending.
<R,A> void
runCompletion(CompletionHandler<R,A> handler, A attachment, Future<R> future)
          Invokes the given completion handler, if it is not null; otherwise does nothing.
 void selected(int readyOps)
          Notifies this key that the given IO operations are ready on the underlying channel.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

key

final SelectionKey key
The SelectionKey representing the underlying channel's registration with this Reactor's Selector.

Constructor Detail

Reactor.ReactiveAsyncKey

Reactor.ReactiveAsyncKey(SelectionKey key)
Creates a new instance that wraps the given selector key.

Parameters:
key - the selection key that represents the underlying channel's registration with this reactor's selector
Method Detail

close

public void close()
           throws IOException
Closes this key's underlying channel. The channel must be closed via this key, not directly.

[Description copied from AsynchronousChannel.close()]

Any outstanding asynchronous operations upon this channel will complete by throwing ExecutionException with cause AsynchronousCloseException.

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

This implementation does the following:

Specified by:
close in interface AsyncKey
Specified by:
close in interface Closeable
Throws:
IOException - if an I/O error occurs

isOpPending

public boolean isOpPending(int op)
Returns whether the given operation is pending. An operation is marked as finished (i.e., no longer pending) just before its completion handler is invoked.

Specified by:
isOpPending in interface AsyncKey
Parameters:
op - a SelectionKey opcode
Returns:
true if the operation is pending

channel

public SelectableChannel channel()
Returns the underlying SelectableChannel for this key.

Specified by:
channel in interface AsyncKey
Returns:
the underlying SelectableChannel for this key

selected

public void selected(int readyOps)
Notifies this key that the given IO operations are ready on the underlying channel. The caller must ensure that interest in these ops has been cleared before invoking this method.

Specified by:
selected in interface AsyncKey
Parameters:
readyOps - the SelectionKey ops that are ready

execute

public <R,A> IoFuture<R,A> execute(int op,
                                   A attachment,
                                   CompletionHandler<R,? super A> handler,
                                   long timeout,
                                   TimeUnit unit,
                                   Callable<R> callable)
Initiates the given operation asynchronously on the underlying channel, and returns a future representing the result. An appropriate exception is thrown if the channel is closed or the requested operation is already pending. If a non-null completion handler is provided, it will be invoked when the operation completes.

Specified by:
execute in interface AsyncKey
Type Parameters:
R - the result type
A - the attachment type
Parameters:
op - a SelectionKey opcode
attachment - the attachment for the IoFuture; may be null
handler - the completion handler; may be null
timeout - the timeout for this operation, or 0 to wait indefinitely
unit - the unit of the timeout
callable - performs an IO operation on the underlying channel when invoked
Returns:
a future representing the result of this operation
See Also:
CompletionHandler, AsynchronousChannel

execute

public void execute(Runnable command)
Executes the given command according to the execution policy determined by this key and channel group. This method supports asynchronous channel operations that cannot be awaited using select().

Specified by:
execute in interface AsyncKey
Specified by:
execute in interface Executor
Parameters:
command - the command to run, possibly in another thread

runCompletion

public <R,A> void runCompletion(CompletionHandler<R,A> handler,
                                A attachment,
                                Future<R> future)
Invokes the given completion handler, if it is not null; otherwise does nothing. Passes the handler an IoFuture constructed from the given future and attachment object.

Specified by:
runCompletion in interface AsyncKey
Type Parameters:
R - the result type
A - the attachment type
Parameters:
handler - the completion handler
attachment - the attachment, or null
future - the result

toString

public String toString()

Overrides:
toString in class Object

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