Package ptolemy.actor.lib.aspect
Class CompositeExecutionAspect
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity
-
- ptolemy.kernel.CompositeEntity
-
- ptolemy.actor.CompositeActor
-
- ptolemy.actor.TypedCompositeActor
-
- ptolemy.actor.lib.aspect.CompositeExecutionAspect
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,ActorExecutionAspect
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class CompositeExecutionAspect extends TypedCompositeActor implements ActorExecutionAspect
This is a composite execution aspect. Actors decorated by this aspect also specify a requestPort. A record token with the actor and its execution time is created on this requestPort whenever the director wants to schedule the actor. When this token is received by a ResourceMappingOutputport inside this CompositeExecutionAspect, the director is informed that the actor can now fire.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Patricia Derler
- Pt.AcceptedRating:
- Red (derler)
- Pt.ProposedRating:
- Red (derler)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompositeExecutionAspect.CompositeExecutionAspectAttributes
Attributes for actors decorated by this CompositeExecutionAspects.-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<NamedObj>
_actors
Actors decorated by this aspect.protected java.util.List<NamedObj>
_currentlyExecuting
List of currently executing actors.protected java.util.List<ExecutionAspectListener>
_executionAspectListeners
Listeners that want to be informed about execution events.protected boolean
_lastActorFinished
True if in the last request to schedule an actor, this actor finished execution.Parameter
justMonitor
This parameter indicates whether the tokens received via the ImmediateReceivers are immediately forwarded to the wrapped receivers or whether they are delayed by this communication aspect and only forwarded through a CommunicationResponsePort.-
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 CompositeExecutionAspect(CompositeEntity container, java.lang.String name)
Create a new actor in the specified container with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExecutingListener(ExecutionAspectListener listener)
Add schedule listener.void
attributeChanged(Attribute attribute)
React to the change of the justMonitor attribute by updating internal variables.java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.DecoratorAttributes
createDecoratorAttributes(NamedObj target)
Return the decorated attributes for the target NamedObj.java.util.List<NamedObj>
decoratedObjects()
Return a list of the entities deeply contained by the container of this ExecutionAspect.double
getExecutionTime(NamedObj actor)
Get the execution time of an actor.void
initialize()
Initialize local variables.void
initializeDecoratedActors()
Iterate through all entities deeply contained by the container, record for each that it is not executing.boolean
isGlobalDecorator()
Return true to indicate that this decorator should decorate objects across opaque hierarchy boundaries.boolean
isWaitingForResource(Actor actor)
Check whether the execution of an actor is handled by this aspect actor.boolean
lastScheduledActorFinished()
If the last actor that was scheduled finished execution then this method returns true.void
notifyExecutionListeners(NamedObj entity, java.lang.Double time, ExecutionAspectListener.ExecutionEventType eventType)
Notify execution listeners about rescheduling events.boolean
postfire()
Iterate through resource mapping output ports and if they contain tokens, inform the director of the actors in the tokens that these actors can resume execution.void
removeExecutionListener(ExecutionAspectListener listener)
Remove schedule listener.Time
schedule(Time environmentTime)
Perform rescheduling actions when no new actor requests to be scheduled.Time
schedule(NamedObj actor, Time currentPlatformTime, Time deadline, Time executionTime)
Schedule a new actor for execution.void
setContainer(CompositeEntity container)
Override the base class to first set the container, then establish a connection with any decorated objects it finds in scope in the new container.void
setRequestPort(NamedObj actor, java.lang.String portName)
Set the name of the port that will receive scheduling requests for the actor.-
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newPort, newRelation, resolveTypes, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, fire, 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, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort, wrapup
-
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
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
justMonitor
public Parameter justMonitor
This parameter indicates whether the tokens received via the ImmediateReceivers are immediately forwarded to the wrapped receivers or whether they are delayed by this communication aspect and only forwarded through a CommunicationResponsePort. This parameter is a boolean that defaults to false.
-
_actors
protected java.util.List<NamedObj> _actors
Actors decorated by this aspect.
-
_lastActorFinished
protected boolean _lastActorFinished
True if in the last request to schedule an actor, this actor finished execution.
-
_executionAspectListeners
protected java.util.List<ExecutionAspectListener> _executionAspectListeners
Listeners that want to be informed about execution events.
-
_currentlyExecuting
protected java.util.List<NamedObj> _currentlyExecuting
List of currently executing actors.
-
-
Constructor Detail
-
CompositeExecutionAspect
public CompositeExecutionAspect(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Create a new actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.- Parameters:
container
- The container.name
- The name of this actor within the container.- Throws:
IllegalActionException
- If this actor cannot be contained by the proposed container (see the setContainer() method).NameDuplicationException
- If the name coincides with an entity already in the container.
-
-
Method Detail
-
addExecutingListener
public void addExecutingListener(ExecutionAspectListener listener) throws IllegalActionException
Add schedule listener. If necessary, initialize list of actors scheduled by this ExecutionAspect.- Specified by:
addExecutingListener
in interfaceActorExecutionAspect
- Parameters:
listener
- The listener to be added.- Throws:
IllegalActionException
- If an error occurs in the initialization of actors scheduled by this ExecutionAspect.
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
React to the change of the justMonitor attribute by updating internal variables.- Overrides:
attributeChanged
in classTypedCompositeActor
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If token in attribute cannot be accessed.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- Overrides:
clone
in classCompositeActor
- 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)
-
createDecoratorAttributes
public DecoratorAttributes createDecoratorAttributes(NamedObj target)
Return the decorated attributes for the target NamedObj. If the specified target is not an Actor, return null.- Specified by:
createDecoratorAttributes
in interfaceDecorator
- Parameters:
target
- The NamedObj that will be decorated.- Returns:
- The decorated attributes for the target NamedObj, or null if the specified target is not an Actor.
-
decoratedObjects
public java.util.List<NamedObj> decoratedObjects()
Return a list of the entities deeply contained by the container of this ExecutionAspect.- Specified by:
decoratedObjects
in interfaceDecorator
- Returns:
- A list of the objects decorated by this decorator.
-
getExecutionTime
public double getExecutionTime(NamedObj actor) throws IllegalActionException
Get the execution time of an actor. If the actor does not have an attribute specifying the execution time, return the minimum execution time.- Specified by:
getExecutionTime
in interfaceActorExecutionAspect
- Parameters:
actor
- The actor.- Returns:
- The execution time.
- Throws:
IllegalActionException
- Thrown in attribute or token cannot be read.
-
initialize
public void initialize() throws IllegalActionException
Initialize local variables.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classCompositeActor
- Throws:
IllegalActionException
- Thrown if list of actors decorated by this aspect cannot be retrieved.
-
initializeDecoratedActors
public void initializeDecoratedActors() throws IllegalActionException
Iterate through all entities deeply contained by the container, record for each that it is not executing.- Specified by:
initializeDecoratedActors
in interfaceActorExecutionAspect
- Throws:
IllegalActionException
- If the decorator parameters cannot be read.
-
isGlobalDecorator
public boolean isGlobalDecorator()
Return true to indicate that this decorator should decorate objects across opaque hierarchy boundaries.- Specified by:
isGlobalDecorator
in interfaceDecorator
- Returns:
- True if decorator is global.
-
isWaitingForResource
public boolean isWaitingForResource(Actor actor)
Check whether the execution of an actor is handled by this aspect actor.- Specified by:
isWaitingForResource
in interfaceActorExecutionAspect
- Parameters:
actor
- The actor.- Returns:
- True, if the actor execution is handled by this aspect actor.
-
lastScheduledActorFinished
public boolean lastScheduledActorFinished()
If the last actor that was scheduled finished execution then this method returns true.- Specified by:
lastScheduledActorFinished
in interfaceActorExecutionAspect
- Returns:
- True if last actor that was scheduled finished execution.
-
notifyExecutionListeners
public void notifyExecutionListeners(NamedObj entity, java.lang.Double time, ExecutionAspectListener.ExecutionEventType eventType)
Notify execution listeners about rescheduling events.- Specified by:
notifyExecutionListeners
in interfaceActorExecutionAspect
- Parameters:
entity
- Entity that is being scheduled.time
- Time when entity is being scheduled.eventType
- Type of event.
-
postfire
public boolean postfire() throws IllegalActionException
Iterate through resource mapping output ports and if they contain tokens, inform the director of the actors in the tokens that these actors can resume execution.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classCompositeActor
- Returns:
- True if the execution can continue into the next iteration.
- Throws:
IllegalActionException
- Not explicitly thrown here.
-
schedule
public Time schedule(Time environmentTime) throws IllegalActionException
Perform rescheduling actions when no new actor requests to be scheduled.- Specified by:
schedule
in interfaceActorExecutionAspect
- Parameters:
environmentTime
- The outside time.- Returns:
- Relative time when this aspect has to be executed again to perform rescheduling actions.
- Throws:
IllegalActionException
- Thrown in subclasses.
-
schedule
public Time schedule(NamedObj actor, Time currentPlatformTime, Time deadline, Time executionTime) throws IllegalActionException
Schedule a new actor for execution. Find the const actor in the _model that is mapped to this actor and trigger a firing of that one, if the actor is not already in execution. If the actor finished execution, return zero time, otherwise return the next time the model has something to do.- Specified by:
schedule
in interfaceActorExecutionAspect
- Parameters:
actor
- The actor to be scheduled.currentPlatformTime
- The current platform time.deadline
- The deadline of the event.executionTime
- The execution time of the actor.- Returns:
- Relative time when this aspect has to be executed again.
- Throws:
IllegalActionException
- Thrown if actor parameters such as execution time or priority cannot be read.
-
setContainer
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
Override the base class to first set the container, then establish a connection with any decorated objects it finds in scope in the new container.- Overrides:
setContainer
in classCompositeActor
- Parameters:
container
- The container to attach this attribute to..- Throws:
IllegalActionException
- If this attribute is not of the expected class for the container, or it has no name, or the attribute and container are not in the same workspace, or the proposed container would result in recursive containment.NameDuplicationException
- If the container already has an attribute with the name of this attribute.- See Also:
ComponentEntity.getContainer()
-
setRequestPort
public void setRequestPort(NamedObj actor, java.lang.String portName)
Set the name of the port that will receive scheduling requests for the actor.- Parameters:
actor
- The actor.portName
- The request port.
-
removeExecutionListener
public void removeExecutionListener(ExecutionAspectListener listener)
Remove schedule listener.- Specified by:
removeExecutionListener
in interfaceActorExecutionAspect
- Parameters:
listener
- The listener to be removed.
-
-