Class TimedPNDirector
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Executable
,Initializable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class TimedPNDirector extends PNDirector
A TimedPNDirector governs the execution of a CompositeActor with Kahn-MacQueen process networks (PN) semantics extended by introduction of a notion of global time.The thread that calls the various execution methods (initialize, prefire, fire and postfire) on the director is referred to as the directing thread. This directing thread might be the main thread responsible for the execution of the entire simulation or might be the thread created by the executive director of the containing composite actor.
In the PN domain, the director creates a thread (an instance of ProcessThread), representing a Kahn process, for each actor in the model. The threads are created in initialize() and started in the prefire() method of the ProcessDirector. A process is considered active from its creation until its termination. An active process can block when trying to read from a channel (read-blocked), when trying to write to a channel (write-blocked), or when waiting for time to progress (time-blocked). Time can progress for an active process in this model of computation only when the process is blocked.
A deadlock is when all the active processes are blocked. The director is responsible for handling deadlocks during execution. This director handles three different sorts of deadlocks, real deadlock, timed deadlock and artificial deadlock.
A real deadlock is when all the processes are blocked on a read meaning that no process can proceed until it receives new data. The execution can be terminated, if desired, in such a situation. If the container of this director does not have any input ports (as is in the case of a top-level composite actor), then the executive director or manager terminates the execution. If the container has input ports, then it is up to the executive director of the container to decide on the termination of the execution. To terminate the execution after detection of a real deadlock, the manager or the executive director calls wrapup() on the director.
An artificial deadlock is when all processes are blocked and at least one process is blocked on a write. In this case the director increases the capacity of the receiver with the smallest capacity amongst all the receivers on which a process is blocked on a write. This breaks the deadlock and the execution can proceed.
A timed deadlock is when all the processes under the control of this director are blocked, at least one process is blocked on a delay (time-blocked) and no process is blocked on a write. This director supports a notion of global time. All active processes that are not blocked and are executing concurrently are executing at the same global time. A process that wants time to advance, suspends itself by calling the fireAt() method of the director and specifies the time it wants to be awakened at. Time can advance only when a timed deadlock occurs. In such a case, the director advances time to the time when the first timed-blocked process can be awakened.
- Since:
- Ptolemy II 0.2
- Version:
- $Id$
- Author:
- Mudit Goel
- Pt.AcceptedRating:
- Green (davisj)
- Pt.ProposedRating:
- Green (mudit)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected int
_delayBlockCount
The number of time-blocked processes.protected CalendarQueue
_eventQueue
The priority queue that stores the list of processes waiting for time to advance.-
Fields inherited from class ptolemy.domains.pn.kernel.PNDirector
_readBlockedQueues, _receivers, _writeBlockedQueues, initialQueueCapacity, maximumQueueCapacity, READ_BLOCKED, WRITE_BLOCKED
-
Fields inherited from class ptolemy.actor.process.ProcessDirector
_newActorThreadList, _notDone
-
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 TimedPNDirector()
Construct a director in the default workspace with an empty string as its name.TimedPNDirector(CompositeEntity container, java.lang.String name)
Construct a director in the given container with the given name.TimedPNDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_areThreadsDeadlocked()
Return true if a deadlock is detected.protected void
_informOfDelayBlock()
Increment by 1 the count of actors waiting for the time to advance.protected void
_informOfDelayUnblock()
Decrease by 1 the count of processes blocked on a delay.protected boolean
_resolveDeadlock()
Return false on detection of a real deadlock.java.lang.Object
clone(Workspace workspace)
Clone the director into the specified workspace.Time
fireAt(Actor actor, Time newFiringTime, int microstep)
Suspend the calling process until the time has advanced to at least the time specified by the method argument.void
setModelTime(Time newTime)
Set a new value to the current time of the model, where the new time must be no earlier than the current time.void
wrapup()
Reset private variables.-
Methods inherited from class ptolemy.domains.pn.kernel.PNDirector
_incrementLowestWriteCapacityPort, _resolveInternalDeadlock, addProcessListener, initialize, newReceiver, postfire, preinitialize, removeProcessListener, suggestedModalModelDirectors, supportMultirateFiring, threadBlocked, threadUnblocked
-
Methods inherited from class ptolemy.actor.process.CompositeProcessDirector
_areActorsExternallyBlocked, _controllerBlocked, _controllerUnBlocked, _isInputControllerBlocked, _isOutputControllerBlocked, createBranchController, getInputController, getOutputController, prefire, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked
-
Methods inherited from class ptolemy.actor.process.ProcessDirector
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, _requestFinishOnReceivers, addThread, finish, fire, initialize, isStopFireRequested, isThreadActive, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs
-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getExecutionAspect, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, invalidateResolvedTypes, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, notifyTokenSentToCommunicationAspect, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setTimeResolution, suspend, 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, addDebugListener, 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, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
_eventQueue
protected CalendarQueue _eventQueue
The priority queue that stores the list of processes waiting for time to advance. These processes are sorted by the time they want to resume at.
-
_delayBlockCount
protected int _delayBlockCount
The number of time-blocked processes.
-
-
Constructor Detail
-
TimedPNDirector
public TimedPNDirector() throws IllegalActionException, NameDuplicationException
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace. Create a director parameter "initialQueueCapacity" with the default value 1. This sets the initial capacities of the FIFO queues in all the receivers created in the PN domain.- Throws:
IllegalActionException
- If the name has a period in it, or the director is not compatible with the specified container.NameDuplicationException
- If the container already contains an entity with the specified name.
-
TimedPNDirector
public TimedPNDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
Construct a director in the workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace. Create a director parameter "initialQueueCapacity" with the default value 1. This sets the initial capacities of the queues in all the receivers created in the PN domain.- Parameters:
workspace
- The workspace of this object.- Throws:
IllegalActionException
- If the name has a period in it, or the director is not compatible with the specified container.NameDuplicationException
- If the container already contains an entity with the specified name.
-
TimedPNDirector
public TimedPNDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a director in the given container with the given name. If 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. Create a director parameter "initialQueueCapacity" with the default value 1. This sets the initial capacities of the queues in all the receivers created in the PN domain.- 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 derived classes.NameDuplicationException
- If the container 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
Clone the director into the specified workspace. The new object is not added to the directory of that workspace (It must be added by the user if he wants it to be there). The result is a new director with no container and no topology listeners. The count of active processes is zero. The parameter "initialQueueCapacity" has the same value as the director being cloned.- Overrides:
clone
in classPNDirector
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- The new TimedPNDirector.
- Throws:
java.lang.CloneNotSupportedException
- If one of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fireAt
public Time fireAt(Actor actor, Time newFiringTime, int microstep) throws IllegalActionException
Suspend the calling process until the time has advanced to at least the time specified by the method argument. Add the actor corresponding to the calling process to the priority queue and sort it by the time specified by the method argument. Increment the count of the actors blocked on a delay. Suspend the calling process until the time has advanced to at least the time specified by the method argument. Resume the execution of the calling process and return.- Overrides:
fireAt
in classDirector
- Parameters:
actor
- The actor scheduled to be fired.newFiringTime
- The scheduled time.microstep
- The microstep (ignored by this director).- Returns:
- the value of the newFiringTime argument.
- Throws:
IllegalActionException
- If the operation is not permissible (e.g. the given time is in the past).- See Also:
Director.fireAtCurrentTime(Actor)
,Director.fireContainerAt(Time)
-
setModelTime
public void setModelTime(Time newTime) throws IllegalActionException
Set a new value to the current time of the model, where the new time must be no earlier than the current time.- Overrides:
setModelTime
in classDirector
- Parameters:
newTime
- The new time of the model.- Throws:
IllegalActionException
- If an attempt is made to change the time to less than the current time.- See Also:
Director.getModelTime()
-
wrapup
public void wrapup() throws IllegalActionException
Reset private variables. added 7/15/08 Patricia Derler- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classCompositeProcessDirector
- Throws:
IllegalActionException
- If an error occurs while accessing the receivers of all actors under the control of this director.
-
_areThreadsDeadlocked
protected boolean _areThreadsDeadlocked()
Return true if a deadlock is detected. Return false otherwise. Return true if all the active processes in the container are either read-blocked, write-blocked or delay-blocked.- Overrides:
_areThreadsDeadlocked
in classCompositeProcessDirector
- Returns:
- true if a deadlock is detected.
-
_informOfDelayBlock
protected void _informOfDelayBlock()
Increment by 1 the count of actors waiting for the time to advance. Check for a resultant deadlock or pausing of the execution. If either of them is detected, then notify the directing thread of the same.
-
_informOfDelayUnblock
protected void _informOfDelayUnblock()
Decrease by 1 the count of processes blocked on a delay.
-
_resolveDeadlock
protected boolean _resolveDeadlock() throws IllegalActionException
Return false on detection of a real deadlock. Otherwise break the deadlock and return true. On detection of a timed deadlock, advance time to the earliest time that a delayed process is waiting for, wake up all the actors waiting for time to advance to the new time, and remove them from the priority queue. This method is synchronized on the director.- Overrides:
_resolveDeadlock
in classCompositeProcessDirector
- Returns:
- true if a real deadlock is detected, false otherwise.
- Throws:
IllegalActionException
- Not thrown in this base class. This might be thrown by derived classes.
-
-