Class CompositeActorSimpleApplication

  • Direct Known Subclasses:
    CompositeActorApplication

    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:

     java -classpath $PTII ptolemy.actor.gui.CompositeActorSimpleApplication \
     -director.iterations 1000 \
     -class ptolemy.actor.gui.test.TestModel
     

    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$
    Author:
    Christopher Brooks
    See Also:
    CompositeActorApplication
    Pt.AcceptedRating:
    Red (vogel)
    Pt.ProposedRating:
    Red (cxh)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      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.
      protected java.util.List<CompositeActor> _models
      The list of all the models.
      protected int _openCount
      The count of currently open windows.
      protected static boolean _test
      If true, then auto exit after a few seconds.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 static void _run​(CompositeActorSimpleApplication application, java.lang.String[] args)
      Run the application.
      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.
      java.util.List<CompositeActor> models()
      Return the list of models.
      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.
      java.lang.Object 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<CompositeActor> _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.
    • 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.
      • models

        public java.util.List<CompositeActor> models()
        Return the list of models.
        Returns:
        The list of models passed in as 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 java.lang.Object 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.
        Returns:
        Always returns null.
        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:
        • If the argument is "-class", then attempt to interpret the next argument as the fully qualified classname of a class to instantiate as a ptolemy model. The model will be created, added to the directory of models, and then executed.
        • If the argument is "-help", then print a help message.
        • If the argument is "-test", then set a flag that will abort execution of any created models after two seconds.
        • If the argument is "-version", then print a short version message.
        • If the argument is "", then ignore it.
        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.
      • _run

        protected static void _run​(CompositeActorSimpleApplication application,
                                   java.lang.String[] args)
        Run the application.
        Parameters:
        application - The application.
        args - The arguments to be passed to the application.
      • _usage

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