Class SystemCommand
- java.lang.Object
-
- All Implemented Interfaces:
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 parameterprogramName
with argumentsprogramArguments
. It waits unit the command terminates. The output of the actor are the exit flag, the standard output and standard error of the commandThe parameters
programName
andprogramArguments
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 calledinPort
and enter as theprogramArguments
the string1 $inPort 3
. Then, if at the current firing, the input port isinPort=2
, then the program argument will be1 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$
- Author:
- Michael Wetter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description 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 thetrue
if Ptolemy is run without any graphical interface IfisHeadless=true
, this actor will not open any windows for reporting outputs or warnings.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.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description SystemCommand(CompositeEntity container, java.lang.String name)
Constructs an actor with the given container and name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, 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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
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
-
-
-
-
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 thetrue
if Ptolemy is run without any graphical interface IfisHeadless=true
, this actor will not open any windows for reporting outputs or warnings.
-
-
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 theinit
andstep
public members to the parameters of the new actor.- Overrides:
clone
in classTypedAtomicActor
- 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 interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- 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 interfaceInitializable
- Overrides:
preinitialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the parameters of the actor are invalid.
-
initialize
public void initialize() throws IllegalActionException
Initialize actor.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the parent class throws it.
-
postfire
public boolean postfire() throws IllegalActionException
Increment the iteration count.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- 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 interfaceExecutable
- Overrides:
prefire
in classAtomicActor<TypedIOPort>
- 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 interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- 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
-
-