org.apache.awf.io
Class IOLoop

java.lang.Object
  extended by org.apache.awf.io.IOLoop
All Implemented Interfaces:
IOLoopMXBean

public class IOLoop
extends Object
implements IOLoopMXBean


Field Summary
static IOLoop INSTANCE
           
 
Constructor Summary
IOLoop()
           
 
Method Summary
 void addCallback(AsyncCallback callback)
          The callback will be invoked in the next iteration in the io loop.
 SelectionKey addHandler(SelectableChannel channel, IOHandler handler, int interestOps, Object attachment)
          Registers a new IOHandler with this IOLoop.
 void addKeepAliveTimeout(SelectableChannel channel, Timeout keepAliveTimeout)
           
 void addTimeout(Timeout timeout)
           
 int getNumberOfRegisteredIOHandlers()
           
 List<String> getRegisteredIOHandlers()
           
 boolean hasKeepAliveTimeout(SelectableChannel channel)
           
 boolean isRunning()
          Checks whether this IOLoop is running or not.
 void removeHandler(SelectableChannel channel)
          Unregisters the previously registered IOHandler.
 void start()
          Start the io loop.
 void stop()
          Stop the io loop and release the thread (io loop thread) that invoked the start() method.
 void updateHandler(SelectableChannel channel, int newInterestOps)
          Update an earlier registered SelectableChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final IOLoop INSTANCE
Constructor Detail

IOLoop

public IOLoop()
Method Detail

start

public void start()
Start the io loop. The thread that invokes this method will be blocked (until stop() is invoked) and will be the io loop thread.


stop

public void stop()
Stop the io loop and release the thread (io loop thread) that invoked the start() method.


addHandler

public SelectionKey addHandler(SelectableChannel channel,
                               IOHandler handler,
                               int interestOps,
                               Object attachment)
Registers a new IOHandler with this IOLoop.

Parameters:
channel - The SelectableChannel
handler - IOHandler that will receive the io callbacks.
interestOps - See SelectionKey for valid values. (Xor for multiple interests).
attachment - The attachment that will be accessible from the returning SelectionKeys attachment.

removeHandler

public void removeHandler(SelectableChannel channel)
Unregisters the previously registered IOHandler.

Parameters:
channel - The SelectableChannel that was registered with a user defined IOHandler

updateHandler

public void updateHandler(SelectableChannel channel,
                          int newInterestOps)
Update an earlier registered SelectableChannel

Parameters:
channel - The SelectableChannel
newInterestOps - The complete new set of interest operations.

addKeepAliveTimeout

public void addKeepAliveTimeout(SelectableChannel channel,
                                Timeout keepAliveTimeout)

hasKeepAliveTimeout

public boolean hasKeepAliveTimeout(SelectableChannel channel)

addTimeout

public void addTimeout(Timeout timeout)

addCallback

public void addCallback(AsyncCallback callback)
The callback will be invoked in the next iteration in the io loop. This is the only thread safe method that is exposed by AWF. This is a convenient way to return control to the io loop.


getNumberOfRegisteredIOHandlers

public int getNumberOfRegisteredIOHandlers()
Specified by:
getNumberOfRegisteredIOHandlers in interface IOLoopMXBean

getRegisteredIOHandlers

public List<String> getRegisteredIOHandlers()
Specified by:
getRegisteredIOHandlers in interface IOLoopMXBean

isRunning

public boolean isRunning()
Checks whether this IOLoop is running or not.

Returns:
true if running; false otherwise.


Copyright © 2012. All Rights Reserved.