net.sf.asyncobjects.net.nio
Class NIOSelectorRunner

java.lang.Object
  extended by net.sf.asyncobjects.vats.VatRunner
      extended by net.sf.asyncobjects.vats.VatQueueRunner
          extended by net.sf.asyncobjects.vats.SingleThreadIdleRunner
              extended by net.sf.asyncobjects.net.nio.NIOSelectorRunner
All Implemented Interfaces:
ThreadBasedRunner, VatFactory

public class NIOSelectorRunner
extends SingleThreadIdleRunner

A selector runner, there could be only one vat per selector and only one selector in runner. JDK 1.4 NIO is really "single point of blocking for many sockets" rather then nonblocking.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.asyncobjects.vats.VatQueueRunner
VatQueueRunner.EnqueuedVat
 
Nested classes/interfaces inherited from class net.sf.asyncobjects.vats.VatRunner
VatRunner.VatRunnerState
 
Field Summary
 
Fields inherited from class net.sf.asyncobjects.vats.SingleThreadIdleRunner
isIdle
 
Fields inherited from class net.sf.asyncobjects.vats.VatQueueRunner
queue
 
Fields inherited from class net.sf.asyncobjects.vats.VatRunner
state, stateLock
 
Constructor Summary
NIOSelectorRunner()
          a constructor
NIOSelectorRunner(String name, boolean isDaemon)
          A constructor
 
Method Summary
protected  ByteBuffer getDirectBuffer()
           
protected  void idle()
          perform idle action, idle action should stop to be performed after wakeup call.
protected  void init()
          init action
 NIOSelectorVat newVat(String name)
          Create default vat for this runner
protected  void pollIdle()
          poll action, poll should never block.
 SelectionKey registerChannel(SelectableChannel ch)
          register channel with listener
protected  void returnDirectBuffer(ByteBuffer buffer)
          Return buffer to the runner
 void stop()
          Stop this runner
protected  void stopped()
          stop action
protected  void wakeupIdle()
          wakeup idle action and perform, wakeupIdle should be ready to fact that it will be called several times and that it could be called before actual entering into idle call.
 
Methods inherited from class net.sf.asyncobjects.vats.SingleThreadIdleRunner
hasEvents, isStopping, resumeInCurrentThread, setPollInterval, startInCurrentThread, startInNewThread, stopping, suspend
 
Methods inherited from class net.sf.asyncobjects.vats.VatRunner
cancelledEqueuedVat, getBachingFactor, getState, newVat, setBachingFactor, setStarted, setStarting, setState, setStopped, setStopping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asyncobjects.vats.VatFactory
newVat
 

Constructor Detail

NIOSelectorRunner

public NIOSelectorRunner(String name,
                         boolean isDaemon)
A constructor

Parameters:
name - name of runner
isDaemon - true if a created thread should be daemon thread

NIOSelectorRunner

public NIOSelectorRunner()
a constructor

Method Detail

newVat

public NIOSelectorVat newVat(String name)
Description copied from class: VatRunner
Create default vat for this runner

Specified by:
newVat in interface VatFactory
Overrides:
newVat in class VatRunner
Parameters:
name - a vat name
Returns:
a vat
See Also:
VatRunner.newVat(java.lang.String)

init

protected void init()
init action

Overrides:
init in class SingleThreadIdleRunner

stop

public void stop()
Description copied from class: SingleThreadIdleRunner
Stop this runner

Specified by:
stop in interface ThreadBasedRunner
Overrides:
stop in class SingleThreadIdleRunner
See Also:
SingleThreadIdleRunner.stop()

stopped

protected void stopped()
stop action

Overrides:
stopped in class SingleThreadIdleRunner

idle

protected void idle()
perform idle action, idle action should stop to be performed after wakeup call.

Specified by:
idle in class SingleThreadIdleRunner

pollIdle

protected void pollIdle()
poll action, poll should never block. It is intendent for getting message if there is overabudance of action on the vat.

Overrides:
pollIdle in class SingleThreadIdleRunner

registerChannel

public SelectionKey registerChannel(SelectableChannel ch)
                             throws Exception
register channel with listener

Parameters:
ch - a channel used by component
Returns:
a selection key for that component
Throws:
Exception - if there is IO problme

getDirectBuffer

protected ByteBuffer getDirectBuffer()
Returns:
the direct buffer from runner

returnDirectBuffer

protected void returnDirectBuffer(ByteBuffer buffer)
Return buffer to the runner

Parameters:
buffer - a buffer to return

wakeupIdle

protected void wakeupIdle()
wakeup idle action and perform, wakeupIdle should be ready to fact that it will be called several times and that it could be called before actual entering into idle call.

Specified by:
wakeupIdle in class SingleThreadIdleRunner


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.