orc.runtime
Class OrcEngine

java.lang.Object
  extended by orc.runtime.OrcEngine
All Implemented Interfaces:
java.lang.Runnable

public class OrcEngine
extends java.lang.Object
implements java.lang.Runnable

The Orc Engine provides the main loop for executing active tokens. Tokens are always processed in a single thread, but tokens might be activated or resumed from other threads, so some synchronization is necessary.

Author:
wcook, dkitchin, quark

Field Summary
 boolean debugMode
           
protected  boolean halt
          This flag is set by the Execution region when execution completes to terminate the engine.
 
Constructor Summary
OrcEngine()
           
 
Method Summary
 void activate(Token t)
          Activate a token by adding it to the queue of active tokens
 boolean addClock(LogicalClock clock)
           
 void debug(java.lang.String s)
           
 Token getCurrentToken()
          Provide access to a package static method.
 boolean isDead()
           
 void print(java.lang.String string)
          Print something (for use by the print and println sites).
 void println(java.lang.String string)
          Print something (for use by the print and println sites).
 void pub(Value v)
          Publish a result.
 void reportRound()
           
 void resume(Token t)
          Activate a token by adding it to the queue of returning tokens
 void run()
          Process active nodes, running indefinitely until signalled to stop by a call to terminate().
 void run(Node root)
          Run Orc given a root node.
 void run(Node root, Env env)
           
 void setCurrentToken(Token caller)
          Provide access to a package static method.
 void start(Node root)
           
 void start(Node root, Env env)
           
protected  boolean step()
          Run one step (process one token, handle one site response, or advance all logical clocks).
 void terminate()
          Terminate execution.
 void tokenError(Token t, TokenException problem)
          A token owned by this engine has encountered an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugMode

public boolean debugMode

halt

protected boolean halt
This flag is set by the Execution region when execution completes to terminate the engine.

Constructor Detail

OrcEngine

public OrcEngine()
Method Detail

isDead

public boolean isDead()

run

public void run()
Process active nodes, running indefinitely until signalled to stop by a call to terminate(). Typically you will use one of the other run methods to queue an active token to process first.

Specified by:
run in interface java.lang.Runnable

terminate

public void terminate()
Terminate execution.


run

public void run(Node root)
Run Orc given a root node. Creates an initial environment and then executes the main loop.

Parameters:
root - node to run

run

public void run(Node root,
                Env env)

start

public void start(Node root)

start

public void start(Node root,
                  Env env)

step

protected boolean step()
Run one step (process one token, handle one site response, or advance all logical clocks). Returns true if work was done.


activate

public void activate(Token t)
Activate a token by adding it to the queue of active tokens

Parameters:
t - the token to be added

resume

public void resume(Token t)
Activate a token by adding it to the queue of returning tokens

Parameters:
t - the token to be added

pub

public void pub(Value v)
Publish a result. This method is called by the Pub node when a publication is 'escaping' the bottom of the execution graph. The default implementation prints the value's string representation to the console. Change this behavior by extending OrcEngine and overriding this method.

Parameters:
v -

tokenError

public void tokenError(Token t,
                       TokenException problem)
A token owned by this engine has encountered an exception. The token dies, remaining silent and leaving the execution, and then calls this method so that the engine can report or otherwise handle the failure.


debug

public void debug(java.lang.String s)

reportRound

public void reportRound()

addClock

public boolean addClock(LogicalClock clock)

print

public void print(java.lang.String string)
Print something (for use by the print and println sites). By default, this prints to System.out, but this can be overridden to do something else if appropriate.

Parameters:
string -

println

public void println(java.lang.String string)
Print something (for use by the print and println sites). By default, this prints to System.out, but this can be overridden to do something else if appropriate.

Parameters:
string -

setCurrentToken

public void setCurrentToken(Token caller)
Provide access to a package static method.


getCurrentToken

public Token getCurrentToken()
Provide access to a package static method.