ptolemy.actor.gui
Class CompositeActorSimpleApplication

java.lang.Object
  extended by ptolemy.actor.gui.CompositeActorSimpleApplication

public class CompositeActorSimpleApplication
extends java.lang.Object

This application creates one or more Ptolemy II models given a classname on the command line, and then executes those models, each in its own thread. Each specified class should be derived from CompositeActor, and should have a constructor that takes a single argument, an instance of Workspace. If the model does not contain a manager, then one will be created for it. The model is not displayed, models that have actors that extend Placeable should instead use CompositeActorApplication.

The command-line arguments can also set parameter values for any parameter in the models, with the name given relative to the top-level entity. For example, to specify the iteration count in an SDF model, you can invoke this on the command line as follows:

 CLASSPATH=$PTII
 export CLASSPATH
 java ptolemy.actor.gui.CompositeActorSimpleApplication \
 -director.iterations 1000 \
 -class ptolemy.domains.sdf.demo.Butterfly.Butterfly
 
This assumes that the model given by the specified class name has a director named "director" with a parameter named "iterations". If more than one model is given on the command line, then the parameter values will be set for all models that have such a parameter.

Since:
Ptolemy II 4.1
Version:
$Id: CompositeActorSimpleApplication.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Christopher Brooks
See Also:
CompositeActorApplication
Accepted Rating:
Red (vogel)
Proposed Rating:
Red (cxh)

Field Summary
protected  java.lang.String[] _commandFlags
          The command-line options that are either present or not.
protected  java.lang.String[][] _commandOptions
          The command-line options that take arguments.
protected  java.lang.String _commandTemplate
          The form of the command line.
private  boolean _expectingClass
           
protected  java.util.List _models
          The list of all the models.
protected  int _openCount
          The count of currently open windows.
private  java.util.List _parameterNames
           
private  java.util.List _parameterValues
           
protected static boolean _test
          If true, then auto exit after a few seconds.
 
Constructor Summary
CompositeActorSimpleApplication()
           
 
Method Summary
protected  boolean _parseArg(java.lang.String arg)
          Parse a command-line argument.
protected  void _parseArgs(java.lang.String[] args)
          Parse the command-line arguments.
protected  java.lang.String _usage()
          Return a string summarizing the command-line arguments.
static void main(java.lang.String[] args)
          Create a new application with the specified command-line arguments.
 void processArgs(java.lang.String[] args)
          Parse the command-line arguments, creating models as specified.
 void report(java.lang.Exception ex)
          Report an exception.
 void report(java.lang.String message)
          Report a message to the user.
 void report(java.lang.String message, java.lang.Exception ex)
          Report an exception with an additional message.
 void startRun(CompositeActor model)
          If the specified model has a manager and is not already running, then execute the model in a new thread.
 void stopRun(CompositeActor model)
          If the specified model has a manager and is executing, then stop execution by calling the stop() method of the manager.
 void waitForFinish()
          Wait for all windows to close.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_commandFlags

protected java.lang.String[] _commandFlags
The command-line options that are either present or not.


_commandOptions

protected java.lang.String[][] _commandOptions
The command-line options that take arguments.


_commandTemplate

protected java.lang.String _commandTemplate
The form of the command line.


_models

protected java.util.List _models
The list of all the models.


_openCount

protected int _openCount
The count of currently open windows.


_test

protected static boolean _test
If true, then auto exit after a few seconds.


_expectingClass

private boolean _expectingClass

_parameterNames

private java.util.List _parameterNames

_parameterValues

private java.util.List _parameterValues
Constructor Detail

CompositeActorSimpleApplication

public CompositeActorSimpleApplication()
Method Detail

main

public static void main(java.lang.String[] args)
Create a new application with the specified command-line arguments.

Parameters:
args - The command-line arguments.

processArgs

public void processArgs(java.lang.String[] args)
                 throws java.lang.Exception
Parse the command-line arguments, creating models as specified.

Parameters:
args - The command-line arguments.
Throws:
java.lang.Exception - If something goes wrong.

report

public void report(java.lang.Exception ex)
Report an exception. This prints a message to the standard error stream, followed by the stack trace.

Parameters:
ex - The exception to report.

report

public void report(java.lang.String message)
Report a message to the user. This prints a message to the standard output stream.

Parameters:
message - The message to report.

report

public void report(java.lang.String message,
                   java.lang.Exception ex)
Report an exception with an additional message. This prints a message to standard error, followed by the stack trace.

Parameters:
message - The message.
ex - The exception to report.

startRun

public void startRun(CompositeActor model)
              throws IllegalActionException
If the specified model has a manager and is not already running, then execute the model in a new thread. Otherwise, do nothing. If the model contains an atomic entity that implements Placeable, we create create an instance of ModelFrame, if nothing implements Placeable, then we do not create an instance of ModelFrame. This allows us to run non-graphical models on systems that do not have a display.

We then start the model running.

Parameters:
model - The model to execute.
Throws:
IllegalActionException - If the model contains Placeables. or does not have a manager.
See Also:
Manager.startRun()

stopRun

public void stopRun(CompositeActor model)
If the specified model has a manager and is executing, then stop execution by calling the stop() method of the manager. If there is no manager, do nothing.

Parameters:
model - The model to stop.

waitForFinish

public void waitForFinish()
Wait for all windows to close.


_parseArg

protected boolean _parseArg(java.lang.String arg)
                     throws java.lang.Exception
Parse a command-line argument. The recognized arguments, which result in this method returning true, are summarized below: Otherwise, the argument is ignored and false is returned.

Parameters:
arg - The argument to be parse.
Returns:
True if the argument is understood, false otherwise.
Throws:
java.lang.Exception - If something goes wrong.

_parseArgs

protected void _parseArgs(java.lang.String[] args)
                   throws java.lang.Exception
Parse the command-line arguments.

Parameters:
args - The arguments to be parsed.
Throws:
java.lang.Exception - If an argument is not understood or triggers an error.

_usage

protected java.lang.String _usage()
Return a string summarizing the command-line arguments.

Returns:
A usage string.