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
           
static Globals<OrcEngine,java.lang.Object> globals
          For debugging visualization
protected  boolean halt
          This flag is set by the Execution region when execution completes to terminate the engine.
 
Constructor Summary
OrcEngine(Config config)
           
 
Method Summary
 void activate(Token t)
          Activate a token by adding it to the queue of active tokens
 java.lang.String addGlobal(java.lang.Object value)
           
 java.io.File createTmpdir()
          Create a new temporary directory and return the path to that directory.
 void debug(java.lang.String s)
           
 boolean deleteTmpdir(java.io.File directory)
          Delete a temporary directory
 Config getConfig()
           
 Execution getExecution()
           
 boolean isDead()
           
 void print(java.lang.String string, boolean newline)
          Print something (for use by the print and println sites).
 void publish(java.lang.Object 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 scheduleTimer(java.util.TimerTask task, long delay)
          Schedule a timed task (used by Rtimer).
 void start(Node root)
           
protected  boolean step()
          Run one step (process one token or handle one site response) Return false if engine should halt.
 void terminate()
          Terminate execution.
 void tokenError(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.


globals

public static final Globals<OrcEngine,java.lang.Object> globals
For debugging visualization

Constructor Detail

OrcEngine

public OrcEngine(Config config)
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

start

public void start(Node root)

step

protected boolean step()
Run one step (process one token or handle one site response) Return false if engine should halt.


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

publish

public void publish(java.lang.Object 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(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()

print

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

See Also:
Token.print(String, boolean)

scheduleTimer

public void scheduleTimer(java.util.TimerTask task,
                          long delay)
Schedule a timed task (used by Rtimer).


addGlobal

public java.lang.String addGlobal(java.lang.Object value)

getConfig

public Config getConfig()

getExecution

public Execution getExecution()

createTmpdir

public java.io.File createTmpdir()
                          throws java.io.IOException
Create a new temporary directory and return the path to that directory. The directory will be deleted automatically when the engine halts, or you can delete it earlier with deleteTmpdir

Throws:
java.io.IOException

deleteTmpdir

public boolean deleteTmpdir(java.io.File directory)
Delete a temporary directory