The Meta-Environment API

toolbus
Class ToolBus

java.lang.Object
  extended by toolbus.ToolBus
Direct Known Subclasses:
DebugToolBus

public class ToolBus
extends java.lang.Object

ToolBus implements the behaviour of one ToolBus.


Nested Class Summary
protected static class ToolBus.ProcessInstanceIterator
          Custom iterator class.
 
Field Summary
protected  SocketConnectionHandler connectionHandler
           
private  DirectConnectionHandler directConnectionHandler
           
protected  MatchStore matchStore
           
protected  int nerrors
           
private  long nextTime
           
private  java.io.PrintWriter out
           
protected  int portNumber
           
private  toolbus.util.collections.ConcurrentHashMap<java.lang.String,ProcessDefinition> procdefs
           
protected  java.util.List<ProcessInstance> processes
           
private  int processIdCounter
           
private  java.lang.Object processLock
           
protected  PropertyManager propertyManager
           
private  boolean running
           
private  java.lang.String[] scriptsNames
           
private  java.lang.Object shutdownLock
           
private static int SHUTDOWNTIMEOUT
           
protected  boolean shuttingDown
           
private  long startTime
           
protected  TBTermFactory tbfactory
           
private  toolbus.util.collections.ConcurrentHashMap<java.lang.String,ToolDefinition> tooldefs
           
private  IToolExecutorFactory toolExecutorFactory
           
private  ToolInstanceManager toolInstanceManager
           
private  boolean workHasArrived
           
 
Constructor Summary
ToolBus(java.lang.String[] args)
          Constructor with implicit PrintWriter
ToolBus(java.lang.String[] args, java.io.PrintWriter out)
          Constructor with explicit PrintWriter
ToolBus(java.lang.String[] args, java.io.StringWriter out)
          Constructor with explicit StringWriter
 
Method Summary
 ProcessInstance addProcess(ProcessCall call)
          Add a process (as ProcessCall); previous two will become obsolete.
 void addProcessDefinition(ProcessDefinition PD)
          Add a process definition.
 void addToolDefinition(ToolDefinition TD)
          Add a tool definition.
private  void calculateToolSignatures(java.util.List<Atom> atomSignature)
           
 void clearErrorsAndWarnings()
           
 void dumpPerformanceStats()
          Gathers performance statistics and writes them to the console.
 void dumpUnhandledMessages()
          Prints all unhandled messages and queued notes to stderr.
 void error(java.lang.String src, java.lang.String msg)
           
 void execute()
          The ToolBus's main process loop.
 DirectConnectionHandler getDirectConnectionHandler()
           
(package private) static java.lang.String getHostName()
          Networking functions
 java.lang.String[] getIncludedScripts()
           
 MatchStore getMatchStore()
           
 int getPort()
           
 java.io.PrintWriter getPrintWriter()
          Get current PrintWriter.
 ProcessDefinition getProcessDefinition(java.lang.String name, int numberOfActuals)
          Get a process definition by name.
 java.util.List<ProcessDefinition> getProcessDefinitions()
           
 java.util.List<ProcessInstance> getProcesses()
          Get the current list of processes.
 java.lang.String getProperty(java.lang.String p)
          Getters and setters for global properties
 java.lang.String getProperty(java.lang.String p, java.lang.String def)
           
 long getRunTime()
           
 TBTermFactory getTBTermFactory()
          Get the ATermFactory used.
 ToolDefinition getToolDefinition(java.lang.String name)
          Get a tool definition by name.
 java.util.List<ToolDefinition> getToolDefinitions()
           
 IToolExecutorFactory getToolExecutorFactory()
           
 ToolInstanceManager getToolInstanceManager()
           
 void parsecup()
           
 void parsecup1(java.util.HashSet<java.lang.String> includedFiles, java.util.List<aterm.ATerm> toolbusProcessCalls, java.lang.String filename)
          Parse a Tscript from file and add definitions to this ToolBus.
 void prepare()
           
 void setNextTime(long next)
          Notifies the ToolBus that an atom with a delay on it, which could not be executed, has just been touched.
 void setProperty(java.lang.String key, java.lang.String val)
           
 void setToolExecutorFactory(IToolExecutorFactory toolExecutorFactory)
           
 void showStatus()
          Dumps the current state of all the processes in the ToolBus and the state of all the tools to stderr.
 void shutdown(aterm.ATerm msg)
          Shutdown of this ToolBus.
 void waitTillShutdown()
           
 void workArrived(ToolInstance toolInstance, byte operation)
          Notifies the ToolBus that work has arrived.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHUTDOWNTIMEOUT

private static final int SHUTDOWNTIMEOUT
See Also:
Constant Field Values

propertyManager

protected final PropertyManager propertyManager

portNumber

protected volatile int portNumber

tbfactory

protected final TBTermFactory tbfactory

processes

protected final java.util.List<ProcessInstance> processes

processIdCounter

private int processIdCounter

procdefs

private final toolbus.util.collections.ConcurrentHashMap<java.lang.String,ProcessDefinition> procdefs

matchStore

protected final MatchStore matchStore

tooldefs

private final toolbus.util.collections.ConcurrentHashMap<java.lang.String,ToolDefinition> tooldefs

toolInstanceManager

private final ToolInstanceManager toolInstanceManager

toolExecutorFactory

private volatile IToolExecutorFactory toolExecutorFactory

connectionHandler

protected volatile SocketConnectionHandler connectionHandler

directConnectionHandler

private final DirectConnectionHandler directConnectionHandler

out

private final java.io.PrintWriter out

nerrors

protected int nerrors

startTime

private long startTime

nextTime

private long nextTime

shuttingDown

protected volatile boolean shuttingDown

scriptsNames

private volatile java.lang.String[] scriptsNames

shutdownLock

private final java.lang.Object shutdownLock

running

private volatile boolean running

processLock

private final java.lang.Object processLock

workHasArrived

private volatile boolean workHasArrived
Constructor Detail

ToolBus

public ToolBus(java.lang.String[] args,
               java.io.PrintWriter out)
Constructor with explicit PrintWriter

Throws:
ToolBusError

ToolBus

public ToolBus(java.lang.String[] args)
Constructor with implicit PrintWriter

Throws:
ToolBusError

ToolBus

public ToolBus(java.lang.String[] args,
               java.io.StringWriter out)
Constructor with explicit StringWriter

Throws:
ToolBusError
Method Detail

getMatchStore

public MatchStore getMatchStore()

getToolInstanceManager

public ToolInstanceManager getToolInstanceManager()

setToolExecutorFactory

public void setToolExecutorFactory(IToolExecutorFactory toolExecutorFactory)

getToolExecutorFactory

public IToolExecutorFactory getToolExecutorFactory()

getDirectConnectionHandler

public DirectConnectionHandler getDirectConnectionHandler()

getProperty

public java.lang.String getProperty(java.lang.String p)
Getters and setters for global properties


getProperty

public java.lang.String getProperty(java.lang.String p,
                                    java.lang.String def)

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String val)

getHostName

static java.lang.String getHostName()
Networking functions


getPort

public int getPort()

getTBTermFactory

public TBTermFactory getTBTermFactory()
Get the ATermFactory used.


getProcesses

public java.util.List<ProcessInstance> getProcesses()
Get the current list of processes.


getPrintWriter

public java.io.PrintWriter getPrintWriter()
Get current PrintWriter.


error

public void error(java.lang.String src,
                  java.lang.String msg)

clearErrorsAndWarnings

public void clearErrorsAndWarnings()

getRunTime

public long getRunTime()

setNextTime

public void setNextTime(long next)
Notifies the ToolBus that an atom with a delay on it, which could not be executed, has just been touched.

Parameters:
next - The relative time in milliseconds that needs to elapse before the atom can be executed.

parsecup1

public void parsecup1(java.util.HashSet<java.lang.String> includedFiles,
                      java.util.List<aterm.ATerm> toolbusProcessCalls,
                      java.lang.String filename)
               throws ToolBusException
Parse a Tscript from file and add definitions to this ToolBus.

Throws:
ToolBusException

parsecup

public void parsecup()
              throws ToolBusException
Throws:
ToolBusException

addProcessDefinition

public void addProcessDefinition(ProcessDefinition PD)
                          throws ToolBusError
Add a process definition.

Throws:
ToolBusError

addToolDefinition

public void addToolDefinition(ToolDefinition TD)
                       throws ToolBusError
Add a tool definition.

Throws:
ToolBusError

getToolDefinition

public ToolDefinition getToolDefinition(java.lang.String name)
                                 throws ToolBusError
Get a tool definition by name.

Throws:
ToolBusError

getToolDefinitions

public java.util.List<ToolDefinition> getToolDefinitions()

calculateToolSignatures

private void calculateToolSignatures(java.util.List<Atom> atomSignature)

addProcess

public ProcessInstance addProcess(ProcessCall call)
                           throws ToolBusException
Add a process (as ProcessCall); previous two will become obsolete.

Throws:
ToolBusException

getProcessDefinitions

public java.util.List<ProcessDefinition> getProcessDefinitions()

getProcessDefinition

public ProcessDefinition getProcessDefinition(java.lang.String name,
                                              int numberOfActuals)
                                       throws ToolBusError
Get a process definition by name.

Parameters:
numberOfActuals - TODO
Throws:
ToolBusError

getIncludedScripts

public java.lang.String[] getIncludedScripts()

showStatus

public void showStatus()
Dumps the current state of all the processes in the ToolBus and the state of all the tools to stderr.


shutdown

public void shutdown(aterm.ATerm msg)
Shutdown of this ToolBus.


dumpPerformanceStats

public void dumpPerformanceStats()
Gathers performance statistics and writes them to the console.


dumpUnhandledMessages

public void dumpUnhandledMessages()
Prints all unhandled messages and queued notes to stderr.


prepare

public void prepare()

execute

public void execute()
The ToolBus's main process loop. This method handles the execution of the process logic.


workArrived

public void workArrived(ToolInstance toolInstance,
                        byte operation)
Notifies the ToolBus that work has arrived. This will wake the ToolBus's process loop up if it's currently sleeping.

Parameters:
toolInstance - The tool instance associated with the tool that send us data.
operation - The operation associated with the package that arrived.

waitTillShutdown

public void waitTillShutdown()

The Meta-Environment API