public class Simulator extends SDFTransformer
programName with arguments programArguments.
It then initiates a socket connection and uses the socket to
exchange data with the external simulation program each time
the actor is fired.Entity.ContainedObjectsIterator| Modifier and Type | Field and Description |
|---|---|
protected boolean |
clientTerminated
Flag, set to true when the clients terminates the communication.
|
protected ClientProcess |
cliPro
Thread that runs the simulation.
|
protected double[] |
dblWri
Double values that were written to the socket.
|
protected boolean |
firstFire
Flag that is true during the first firing of this actor/.
|
protected boolean |
isHeadless
Flag, set the
true if Ptolemy is run without any graphical
interface. |
protected static java.lang.String |
LS
System dependent line separator.
|
protected DoubleMatrixToken |
outTok
Output tokens.
|
protected int |
porNo
Port number that is actually used for BSD socket.
|
Parameter |
programArguments
Arguments of program that starts the simulation.
|
FileParameter |
programName
Name of program that starts the simulation.
|
protected Server |
server
Server used for data exchange.
|
Parameter |
showConsoleWindow
If true (the default), a window will be created that
shows the console output.
|
protected double |
simTimPre
Ptolemy's time at the last call of the fire method.
|
protected double |
simTimReaPre
Time read from the simulation program at the last call of the fire method.
|
FileParameter |
simulationLogFile
File name to which this actor writes the simulation log.
|
FileParameter |
socketConfigurationFile
File name to which this actor writes the socket configuration.
|
Parameter |
socketPortNumber
Port number for BSD socket (used if non-negative).
|
Parameter |
socketTimeout
Socket time out in milliseconds.
|
protected java.lang.String |
terminationMessage
Message that will be displayed in the warning window when the client terminated,
but Ptolemy continues with the simulation.
|
protected double |
tokTim
Time of token that will be written to the client.
|
protected java.lang.Thread |
warWin
Thread that is used if a warning window need to be shown.
|
protected java.lang.String |
worDir
Working directory of the subprocess.
|
FileParameter |
workingDirectory
Working directory of the simulation.
|
input, input_tokenConsumptionRate, output, output_tokenInitProduction, output_tokenProductionRate_typesValid_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKSCOMPLETED, NOT_READY, STOP_ITERATING| Constructor and Description |
|---|
Simulator(CompositeEntity container,
java.lang.String name)
Constructs an actor with the given container and name.
|
| Modifier and Type | Method and Description |
|---|---|
protected double[] |
_getDoubleArray(Token t)
Get a double array from the Token.
|
protected void |
_outputInitToken()
Output the first token during initialize.
|
protected void |
_readFromServer()
Read the data from the server instance, which will read it
from the client program.
|
protected void |
_startSimulation()
Start the simulation program.
|
protected void |
_writeToServer()
Write the data to the server instance, which will send it to
the client 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()
Send the input token to the client program and send the
output from the client program to the output port.
|
void |
initialize()
Initialize state variables.
|
void |
preinitialize()
Initializes the data members and checks if the parameters of
the actor are valid.
|
static java.lang.String |
resolveCommandName(java.io.File programName)
Resolve the command string.
|
static java.lang.String |
resolveDirectory(NamedObj namedObj,
java.lang.String dir)
Resolve the working string.
|
void |
wrapup()
Closes sockets and shuts down the simulator.
|
prefire_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition_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, workspaceequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcreateReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortListisFireFunctional, isStrict, iterate, postfire, stop, stopFire, terminateaddInitializable, removeInitializabledescription, getContainer, getDisplayName, getFullName, getName, getName, setNamegetDerivedLevel, getDerivedList, propagateValuepublic Parameter programArguments
public FileParameter programName
public Parameter socketPortNumber
public FileParameter simulationLogFile
public FileParameter socketConfigurationFile
public Parameter socketTimeout
public FileParameter workingDirectory
public Parameter showConsoleWindow
protected double[] dblWri
protected ClientProcess cliPro
protected int porNo
protected Server server
protected java.lang.String worDir
protected DoubleMatrixToken outTok
protected double simTimPre
protected double simTimReaPre
protected boolean clientTerminated
protected java.lang.Thread warWin
protected java.lang.String terminationMessage
protected boolean isHeadless
true if Ptolemy is run without any graphical
interface.
If isHeadless=true, this actor will not open any windows for
reporting outputs or warnings.protected boolean firstFire
protected static final java.lang.String LS
protected double tokTim
public Simulator(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container - The container.name - The name of this actor.IllegalActionException - If the actor cannot be contained
by the proposed container.NameDuplicationException - If the container already has an
actor with this name.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
init and step
public members to the parameters of the new actor.clone in class TypedAtomicActorworkspace - The workspace for the new object.java.lang.CloneNotSupportedException - If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String),
NamedObj.setDeferringChangeRequests(boolean)public void fire()
throws IllegalActionException
fire in interface Executablefire in class AtomicActor<TypedIOPort>IllegalActionException - If the simulation time between Ptolemy
and the client program is not synchronized.protected void _outputInitToken()
throws IllegalActionException
IllegalActionExceptionprotected void _writeToServer()
throws IllegalActionException
IllegalActionException - If there was an error when
writing to the server.protected void _readFromServer()
throws IllegalActionException
IllegalActionException - If there was an error when
reading from the server.public void preinitialize()
throws IllegalActionException
preinitialize in interface Initializablepreinitialize in class AtomicActor<TypedIOPort>IllegalActionException - If the parameters of the
actor are invalid, or if the file with the socket
information cannot be written to disk.public static java.lang.String resolveCommandName(java.io.File programName)
throws IllegalActionException
programName - Name of program that starts the simulation.IllegalActionException - If the simulation process arguments
are invalid.public static java.lang.String resolveDirectory(NamedObj namedObj, java.lang.String dir) throws IllegalActionException
namedObj - A named object, typically the container of the modeldir - The directory to be resolved.IllegalActionException - If an attribute is found with the name "_uri"
that is not an instance of the URIAttribute classprotected void _startSimulation()
throws IllegalActionException
IllegalActionException - If the simulation process arguments
are invalid.public void initialize()
throws IllegalActionException
initialize in interface Initializableinitialize in class AtomicActor<TypedIOPort>IllegalActionException - If the parent class throws it or
if the server socket cannot be openedpublic void wrapup()
throws IllegalActionException
wrapup in interface Initializablewrapup in class AtomicActor<TypedIOPort>IllegalActionException - if the base class throws it or
if an I/O error occurs when closing the socket.public static java.lang.String cutQuotationMarks(java.lang.String str)
str - The string.protected double[] _getDoubleArray(Token t) throws IllegalActionException
t - the token which must be a type that can be converted to an ArrayTokenIllegalActionException - If the base class throws it.