Package ptolemy.cg.lib
Class CompiledCompositeActor
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
EmbeddedCodeActor
public class CompiledCompositeActor extends TypedCompositeActor
A composite actor that can be optionally code generated and then invoked via reflection.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Gang Zhou, contributors: Christopher Brooks, Edward A. Lee, Bert Rodiers, Dai Bui
- Pt.AcceptedRating:
- red (zgang)
- Pt.ProposedRating:
- red (zgang)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description FileParameter
codeDirectory
The directory in which to put the generated code.Parameter
executeEmbeddedCode
If true, then invoke the generated code in the action methods (fire(), etc.).StringParameter
generatorPackage
The name of the package in which to look for adapter class code generators.Parameter
inline
If true, generate file with no functions.Parameter
overwriteFiles
If true, overwrite preexisting files.-
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _derivedPiggybacks, _initializables, _notifyingActorFiring, _piggybacks, _publishedPorts, _publisherRelations, _stopRequested, _subscribedPorts
-
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
-
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 CompiledCompositeActor()
Construct a CodeGenerationCompositeActor in the default workspace with no container and an empty string as its name.CompiledCompositeActor(CompositeEntity container, java.lang.String name)
Create an actor with a name and a container.CompiledCompositeActor(Workspace workspace)
Construct a CodeGenerationCompositeActor in the specified workspace with no container and an empty string as a name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_compileJNICode()
Compile the Java code.protected void
_generateAndCompileEmbeddedCode()
Generate and compile Java code.protected void
_generateAndCompileJNICode()
Generate and compile the JNI code.protected static void
_transferOutputs(TypedCompositeActor compositeActor, IOPort port, java.lang.Object outputTokens)
Transfer the outputs.void
fire()
If executeEmbeddedCode is true, then execute the fire() method of the generated code.java.lang.String
getSanitizedName()
Return the sanitized file name of this actor.void
initialize()
If executeEmbeddedCode is true, then generate and compile the code (if necessary), and then execute the initialize() method of the generated code.void
wrapup()
If executeEmbeddedCode is true, then execute the wrapup() method of the generated code.-
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeChanged, attributeTypeChanged, isBackwardTypeInferenceEnabled, newPort, newRelation, resolveTypes, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, createReceivers, createSchedule, getCausalityInterface, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort
-
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _exportMoMLContents, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, clone, 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, 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, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
codeDirectory
public FileParameter codeDirectory
The directory in which to put the generated code. This is a file parameter that must specify a directory. The default is $HOME/cg.
-
generatorPackage
public StringParameter generatorPackage
The name of the package in which to look for adapter class code generators. This is a string that defaults to "generic.program.procedural.java"
-
inline
public Parameter inline
If true, generate file with no functions. If false, generate file with functions. The default value is a parameter with the value true.
-
executeEmbeddedCode
public Parameter executeEmbeddedCode
If true, then invoke the generated code in the action methods (fire(), etc.). If the value is false, this actor will be executed executing like an ordinary composite actor. Classes like EmbeddedJavaActor set embedded to true when there is only Java code specifying the functionality of an actor.
-
overwriteFiles
public Parameter overwriteFiles
If true, overwrite preexisting files. The default value is a parameter with the value true.
-
-
Constructor Detail
-
CompiledCompositeActor
public CompiledCompositeActor()
Construct a CodeGenerationCompositeActor in the default workspace with no container and an empty string as its name. Add the actor to the workspace directory. You should set a director before attempting to execute it. You should set the container before sending data to it. Increment the version number of the workspace.
-
CompiledCompositeActor
public CompiledCompositeActor(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Create an actor with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace. This actor will have no local director initially, and its executive director will be simply the director of the container. You should set a director before attempting to execute it.- Parameters:
container
- The container actor.name
- The name of this actor.- Throws:
IllegalActionException
- If the container is incompatible with this actor.NameDuplicationException
- If the name coincides with an actor already in the container.
-
CompiledCompositeActor
public CompiledCompositeActor(Workspace workspace)
Construct a CodeGenerationCompositeActor in the specified workspace with no container and an empty string as a name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace. You should set a director before attempting to execute it. You should set the container before sending data to it. Increment the version number of the workspace.- Parameters:
workspace
- The workspace that will list the actor.
-
-
Method Detail
-
fire
public void fire() throws IllegalActionException
If executeEmbeddedCode is true, then execute the fire() method of the generated code. Otherwise, delegate to the superclass, which executes this actor like an ordinary composite actor.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classCompositeActor
- Throws:
IllegalActionException
- If thrown by the super class, or if there are problems invoking the fire() method of wrapper class.
-
getSanitizedName
public java.lang.String getSanitizedName()
Return the sanitized file name of this actor. The sanitized name is created by invokingStringUtilities.sanitizeName(String)
, removing underscores and appending a version number. The version number is necessary so that we can reload the shared object.- Returns:
- The sanitized actor name.
-
initialize
public void initialize() throws IllegalActionException
If executeEmbeddedCode is true, then generate and compile the code (if necessary), and then execute the initialize() method of the generated code. Otherwise, delegate to the superclass, which initializes this actor like an ordinary composite actor.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classCompositeActor
- Throws:
IllegalActionException
- If there is no director, or if the director's initialize() method throws it, or if the actor is not opaque.
-
wrapup
public void wrapup() throws IllegalActionException
If executeEmbeddedCode is true, then execute the wrapup() method of the generated code. Otherwise, delegate to the superclass, which executes this actor like an ordinary composite actor.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classCompositeActor
- Throws:
IllegalActionException
- If there is no director, or if the director's wrapup() method throws it, or if this actor is not opaque.
-
_compileJNICode
protected void _compileJNICode() throws IllegalActionException
Compile the Java code. Thejavac
andjavah
commands are executed on the the java file.- Throws:
IllegalActionException
- If there is a problem reading the codeDirectory parameter.
-
_generateAndCompileEmbeddedCode
protected void _generateAndCompileEmbeddedCode() throws IllegalActionException
Generate and compile Java code.- Throws:
IllegalActionException
- If the adapter class cannot be found, or if the static generateCode(TypedCompositeActor) method in the adapter class cannot be found or invoked.
-
_generateAndCompileJNICode
protected void _generateAndCompileJNICode() throws IllegalActionException
Generate and compile the JNI code.- Throws:
IllegalActionException
- If thrown while getting the path to the shared object, while writing the Java file, or while compiling the Java file.
-
_transferOutputs
protected static void _transferOutputs(TypedCompositeActor compositeActor, IOPort port, java.lang.Object outputTokens) throws IllegalActionException
Transfer the outputs.- Parameters:
compositeActor
- The composite actor transferring the outputs.port
- The port on which the output is to be transferredoutputTokens
- The tokens to be transferred.- Throws:
IllegalActionException
- If there are problems getting the class or otherwise transferring the tokens.
-
-