ptolemy.moml
Class MoMLSimpleApplication

java.lang.Object
  extended by ptolemy.moml.MoMLSimpleApplication
All Implemented Interfaces:
ExecutionListener, ChangeListener
Direct Known Subclasses:
MoMLCommandLineApplication, MoMLSimpleApplication, MoMLSimpleStatisticalApplication

public class MoMLSimpleApplication
extends java.lang.Object
implements ChangeListener, ExecutionListener

A simple application that reads in a .xml file as a command line argument and runs it.

MoMLApplication sets the look and feel, which starts up Swing, so we can't use MoMLApplication for non-graphical simulations.

We implement the ChangeListener interface so that this class will get exceptions thrown by failed change requests. For example to use this class, try:

 java -classpath $PTII ptolemy.actor.gui.MoMLSimpleApplication ../../../ptolemy/domains/sdf/demo/OrthogonalCom/OrthogonalCom.xml
 

Since:
Ptolemy II 8.0
Version:
$Id: MoMLSimpleApplication.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Christopher Hylands
Accepted Rating:
Red (eal)
Proposed Rating:
Red (cxh)

Field Summary
protected  int _activeCount
          The count of currently executing runs.
protected  boolean _executionFinishedOrError
          A flag that indicates if the execution has finished or thrown an error.
protected  Manager _manager
          The manager of this model.
protected  java.lang.Throwable _sawThrowable
          The exception seen by executionError().
 
Constructor Summary
MoMLSimpleApplication()
          A Nullary constructor is necessary so that we can extends this base class with a subclass.
MoMLSimpleApplication(java.lang.String xmlFileName)
          Parse the xml file and run it.
 
Method Summary
 void changeExecuted(ChangeRequest change)
          React to a change request has been successfully executed by doing nothing.
 void changeFailed(ChangeRequest change, java.lang.Exception exception)
          React to a change request that has resulted in an exception.
 void executionError(Manager manager, java.lang.Throwable throwable)
          Report an execution failure.
 void executionFinished(Manager manager)
          Report that the current execution has finished and the wrapup sequence has completed normally.
static void main(java.lang.String[] args)
          Create an instance of a single model and run it.
 void managerStateChanged(Manager manager)
          Report that the manager has changed state.
 void rerun()
          Execute the same model again.
 void waitForFinish()
          Wait for all executing runs to finish, then return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_activeCount

protected volatile int _activeCount
The count of currently executing runs.


_manager

protected Manager _manager
The manager of this model.


_sawThrowable

protected volatile java.lang.Throwable _sawThrowable
The exception seen by executionError().


_executionFinishedOrError

protected volatile boolean _executionFinishedOrError
A flag that indicates if the execution has finished or thrown an error. The code busy waits until executionFinished() or executionError() is called. If this variable is true and _sawThrowable is null then executionFinished() was called. If this variable is true and _sawThrowable is non-null then executionError() was called.

Constructor Detail

MoMLSimpleApplication

public MoMLSimpleApplication()
                      throws java.lang.Exception
A Nullary constructor is necessary so that we can extends this base class with a subclass.

Throws:
java.lang.Exception - Not thrown in this base class

MoMLSimpleApplication

public MoMLSimpleApplication(java.lang.String xmlFileName)
                      throws java.lang.Throwable
Parse the xml file and run it.

Parameters:
xmlFileName - A string that refers to an MoML file that contains a Ptolemy II model. The string should be a relative pathname.
Throws:
java.lang.Throwable - If there was a problem parsing or running the model.
Method Detail

changeExecuted

public void changeExecuted(ChangeRequest change)
React to a change request has been successfully executed by doing nothing. This method is called after a change request has been executed successfully. In this class, we do nothing.

Specified by:
changeExecuted in interface ChangeListener
Parameters:
change - The change that has been executed, or null if the change was not done via a ChangeRequest.

changeFailed

public void changeFailed(ChangeRequest change,
                         java.lang.Exception exception)
React to a change request that has resulted in an exception. This method is called after a change request was executed, but during the execution in an exception was thrown. This method throws a runtime exception with a description of the original exception.

Specified by:
changeFailed in interface ChangeListener
Parameters:
change - The change that was attempted or null if the change was not done via a ChangeRequest.
exception - The exception that resulted.

executionError

public void executionError(Manager manager,
                           java.lang.Throwable throwable)
Report an execution failure. This method will be called when an exception or error is caught by a manager. Exceptions are reported this way when the run() or startRun() methods of the manager are used to perform the execution. If instead the execute() method is used, then exceptions are not caught, and are instead just passed up to the caller of the execute() method. Those exceptions are not reported here (unless, of course, the caller of the execute() method does so). In this class, we set a flag indicating that execution has finished.

Specified by:
executionError in interface ExecutionListener
Parameters:
manager - The manager controlling the execution.
throwable - The throwable to report.

executionFinished

public void executionFinished(Manager manager)
Report that the current execution has finished and the wrapup sequence has completed normally. The number of successfully completed iterations can be obtained by calling getIterationCount() on the manager. In this class, we set a flag indicating that execution has finished.

Specified by:
executionFinished in interface ExecutionListener
Parameters:
manager - The manager controlling the execution.

managerStateChanged

public void managerStateChanged(Manager manager)
Report that the manager has changed state. To access the new state, use the getState() method of Manager. In this class, do nothing.

Specified by:
managerStateChanged in interface ExecutionListener
Parameters:
manager - The manager controlling the execution.
See Also:
Manager.getState()

main

public static void main(java.lang.String[] args)
Create an instance of a single model and run it.

Parameters:
args - The command-line arguments naming the .xml file to run

rerun

public void rerun()
           throws java.lang.Exception
Execute the same model again.

Throws:
java.lang.Exception - if there was a problem rerunning the model.

waitForFinish

public void waitForFinish()
Wait for all executing runs to finish, then return.