Package ptolemy.actor.lib.aspect
Class AtomicExecutionAspect
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.aspect.AtomicExecutionAspect
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,ActorExecutionAspect
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
DynamicCoreAssignmentScheduler
,FCFSScheduler
,FixedPriorityScheduler
public class AtomicExecutionAspect extends TypedAtomicActor implements ActorExecutionAspect
This is a base class for resource schedulers. This is aDecorator
that will decorate any instance ofActor
that is deeply contained by its container, including within opaque composites. This base class provides one decorator attributes. When you create an instance of this class in a composite actor, every Actor within that composite actor is decorated with these this parameter:- enable: If true, then the decorated actor will use this resource. This is a boolean that defaults to false.
- PtidesDirector. A ExecutionAspect on a PtidesPlatform will cause the platform time at which actors produce their outputs to be delayed by the specified execution time beyond the platform time at which the resource becomes available to execute the actor.
- DEDirector. Note that using a ExecutionAspect in a DE model will change the MoC and nondeterminism is introduced with ExecutionAspects.
- SDF Director, if contained hierarchically directly or via multiple hierarchy layers by a PtidesDirector.
- SysMLSequentialDirector, if contained hierarchically directly or via multiple hierarchy layers by a PtidesDirector.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Patricia Derler, Edward A. Lee
- Pt.AcceptedRating:
- Red (derler)
- Pt.ProposedRating:
- Red (derler)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<NamedObj>
_actors
Actors decorated by this aspect.protected java.util.List<ExecutionAspectListener>
_executionAspectListeners
Listeners that want to be informed about rescheduling events.protected boolean
_lastActorFinished
True if in the last request to schedule an actor, this actor finished execution.protected NamedObj
_lastActorThatFinished
Last actor that finished execution.protected java.util.HashMap<NamedObj,Time>
_lastTimeScheduled
The last time an actor's remaining time was updated due to a scheduling request.protected java.util.HashMap<NamedObj,Time>
_remainingTimes
The remaining execution time for every actor that has been scheduled or null if the actor execution finished.-
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 AtomicExecutionAspect(CompositeEntity container, java.lang.String name)
Create a new resource schedule in the specified container with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Time
_getDeadline(Actor actor, Time timestamp)
Get the deadline for an actor that requests a firing at time timestamp.void
addExecutingListener(ExecutionAspectListener listener)
Add schedule listener.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 resource scheduler.void
fire()
Perform rescheduling if necessary.double
getExecutionTime(NamedObj actor)
Get the execution time of an actor.Time
getRemainingTime(NamedObj actor)
Return remaining time actor needs to finish.Time
getTime(double time)
Return a new time object using the enclosing director.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.protected boolean
lastActorFinished()
Return whether last actor that was scheduled finished execution.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 schedule listeners about rescheduling events.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 environmentTime, Time deadline, Time executionTime)
Schedule the actor.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
wrapup()
Create end events for the plotter.-
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, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, 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, 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
-
_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.
-
_lastActorThatFinished
protected NamedObj _lastActorThatFinished
Last actor that finished execution.
-
_lastTimeScheduled
protected java.util.HashMap<NamedObj,Time> _lastTimeScheduled
The last time an actor's remaining time was updated due to a scheduling request.
-
_remainingTimes
protected java.util.HashMap<NamedObj,Time> _remainingTimes
The remaining execution time for every actor that has been scheduled or null if the actor execution finished.
-
_executionAspectListeners
protected java.util.List<ExecutionAspectListener> _executionAspectListeners
Listeners that want to be informed about rescheduling events.
-
-
Constructor Detail
-
AtomicExecutionAspect
public AtomicExecutionAspect(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Create a new resource schedule 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 resource scheduler.- 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 resource scheduler.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- 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)
-
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 resource scheduler.- Specified by:
decoratedObjects
in interfaceDecorator
- Returns:
- A list of the objects decorated by this decorator.
-
fire
public void fire() throws IllegalActionException
Perform rescheduling if necessary.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown here.
-
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.
-
getRemainingTime
public Time getRemainingTime(NamedObj actor)
Return remaining time actor needs to finish.- Parameters:
actor
- The actor.- Returns:
- The time the actor still needs.
-
getTime
public Time getTime(double time) throws IllegalActionException
Return a new time object using the enclosing director.- Parameters:
time
- Double value of the new time object.- Returns:
- The new time object.
- Throws:
IllegalActionException
- If the time object cannot be created.
-
initialize
public void initialize() throws IllegalActionException
Initialize local variables.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Thrown if list of actors scheduled by this scheduler 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 schedule 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.
-
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 classAtomicActor<TypedIOPort>
- 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()
-
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 Scheduler has to be executed again to perform rescheduling actions.
- Throws:
IllegalActionException
- Thrown in subclasses.
-
schedule
public Time schedule(NamedObj actor, Time environmentTime, Time deadline, Time executionTime) throws IllegalActionException
Schedule the actor. In this base class, do nothing. Derived classes should schedule the actor.- Specified by:
schedule
in interfaceActorExecutionAspect
- Parameters:
actor
- The actor to be scheduled.environmentTime
- The current platform time.deadline
- The deadline timestamp of the event to be scheduled. This can be the same as the environmentTime.executionTime
- The execution time of the actor.- Returns:
- Relative time when this Scheduler has to be executed again to perform rescheduling actions. In this base class, null is returned.
- Throws:
IllegalActionException
- Thrown if actor parameters such as execution time or priority cannot be read.
-
removeExecutionListener
public void removeExecutionListener(ExecutionAspectListener listener)
Remove schedule listener.- Specified by:
removeExecutionListener
in interfaceActorExecutionAspect
- Parameters:
listener
- The listener to be removed.
-
wrapup
public void wrapup() throws IllegalActionException
Create end events for the plotter.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Thrown by super class.
-
_getDeadline
protected Time _getDeadline(Actor actor, Time timestamp) throws IllegalActionException
Get the deadline for an actor that requests a firing at time timestamp. This base class just returns the maximum value.- Parameters:
actor
- The actor that requests firing.timestamp
- The time when the actor wants to be fired.- Returns:
- The deadline for the actor.
- Throws:
IllegalActionException
- If time objects cannot be created.
-
lastActorFinished
protected boolean lastActorFinished()
Return whether last actor that was scheduled finished execution.- Returns:
- True if last actor finished execution.
-
-