net.sf.asyncobjects.vats
Class SingleThreadIdleRunner

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

public abstract class SingleThreadIdleRunner
extends VatQueueRunner
implements ThreadBasedRunner

This base class for runners allows executing some idle action instead of blocking on vat queue.

Author:
const

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
protected  boolean isIdle
          if true, the action is currently idle
 
Fields inherited from class net.sf.asyncobjects.vats.VatQueueRunner
queue
 
Fields inherited from class net.sf.asyncobjects.vats.VatRunner
state, stateLock
 
Constructor Summary
SingleThreadIdleRunner()
          A constructor
SingleThreadIdleRunner(String threadName, boolean isDaemon)
          A constructor
 
Method Summary
protected  boolean hasEvents(Vat vat, Object ticket)
          This method is called by the vat when new events have arrived.
protected abstract  void idle()
          perform idle action, idle action should stop to be performed after wakeup call.
protected  void init()
          Init the vat
protected  boolean isStopping()
           
protected  void pollIdle()
          poll action, poll should never block.
 void resumeInCurrentThread()
          This methods resumes the suspended runner in the current thread.
protected  void setPollInterval(int n)
          Set poll interval
 void startInCurrentThread()
          Start runner in the current thread.
 void startInNewThread()
          Start vat in new thread
 void stop()
          Stop this runner
protected  void stopped()
          After vat is stopped
protected  void stopping()
          Stopping the vat
 void suspend()
          This method cases the runner to suspend its work.
protected abstract  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.VatRunner
cancelledEqueuedVat, getBachingFactor, getState, newVat, 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, newVat
 

Field Detail

isIdle

protected boolean isIdle
if true, the action is currently idle

Constructor Detail

SingleThreadIdleRunner

public SingleThreadIdleRunner(String threadName,
                              boolean isDaemon)
A constructor

Parameters:
threadName - a thread name
isDaemon - if true a thread will be a daemon thread

SingleThreadIdleRunner

public SingleThreadIdleRunner()
A constructor

Method Detail

setPollInterval

protected void setPollInterval(int n)
Set poll interval

Parameters:
n - a poll turns

hasEvents

protected boolean hasEvents(Vat vat,
                            Object ticket)
Description copied from class: VatRunner
This method is called by the vat when new events have arrived. This method should never block and to be as fast as possible. This method executed within synchronoization over Vat's state lock. The vat enqueues itself only if is not running or enqueued yet.

Overrides:
hasEvents in class VatQueueRunner
Parameters:
vat - a vat that has new events and is associated with the runner
ticket - a ticket from the vat
Returns:
true if runner accpets the vat, false otherwise (happens if runner is stopped or is stopping)
See Also:
VatQueueRunner.hasEvents(net.sf.asyncobjects.vats.Vat, java.lang.Object)

startInCurrentThread

public void startInCurrentThread()
Start runner in the current thread.

Specified by:
startInCurrentThread in interface ThreadBasedRunner

startInNewThread

public void startInNewThread()
Start vat in new thread

Specified by:
startInNewThread in interface ThreadBasedRunner

stop

public void stop()
Stop this runner

Specified by:
stop in interface ThreadBasedRunner

init

protected void init()
Init the vat


stopping

protected void stopping()
Stopping the vat


stopped

protected void stopped()
After vat is stopped


idle

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


wakeupIdle

protected abstract 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.


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.


isStopping

protected boolean isStopping()
Returns:
true if stop operation is in progress

suspend

public void suspend()
Description copied from interface: ThreadBasedRunner
This method cases the runner to suspend its work.

Specified by:
suspend in interface ThreadBasedRunner
See Also:
ThreadBasedRunner.suspend()

resumeInCurrentThread

public void resumeInCurrentThread()
Description copied from interface: ThreadBasedRunner
This methods resumes the suspended runner in the current thread.

Specified by:
resumeInCurrentThread in interface ThreadBasedRunner
See Also:
ThreadBasedRunner.resumeInCurrentThread()


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.