Package ptolemy.moml
Class MoMLSimpleApplication
- java.lang.Object
-
- ptolemy.moml.MoMLSimpleApplication
-
- All Implemented Interfaces:
ExecutionListener
,ChangeListener
- Direct Known Subclasses:
MoMLCommandLineApplication
,MoMLSimpleApplication
,MoMLSimpleStatisticalApplication
,MoMLSimpleTimeoutApplication
,Rerun
,UnloadModelTest
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$
- Author:
- Christopher Hylands
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Red (cxh)
-
-
Field Summary
Fields Modifier and Type Field Description 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 MoMLParser
_parser
The MoMLParser used to parse the model.protected java.lang.Throwable
_sawThrowable
The exception seen by executionError().protected CompositeActor
_toplevel
The toplevel model that is created and then destroyed.protected Workspace
_workspace
The workspace in which the model and Manager are created.
-
Constructor Summary
Constructors Constructor Description MoMLSimpleApplication()
Instantiate a MoMLSimpleApplication.MoMLSimpleApplication(java.lang.String xmlFileName)
Parse the xml file and run it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
cleanup()
Clean up by freeing memory.static void
closeVertx()
If the VertxHelperBase class is present, then invoke the closeVertx() method so that this process does not wait around for the Vert.x threads.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 each model file named in the arguments and run it.void
managerStateChanged(Manager manager)
Report that the manager has changed state.void
rerun()
Execute the same model again.CompositeActor
toplevel()
Return the toplevel.void
waitForFinish()
Wait for all executing runs to finish, then return.
-
-
-
Field Detail
-
_activeCount
protected volatile int _activeCount
The count of currently executing runs.
-
_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.
-
_manager
protected Manager _manager
The manager of this model.
-
_parser
protected volatile MoMLParser _parser
The MoMLParser used to parse the model.
-
_sawThrowable
protected volatile java.lang.Throwable _sawThrowable
The exception seen by executionError().
-
_toplevel
protected volatile CompositeActor _toplevel
The toplevel model that is created and then destroyed.
-
_workspace
protected volatile Workspace _workspace
The workspace in which the model and Manager are created.
-
-
Constructor Detail
-
MoMLSimpleApplication
public MoMLSimpleApplication() throws java.lang.Exception
Instantiate a MoMLSimpleApplication. This constructor is probably not useful by itself, it is for use by subclasses.The HandSimDroid work in $PTII/ptserver uses dependency injection to determine which implementation actors such as Const and Display to use. This method reads the ptolemy/actor/ActorModule.properties file.
- 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 interfaceChangeListener
- 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 interfaceChangeListener
- Parameters:
change
- The change that was attempted or null if the change was not done via a ChangeRequest.exception
- The exception that resulted.
-
cleanup
public void cleanup()
Clean up by freeing memory. After calling cleanup(), do not call rerun().
-
closeVertx
public static void closeVertx()
If the VertxHelperBase class is present, then invoke the closeVertx() method so that this process does not wait around for the Vert.x threads.
-
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 interfaceExecutionListener
- 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 interfaceExecutionListener
- 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 interfaceExecutionListener
- Parameters:
manager
- The manager controlling the execution.- See Also:
Manager.getState()
-
main
public static void main(java.lang.String[] args)
Create an instance of each model file named in the arguments and run it.- Parameters:
args
- The command-line arguments naming the Ptolemy II model files (typically .xml files) to be invoked.
-
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.
-
toplevel
public CompositeActor toplevel()
Return the toplevel.- Returns:
- The toplevel
-
waitForFinish
public void waitForFinish()
Wait for all executing runs to finish, then return.
-
-