lbnl.actor.lib
Class SystemCommand

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by lbnl.actor.lib.SystemCommand
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class SystemCommand
extends TypedAtomicActor

Actor that calls a system command. This actor fires a system command that is defined by the parameter programName with arguments programArguments. It waits unit the command terminates. The output of the actor are the exit flag, the standard output and standard error of the command

The parameters programName and programArguments can have references to the port name that will be replaced by the token value of the respective port. For example, a user may add an input port called inPort and enter as the programArguments the string 1 $inPort 3. Then, if at the current firing, the input port is inPort=2, then the program argument will be 1 2 3. In addition to port names, you can also use the variable $time and $iteration, which will be replaced by the current simulation time and the iteration count. To use this class, instantiate it, then add ports (instances of TypedIOPort). In vergil, you can add ports by right clicking on the icon and selecting "Configure Ports". In MoML you can add ports by just including ports of class TypedIOPort, set to be inputs, as in the following example:

 <entity name="exp" class="lbnl.actor.lib.SystemCommand">
 <port name="in" class="ptolemy.actor.TypedIOPort">
 <property name="input"/>
 </port>
 </entity>
 

Since:
Ptolemy II 8.0
Version:
$Id: SystemCommand.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Michael Wetter
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  int _iterationCount
           
private  java.util.HashMap<java.lang.String,Token> _tokenMap
           
protected  ClientProcess cliPro
          Thread that runs the simulation.
protected  java.util.ArrayList<java.lang.String> commandList
          List with the command and the arguments.
 TypedIOPort error
          The port that outputs the standard error stream of the program.
 TypedIOPort exitValue
          The port that outputs the exit value of the program.
protected  boolean isHeadless
          Flag, set the true if Ptolemy is run without any graphical interface If isHeadless=true, this actor will not open any windows for reporting outputs or warnings.
private static java.lang.String LS
          System dependent line separator
 TypedIOPort output
          The port that outputs the standard output stream of the program.
protected  Parameter programArguments
          Arguments of program that starts the simulation.
 FileParameter programName
          Name of program that starts the simulation.
 Parameter showConsoleWindow
          If true (the default), a window will be created that shows the console output.
 FileParameter simulationLogFile
          File name to which this actor writes the simulation log.
protected  java.lang.String worDir
          Working directory of the subprocess.
 FileParameter workingDirectory
          Working directory of the simulation.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
SystemCommand(CompositeEntity container, java.lang.String name)
          Constructs an actor with the given container and name.
 
Method Summary
private  void _initializeSimulation()
          Initializes the simulation program.
private  void _startSimulation()
          Starts the simulation program.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
static java.lang.String cutQuotationMarks(java.lang.String str)
          Cut the leading and terminating quotation marks if present.
 void fire()
          Read the input token, update the program name and program arguments, start the program and wait unit it terminates.
 void initialize()
          Initialize actor.
 boolean postfire()
          Increment the iteration count.
 boolean prefire()
          Prefire this actor.
 void preinitialize()
          Initializes the data members and checks if the parameters of the actor are valid.
 void wrapup()
          Wraps up the base class.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

output

public TypedIOPort output
The port that outputs the standard output stream of the program.


error

public TypedIOPort error
The port that outputs the standard error stream of the program.


exitValue

public TypedIOPort exitValue
The port that outputs the exit value of the program.


programName

public FileParameter programName
Name of program that starts the simulation.


simulationLogFile

public FileParameter simulationLogFile
File name to which this actor writes the simulation log.


workingDirectory

public FileParameter workingDirectory
Working directory of the simulation.


showConsoleWindow

public Parameter showConsoleWindow
If true (the default), a window will be created that shows the console output.


programArguments

protected Parameter programArguments
Arguments of program that starts the simulation.


cliPro

protected ClientProcess cliPro
Thread that runs the simulation.


commandList

protected java.util.ArrayList<java.lang.String> commandList
List with the command and the arguments. This list is stored as it may contain references to input ports that will be substituted prior to the simulation


worDir

protected java.lang.String worDir
Working directory of the subprocess.


isHeadless

protected boolean isHeadless
Flag, set the true if Ptolemy is run without any graphical interface If isHeadless=true, this actor will not open any windows for reporting outputs or warnings.


_iterationCount

private int _iterationCount

_tokenMap

private java.util.HashMap<java.lang.String,Token> _tokenMap

LS

private static final java.lang.String LS
System dependent line separator

Constructor Detail

SystemCommand

public SystemCommand(CompositeEntity container,
                     java.lang.String name)
              throws NameDuplicationException,
                     IllegalActionException
Constructs an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the init and step public members to the parameters of the new actor.

Overrides:
clone in class AtomicActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Read the input token, update the program name and program arguments, start the program and wait unit it terminates. Then, send the program's exit value, the standard output and the standard error stream to the output ports.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - Not thrown in this base class.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Initializes the data members and checks if the parameters of the actor are valid.

Specified by:
preinitialize in interface Initializable
Overrides:
preinitialize in class AtomicActor
Throws:
IllegalActionException - If the parameters of the actor are invalid.

_initializeSimulation

private void _initializeSimulation()
                            throws IllegalActionException
Initializes the simulation program.

Throws:
IllegalActionException - If the simulation process arguments are invalid.

_startSimulation

private void _startSimulation()
                       throws IllegalActionException
Starts the simulation program.

Throws:
IllegalActionException - If the simulation process arguments are invalid.

initialize

public void initialize()
                throws IllegalActionException
Initialize actor.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it.

postfire

public boolean postfire()
                 throws IllegalActionException
Increment the iteration count.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If the superclass throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Prefire this actor. Return false if an input port has no data, otherwise return true.

Specified by:
prefire in interface Executable
Overrides:
prefire in class AtomicActor
Returns:
True if this actor is ready for firing, false otherwise.
Throws:
IllegalActionException - If the superclass throws it.

wrapup

public void wrapup()
            throws IllegalActionException
Wraps up the base class.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class AtomicActor
Throws:
IllegalActionException - if the base class throws it.

cutQuotationMarks

public static java.lang.String cutQuotationMarks(java.lang.String str)
Cut the leading and terminating quotation marks if present.

Parameters:
str - The string.
Returns:
The string with leading and terminating quotation marks removed if present