com.sun.sgs.impl.nio
Interface AsyncKey

All Superinterfaces:
Closeable, Executor
All Known Implementing Classes:
Reactor.ReactiveAsyncKey

interface AsyncKey
extends Closeable, Executor

A token handed out by an AsyncGroupImpl to support asynchronous IO operations on an underlying SelectableChannel.

It is similar in function to the SelectionKey in non-blocking reactive IO.


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.
 

Method Detail

channel

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

Returns:
the underlying SelectableChannel for this key

isOpPending

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.

Parameters:
op - a SelectionKey opcode
Returns:
true if the operation is pending

selected

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.

Parameters:
readyOps - the SelectionKey ops that are ready

execute

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 Executor
Parameters:
command - the command to run, possibly in another thread

runCompletion

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

Type Parameters:
R - the result type
A - the attachment type
Parameters:
handler - the completion handler
attachment - the attachment, or null
future - the result

execute

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

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
Throws:
ClosedAsynchronousChannelException - if the channel is closed
ReadPendingException - if OP_READ is requested but already pending
WritePendingException - if OP_WRITE is requested but already pending
ConnectionPendingException - OP_CONNECT is requested but already pending
AcceptPendingException - if OP_ACCEPT is requested but already pending
See Also:
CompletionHandler, AsynchronousChannel

close

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.

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

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