juju.reattore.core.reactor.impl
Class CombinedReactor

java.lang.Object
  |
  +--juju.reattore.core.reactor.impl.CombinedReactor
All Implemented Interfaces:
ClientSocketReactor, Reactor, ServerSocketReactor

public class CombinedReactor
extends java.lang.Object
implements ServerSocketReactor, ClientSocketReactor

Base implementation of a combined server/client reactor


Constructor Summary
CombinedReactor()
          Creates a new reactor.
 
Method Summary
 void attach(java.nio.channels.ServerSocketChannel ch, ServerSocketHandler handler)
          Binds this reactor to a new handler and socket.
 void attach(java.nio.channels.SocketChannel ch, ClientSocketHandler handler)
          Binds this reactor to a new handler and socket.
 void close()
          Causes this reactor to stop once all of the handlers are done.
 void connect(java.nio.channels.SocketChannel ch, java.net.SocketAddress addr, ClientSocketHandler handler)
          Similar to #attach, but takes a currently unconnected socket, connects it, and manages it.
 void go()
          Hands over execution to this reactor.
 void poll()
          Polls the list of sockets and processes any that have become active.
 void setStatsInterval(int interval)
          Sets how often the statistics are dumped to the console.
 void stop()
          Causes this reactor to asynchronisally stop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CombinedReactor

public CombinedReactor()
                throws java.io.IOException
Creates a new reactor.

Throws:
java.io.IOException - if a selector cannot be opened (fatal)
Method Detail

setStatsInterval

public void setStatsInterval(int interval)
Sets how often the statistics are dumped to the console. This interval is not a guaranteed.

Parameters:
interval - The time in ms, or <=0 to disable.

go

public void go()
        throws java.io.IOException
Hands over execution to this reactor. The reactor will run until #stop() is called.

Throws:
java.io.IOException - if an unspecified (fatal) error occurs.

stop

public void stop()
Causes this reactor to asynchronisally stop. Will not stop a stuck reactor.


close

public void close()
Causes this reactor to stop once all of the handlers are done. May result in high CPU load. May not stop.


poll

public void poll()
          throws java.io.IOException
Polls the list of sockets and processes any that have become active.

Throws:
java.io.IOException - on a fatal error PENDING

attach

public void attach(java.nio.channels.ServerSocketChannel ch,
                   ServerSocketHandler handler)
            throws java.io.IOException
Description copied from interface: ServerSocketReactor
Binds this reactor to a new handler and socket. The socket should be created and bound but otherwise unused.

Specified by:
attach in interface ServerSocketReactor
Parameters:
ch - The socket to manage
handler - The handler to call when the socket changes
Throws:
java.io.IOException - on PENDING
See Also:
ServerSocketReactor

attach

public void attach(java.nio.channels.SocketChannel ch,
                   ClientSocketHandler handler)
            throws java.io.IOException
Description copied from interface: ClientSocketReactor
Binds this reactor to a new handler and socket. The socket should be created and bound but otherwise unused.

Specified by:
attach in interface ClientSocketReactor
Parameters:
ch - The socket to manage
handler - The handler to call when the socket changes
Throws:
java.io.IOException - on PENDING
See Also:
ClientSocketReactor

connect

public void connect(java.nio.channels.SocketChannel ch,
                    java.net.SocketAddress addr,
                    ClientSocketHandler handler)
             throws java.io.IOException
Description copied from interface: ClientSocketReactor
Similar to #attach, but takes a currently unconnected socket, connects it, and manages it.

Specified by:
connect in interface ClientSocketReactor
Parameters:
ch - The socket to manage
addr - The address to connect to
handler - The handler to call when the socket changes
Throws:
java.io.IOException - on PENDING
See Also:
ClientSocketReactor


Copyright © 2002-2003 Michael Hope. All Rights Reserved.