rabbit.httpio
Class SelectorRunner

java.lang.Object
  extended by rabbit.httpio.SelectorRunner
All Implemented Interfaces:
Runnable, TaskRunner

public class SelectorRunner
extends Object
implements Runnable, TaskRunner

A class that handles a selector.

Author:
Robert Olofsson

Constructor Summary
SelectorRunner(ExecutorService executorService, Logger logger)
          Create a SelectorRunner that uses the given thread pool to run background tasks.
 
Method Summary
 Selector getSelector()
          Get the selector used for network operations.
 void run()
          Run the selector operations.
 void runMainTask(Runnable r)
          Run a task on the selector.
 void runThreadTask(Runnable r)
          Run a task in the thread pool.
 void shutdown()
          Stop and close the selector and shutdown the thread pool.
 void start()
          Start running the selector in a new thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectorRunner

public SelectorRunner(ExecutorService executorService,
                      Logger logger)
               throws IOException
Create a SelectorRunner that uses the given thread pool to run background tasks.

Throws:
IOException
Method Detail

start

public void start()
Start running the selector in a new thread.


shutdown

public void shutdown()
Stop and close the selector and shutdown the thread pool.

Specified by:
shutdown in interface TaskRunner

runThreadTask

public void runThreadTask(Runnable r)
Run a task in the thread pool.

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

runMainTask

public void runMainTask(Runnable r)
Run a task on the selector.

Specified by:
runMainTask in interface TaskRunner
Parameters:
r - the task to run on the main thread.

getSelector

public Selector getSelector()
Get the selector used for network operations.


run

public void run()
Run the selector operations.

Specified by:
run in interface Runnable