|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.lightwolf.IOActivator
public class IOActivator
An object that activate flows when a NIO channel operation becomes available.
Constructor Summary | |
---|---|
IOActivator()
|
Method Summary | |
---|---|
SocketChannel |
accept(ServerSocketChannel socket)
Accepts a single incoming connection without holding any thread during the wait. |
SocketChannel |
acceptMany(ServerSocketChannel socket)
Accepts multiple incoming connections without holding any thread during the wait. |
void |
cancelAccepts(ServerSocketChannel socket)
|
void |
close()
|
int |
read(ReadableByteChannel channel,
ByteBuffer dst)
Reads a sequence of bytes from the channel without holding any thread during the wait. |
int |
wait(SelectableChannel channel,
int ops)
|
int |
write(WritableByteChannel channel,
ByteBuffer src)
Writes a sequence of bytes from the channel without holding any thread during the wait. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IOActivator() throws IOException
IOException
Method Detail |
---|
public SocketChannel acceptMany(ServerSocketChannel socket) throws IOException
@FlowMethod
void example() {
ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(8080));
serverSocket.configureBlocking(false);
IOActivator activator = new IOActivator();
// The following will run for each incoming connection.
SocketChannel clientSocket = activator.acceptMany(serverSocket);
// Process this connection. May run in parallel with other connections.
clientSocket.close();
}
The informed socket must be in non-blocking mode, so this class can call
register()
without triggering an exception. Despite this fact, this method never
returns null
nor it blocks the current thread, as specified
in on Flow.suspend(Object)
.
This method always returns to a new flow. That is, it never returns to the invoker's flow.
socket
- The server socket. Must be already bound to an address, and
must be configured to non-blocking mode.
ClosedChannelException
- If this channel is closed.
AsynchronousCloseException
- If another thread closes this channel
while the accept operation is in progress.
ClosedByInterruptException
- If another thread interrupts the
current thread while the accept operation is in progress, thereby
closing the channel and setting the current thread's interrupt
status.
IOException
- If some other I/O error occurs.
IllegalBlockingModeException
- If this channel is not in
non-blocking mode.
NotYetBoundException
- If this channel's socket has not yet been
bound.
SecurityException
- If a security manager has been installed and it
does not permit access to the remote endpoint of the new
connection.ServerSocketChannel.accept()
public SocketChannel accept(ServerSocketChannel socket) throws IOException
ServerSocketChannel.accept()
operation, this method returns
immediately. Otherwise the channel is
registered
on this object's selector and the current flow is
suspended until an incoming connection is
established.
This method always returns to the invoker's flow.
socket
- The server socket. Must be already bound to an address, and
must be configured to non-blocking mode.
ClosedChannelException
- If this channel is closed.
AsynchronousCloseException
- If another thread closes this channel
while the accept operation is in progress.
ClosedByInterruptException
- If another thread interrupts the
current thread while the accept operation is in progress, thereby
closing the channel and setting the current thread's interrupt
status.
IOException
- If some other I/O error occurs.
IllegalBlockingModeException
- If this channel is not in
non-blocking mode.
NotYetBoundException
- If this channel's socket has not yet been
bound.
SecurityException
- If a security manager has been installed and it
does not permit access to the remote endpoint of the new
connection.ServerSocketChannel.accept()
public int read(ReadableByteChannel channel, ByteBuffer dst) throws IOException
This method always returns to the invoker's flow.
channel
- The channel on which the read operation is to be
performed.dst
- The buffer into which bytes are to be transferred
ClassCastException
- If the channel is not a
SelectableChannel
.
NonReadableChannelException
- If this channel was not opened for
reading
ClosedChannelException
- If this channel is closed
AsynchronousCloseException
- If another thread closes this channel
while the read operation is in progress
ClosedByInterruptException
- If another thread interrupts the
current thread while the read operation is in progress, thereby
closing the channel and setting the current thread's interrupt
status
IOException
- If some other I/O error occursReadableByteChannel.read(ByteBuffer)
public int write(WritableByteChannel channel, ByteBuffer src) throws IOException
This method always returns to the invoker's flow.
channel
- The channel on which the write operation is to be
performed.src
- The buffer from which bytes are to be retrieved
ClassCastException
- If the channel is not a
SelectableChannel
.
NonWritableChannelException
- If this channel was not opened for
writing
ClosedChannelException
- If this channel is closed
AsynchronousCloseException
- If another thread closes this channel
while the write operation is in progress
ClosedByInterruptException
- If another thread interrupts the
current thread while the write operation is in progress, thereby
closing the channel and setting the current thread's interrupt
status
IOException
- If some other I/O error occursWritableByteChannel.write(ByteBuffer)
public int wait(SelectableChannel channel, int ops) throws IOException
IOException
public void cancelAccepts(ServerSocketChannel socket)
public void close() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |