org.openflow.example
Class SelectLoop

java.lang.Object
  extended by org.openflow.example.SelectLoop

public class SelectLoop
extends java.lang.Object

Dirt simple SelectLoop for simple java controller


Field Summary
protected  SelectListener callback
           
protected  boolean dontStop
           
protected  java.lang.Object registrationLock
           
protected  java.util.Queue<java.lang.Object[]> registrationQueue
           
protected  int registrationRequests
           
protected  java.nio.channels.Selector selector
           
protected  long timeout
           
 
Constructor Summary
SelectLoop(SelectListener cb)
           
SelectLoop(SelectListener cb, long timeout)
          Initializes this SelectLoop
 
Method Summary
 void doLoop()
          Main top-level IO loop this dispatches all IO events and timer events together I believe this is fairly efficient
protected  void processRegistrationQueue()
           
 void register(java.nio.channels.SelectableChannel ch, int ops, java.lang.Object arg)
           
 java.nio.channels.SelectionKey registerBlocking(java.nio.channels.SelectableChannel ch, int ops, java.lang.Object arg)
          Registers the supplied SelectableChannel with this SelectLoop.
 void shutdown()
          Shuts down this select loop, may return before it has fully shutdown
 void wakeup()
          Force this select loop to return immediately and re-enter select, useful for example if a new item has been added to the select loop while it was already blocked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

callback

protected SelectListener callback

dontStop

protected boolean dontStop

registrationLock

protected java.lang.Object registrationLock

registrationRequests

protected int registrationRequests

registrationQueue

protected java.util.Queue<java.lang.Object[]> registrationQueue

selector

protected java.nio.channels.Selector selector

timeout

protected long timeout
Constructor Detail

SelectLoop

public SelectLoop(SelectListener cb)
           throws java.io.IOException
Throws:
java.io.IOException

SelectLoop

public SelectLoop(SelectListener cb,
                  long timeout)
           throws java.io.IOException
Initializes this SelectLoop

Parameters:
cb - the callback to call when select returns
timeout - the timeout value in milliseconds that select will be called with
Throws:
java.io.IOException
Method Detail

register

public void register(java.nio.channels.SelectableChannel ch,
                     int ops,
                     java.lang.Object arg)
              throws java.nio.channels.ClosedChannelException
Throws:
java.nio.channels.ClosedChannelException

registerBlocking

public java.nio.channels.SelectionKey registerBlocking(java.nio.channels.SelectableChannel ch,
                                                       int ops,
                                                       java.lang.Object arg)
                                                throws java.nio.channels.ClosedChannelException
Registers the supplied SelectableChannel with this SelectLoop. Note this method blocks until registration proceeds. It is advised that SelectLoop is intialized with a timeout value when using this method.

Parameters:
ch - the channel
ops - interest ops
arg - argument that will be returned with the SelectListener
Returns:
Throws:
java.nio.channels.ClosedChannelException

doLoop

public void doLoop()
            throws java.io.IOException
Main top-level IO loop this dispatches all IO events and timer events together I believe this is fairly efficient

Throws:
java.io.IOException

processRegistrationQueue

protected void processRegistrationQueue()

wakeup

public void wakeup()
Force this select loop to return immediately and re-enter select, useful for example if a new item has been added to the select loop while it was already blocked.


shutdown

public void shutdown()
Shuts down this select loop, may return before it has fully shutdown