Package ptolemy.domains.metroII.kernel
Class MetroIIDEDirectorForPtides
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.domains.de.kernel.DEDirector
-
- ptolemy.domains.metroII.kernel.MetroIIDEDirectorForPtides
-
- All Implemented Interfaces:
java.lang.Cloneable
,Executable
,Initializable
,SuperdenseTimeDirector
,GetFirable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
MetroIIPtidesDirector
public abstract class MetroIIDEDirectorForPtides extends DEDirector implements GetFirable
MetroIIDEDirectorForPtides is an intermediate class for MetroIIPtidesDirector to extend. MetroIIPtidesDirector cannot extend PtidesDirector because the super class DEDirector does not support MetroII semantics. We choose to not extend MetroIIDEDirector either, because all the actors under MetroIIPtidesDirector can be considered as MetroII actors. The assumption greatly simplifies the implementation.MetroIIDEDirectorForPtides is a much simpler version of MetroIIDEDirector with the assumption that all the actors are MetroII actors.
- Since:
- Ptolemy II 11.0
- Version:
- $Id: MetroIIDEDirectorForPtides.java 67634 2013-10-03 17:12:51Z glp$
- Author:
- Liangpeng Guo
- Pt.AcceptedRating:
- Red (glp)
- Pt.ProposedRating:
- Red (glp)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetroIIDEDirectorForPtides.Pair<F,S>
Pair is a data structure used to store two elements.-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Hashtable<java.lang.String,FireMachine>
_actorDictionary
The list of actors governed by MetroIIDEDirector.protected java.util.ArrayList<PtidesEvent>
_eventList
The list of Ptides events that are currently being processed.Parameter
printTrace
Option parameter whether trace info is printed out.-
Fields inherited from class ptolemy.domains.de.kernel.DEDirector
_actorsFinished, _actorsInExecution, _disabledActors, _eventQueue, _eventQueueLock, _isInitializing, _microstep, _noMoreActorsToFire, _stopFireRequested, binCountFactor, enforceMicrostepSemantics, isCQAdaptive, minBinCount, stopWhenQueueIsEmpty, synchronizeToRealTime
-
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
-
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 MetroIIDEDirectorForPtides(CompositeEntity container, java.lang.String name)
Constructs a director in the given container with the given name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected MetroIIDEDirectorForPtides.Pair<PtidesEvent,java.lang.Integer>
_checkNextEventToFire()
_checkNextEventToFire finds the next Ptides event to fire and returns it with an integer indicating: 0 if firing can be executed, and the next event in event queue should be checked for processing; -1 if there's no actor to fire, and we should not keep firing; 1 if there's no actor to fire, but the next event should be checked for processing.protected abstract PtidesEvent
_getNextEventToFire()
Ptides director need to provide the implementation.protected abstract void
_resetLogicalTime()
Reset the logical time.protected abstract void
_setLogicalTime(PtidesEvent ptidesEvent)
Ptides director need to provide the implementation.net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>>
adapter()
Since the MetroIIDEDirectorForPtides is always used inside a MetroIICompositeActor, the adapter() in MetroIICompositeActor is responsible for creating the iterator of getfire(), this adapter() should never be called.java.lang.Object
clone(Workspace workspace)
Clones the object into the specified workspace.void
getfire(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler)
Fires actors according to Ptides events in the event queue.void
initialize()
Initializes the model controlled by this director.void
stop()
Requests the execution of the current iteration to stop.-
Methods inherited from class ptolemy.domains.de.kernel.DEDirector
_actorFired, _checkForNextEvent, _disableActor, _enqueueEvent, _enqueueTriggerEvent, _fire, _getDepthOfActor, _getDepthOfIOPort, _getNextActorToFire, _issueExecutionAspectWarning, _noActorToFire, _requestFiring, _schedule, addDebugListener, attributeChanged, cancelFireAt, cancelFireAt, describePriorities, fire, fireAt, fireAt, fireAtCurrentTime, fireAtRelativeTime, getCausalityInterface, getIndex, getMicrostep, getModelNextIterationTime, getNextEventTime, getStartTime, getStopTime, invalidateSchedule, mutexLockObject, newReceiver, postfire, prefire, preinitialize, removeDebugListener, resumeActor, setIndex, stopFire, suggestedModalModelDirectors, transferInputs, wrapup
-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, finish, fireAt, fireContainerAt, fireContainerAt, getCurrentTime, getDeadline, getEnvironmentTime, getExecutionAspect, getGlobalTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getTimeResolution, implementsStrictActorSemantics, initialize, invalidateResolvedTypes, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, notifyTokenSentToCommunicationAspect, preinitialize, removeInitializable, requestInitialization, resume, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, supportMultirateFiring, suspend, terminate, transferOutputs, transferOutputs
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
printTrace
public Parameter printTrace
Option parameter whether trace info is printed out.
-
_actorDictionary
protected java.util.Hashtable<java.lang.String,FireMachine> _actorDictionary
The list of actors governed by MetroIIDEDirector.
-
_eventList
protected java.util.ArrayList<PtidesEvent> _eventList
The list of Ptides events that are currently being processed.
-
-
Constructor Detail
-
MetroIIDEDirectorForPtides
public MetroIIDEDirectorForPtides(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Constructs a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.- Parameters:
container
- Container of the director.name
- Name of this director.- Throws:
IllegalActionException
- If the director is not compatible with the specified container. May be thrown in a derived class.NameDuplicationException
- If the container is not a CompositeActor and the name collides with an entity in the container.
-
-
Method Detail
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clones the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there).- Overrides:
clone
in classDEDirector
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- The new Attribute.
- Throws:
java.lang.CloneNotSupportedException
- Not thrown in this base class- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
initialize
public void initialize() throws IllegalActionException
Initializes the model controlled by this director. Call the initialize() of super class and then wrap each actor that is controlled by this director.This method should typically be invoked once per execution, after the preinitialization phase, but before any iteration. It may be invoked in the middle of an execution, if reinitialization is desired.
This method is not synchronized on the workspace, so the caller should be.
- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classDEDirector
- Throws:
IllegalActionException
- If the initialize() method of one of the associated actors throws it.
-
stop
public void stop()
Requests the execution of the current iteration to stop. This is similar to stopFire(), except that the current iteration is not allowed to complete.- Specified by:
stop
in interfaceExecutable
- Overrides:
stop
in classDEDirector
-
_checkNextEventToFire
protected MetroIIDEDirectorForPtides.Pair<PtidesEvent,java.lang.Integer> _checkNextEventToFire() throws IllegalActionException
_checkNextEventToFire finds the next Ptides event to fire and returns it with an integer indicating: 0 if firing can be executed, and the next event in event queue should be checked for processing; -1 if there's no actor to fire, and we should not keep firing; 1 if there's no actor to fire, but the next event should be checked for processing.- Returns:
- A pair of elements in which the first one is Ptides event safe to be processed, the second one is the state indicating: 0 if firing can be executed, and the next event in event queue should be checked for processing; -1 if there's no actor to fire, and we should not keep firing; 1 if there's no actor to fire, but the next event should be checked for processing.
- Throws:
IllegalActionException
- If the firing actor throws it, or event queue is not ready, or an event is missed, or time is set backwards.
-
getfire
public void getfire(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler) throws net.jimblackler.Utils.CollectionAbortedException, IllegalActionException
Fires actors according to Ptides events in the event queue. Whether the actual firing of an actor can be done also depend on the MetroII events associated with the actor if the actor is a MetroII actor. Only when the associated MetroII event is NOTIFIED, the firing can be executed. Once a MetroII event is executed, we check again if there are any more events could be executed. getfire() starts with looking at all the Ptides events that are ready to be processed. For each actor that is ready to fire, the startOrResume() interface is called, which in turns calls the getfire() of the actor. These calls to startOrResume() (yields) returns with the MetroII events that are PROPOSED. This getfire() 'yield returns' with all these PROPOSED MetroII events. The getfire() normally exits when no more actors proposing MetroII events.- Specified by:
getfire
in interfaceGetFirable
- Parameters:
resultHandler
- iterable of events 'yield returned'.- Throws:
IllegalActionException
- If we couldn't process an event or if an event of smaller timestamp is found within the event queue.net.jimblackler.Utils.CollectionAbortedException
-
adapter
public net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>> adapter()
Since the MetroIIDEDirectorForPtides is always used inside a MetroIICompositeActor, the adapter() in MetroIICompositeActor is responsible for creating the iterator of getfire(), this adapter() should never be called.- Specified by:
adapter
in interfaceGetFirable
- Returns:
- iterator
-
_getNextEventToFire
protected abstract PtidesEvent _getNextEventToFire() throws IllegalActionException
Ptides director need to provide the implementation.- Returns:
- Ptides event that is safe to process
- Throws:
IllegalActionException
-
_setLogicalTime
protected abstract void _setLogicalTime(PtidesEvent ptidesEvent)
Ptides director need to provide the implementation.- Parameters:
ptidesEvent
- Ptides event the logical time is set to.
-
_resetLogicalTime
protected abstract void _resetLogicalTime()
Reset the logical time.
-
-