net.sf.asyncobjects.vats
Class VatRunner

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

public abstract class VatRunner
extends Object
implements VatFactory

This is a base class for vat runners. The vat is a just an event queue. The vat runner actually executes the events. The vat has a single runner, however runners support multiple vats.

While vat runner is aware about the current vat, it does not keeps track of vats that is running.

The runner might provide additional services to the vats it is hosting. So vats might check if the runner belong to some specific subclass to obtain these services.

Author:
const

Nested Class Summary
static class VatRunner.VatRunnerState
          Vat state
 
Field Summary
protected  VatRunner.VatRunnerState state
          a state of vat runner
protected  Object stateLock
          a state lock
 
Constructor Summary
VatRunner()
           
 
Method Summary
protected  void cancelledEqueuedVat(Vat vat, Object ticket)
          This method cancels enquued vat and detaches it from runner.
 int getBachingFactor()
           
 VatRunner.VatRunnerState getState()
           
protected abstract  boolean hasEvents(Vat vat, Object ticket)
          This method is called by the vat when new events have arrived.
 Vat newVat()
          Create default vat for this runner.
 Vat newVat(String name)
          Create default vat for this runner
 void setBachingFactor(int bachingFactor)
          Set batching factor
protected  void setStarted()
          Set state to started
protected  void setStarting()
          Set state to starting
protected  void setState(VatRunner.VatRunnerState state)
           
protected  void setStopped()
          Set stopped state
protected  void setStopping()
          Set stoppong state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

protected VatRunner.VatRunnerState state
a state of vat runner


stateLock

protected Object stateLock
a state lock

Constructor Detail

VatRunner

public VatRunner()
Method Detail

getBachingFactor

public int getBachingFactor()
Returns:
the bachingFactor

setBachingFactor

public void setBachingFactor(int bachingFactor)
Set batching factor

Parameters:
bachingFactor - the baching factor to set

hasEvents

protected abstract boolean hasEvents(Vat vat,
                                     Object ticket)
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.

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)

cancelledEqueuedVat

protected final void cancelledEqueuedVat(Vat vat,
                                         Object ticket)
This method cancels enquued vat and detaches it from runner. The vat must be in equeued or idle state. This method is called when runner is unable to honor already accepted enqueue request.

Parameters:
vat - a vat
ticket - a ticket
Throws:
IllegalArgumentException - if vat is not attached to this runner or ticket do not match.

setStarted

protected void setStarted()
Set state to started


setStarting

protected void setStarting()
Set state to starting


setStopped

protected void setStopped()
Set stopped state


setStopping

protected void setStopping()
Set stoppong state


getState

public VatRunner.VatRunnerState getState()
Returns:
the state

setState

protected void setState(VatRunner.VatRunnerState state)
Parameters:
state - the state to set

newVat

public Vat newVat(String name)
Create default vat for this runner

Specified by:
newVat in interface VatFactory
Parameters:
name - a vat name
Returns:
a vat

newVat

public Vat newVat()
Create default vat for this runner. It passes null as to name of the vat causing default name generation.

Specified by:
newVat in interface VatFactory
Returns:
a vat


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.