org.khelekore.rnio.impl
Class MultiSelectorNioHandler

java.lang.Object
  extended by org.khelekore.rnio.impl.MultiSelectorNioHandler
All Implemented Interfaces:
NioHandler

public class MultiSelectorNioHandler
extends Object
implements NioHandler

An implementation of NioHandler that runs several selector threads.

Any tasks that should run on a background thread are passed to the ExecutorService that was given in the constructor.

This class will log using the "org.khelekore.rnio" Logger.

Author:
Robert Olofsson

Constructor Summary
MultiSelectorNioHandler(ExecutorService executorService, StatisticsHolder stats, int numSelectors, Long defaultTimeout)
          Create a new MultiSelectorNioHandler that runs background tasks on the given executor and has a specified number of selectors.
 
Method Summary
 void cancel(SelectableChannel channel, SocketChannelHandler handler)
          Remove an event listener.
 void close(SelectableChannel channel)
          Close the given channel.
 Long getDefaultTimeout()
          Get the default timeout time for an operations started at this point in time.
 StatisticsHolder getTimingStatistics()
          Get the timing information for the thread tasks.
 void runThreadTask(Runnable r, TaskIdentifier ti)
          Run a task in a background thread.
 void shutdown()
          Shutdown this task runner.
 void start()
          Start handling operations.
 void visitSelectors(SelectorVisitor visitor)
          Visit all the selectors.
 void waitForAccept(SelectableChannel channel, AcceptHandler handler)
          Install an event listener for accent events.
 void waitForConnect(SelectableChannel channel, ConnectHandler handler)
          Install an event listener for connect events.
 void waitForRead(SelectableChannel channel, ReadHandler handler)
          Install an event listener for read events.
 void waitForWrite(SelectableChannel channel, WriteHandler handler)
          Install an event listener for write events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiSelectorNioHandler

public MultiSelectorNioHandler(ExecutorService executorService,
                               StatisticsHolder stats,
                               int numSelectors,
                               Long defaultTimeout)
                        throws IOException
Create a new MultiSelectorNioHandler that runs background tasks on the given executor and has a specified number of selectors.

Parameters:
executorService - the ExecutorService to use for this NioHandler
stats - the StatisticsHolder to use for this NioHandler
numSelectors - the number of threads that this NioHandler will use
defaultTimeout - the default timeout value for this NioHandler
Throws:
IOException
Method Detail

start

public void start()
Description copied from interface: NioHandler
Start handling operations.

Specified by:
start in interface NioHandler

shutdown

public void shutdown()
Description copied from interface: NioHandler
Shutdown this task runner. This will make the NioHandler stop accepting new thread tasks and it will close all channels that are still registerd (and call closed () for the channel handlers).

Specified by:
shutdown in interface NioHandler

getDefaultTimeout

public Long getDefaultTimeout()
Description copied from interface: NioHandler
Get the default timeout time for an operations started at this point in time.

Specified by:
getDefaultTimeout in interface NioHandler

runThreadTask

public void runThreadTask(Runnable r,
                          TaskIdentifier ti)
Description copied from interface: NioHandler
Run a task in a background thread. The task will be run sometime in the future.

Specified by:
runThreadTask in interface NioHandler
Parameters:
r - the task to run.

waitForRead

public void waitForRead(SelectableChannel channel,
                        ReadHandler handler)
Description copied from interface: NioHandler
Install an event listener for read events. When the channels is ready the ReadHandler.read () method will be called and read selection will be turned off for the channel.

Specified by:
waitForRead in interface NioHandler

waitForWrite

public void waitForWrite(SelectableChannel channel,
                         WriteHandler handler)
Description copied from interface: NioHandler
Install an event listener for write events. When the channel is ready the WriteHandler.write () method will be called and write selection will be turned off for the channel.

Specified by:
waitForWrite in interface NioHandler

waitForAccept

public void waitForAccept(SelectableChannel channel,
                          AcceptHandler handler)
Description copied from interface: NioHandler
Install an event listener for accent events. When the channel is ready the Accepthandler.accept () method will be called and accept selection will be turned off for the channel.

Specified by:
waitForAccept in interface NioHandler

waitForConnect

public void waitForConnect(SelectableChannel channel,
                           ConnectHandler handler)
Description copied from interface: NioHandler
Install an event listener for connect events. When the channel is ready the Connecthandler.connect () method will be called and connect selection will be turned off for the channel.

Specified by:
waitForConnect in interface NioHandler

cancel

public void cancel(SelectableChannel channel,
                   SocketChannelHandler handler)
Description copied from interface: NioHandler
Remove an event listener.

Specified by:
cancel in interface NioHandler

close

public void close(SelectableChannel channel)
Description copied from interface: NioHandler
Close the given channel. Closing a channel will cause SocketChannelHandler.close () to be raised on any listeners for this channel and will then cancel all selector interaction.

Specified by:
close in interface NioHandler

visitSelectors

public void visitSelectors(SelectorVisitor visitor)
Description copied from interface: NioHandler
Visit all the selectors. This should really only be used for status handling and/or debugging.

Specified by:
visitSelectors in interface NioHandler

getTimingStatistics

public StatisticsHolder getTimingStatistics()
Description copied from interface: NioHandler
Get the timing information for the thread tasks.

Specified by:
getTimingStatistics in interface NioHandler