public class CompositeProcessDirector extends ProcessDirector
A composite process director can be contained by an opaque composite actor that is contained by a composite actor. Ports contained by opaque composite actors are called opaque ports and such ports facilitate data transfer across the composite actor boundaries. A composite process director allocates two branch controllers to monitor data transfer in channels associated with opaque ports. The input branch controller monitors data transfer for channels associated with input opaque ports. The output branch controller monitors data transfer for channels associated with output opaque ports.
Associated with the channels of each opaque port is a pair of process receivers. The producer receiver serves as the channel source and the consumer receiver serves as the channel destination. Each branch controller allocates a branch for each process receiver pair and when executing, a branch repeatedly attempts to transfer a single token from its producer receiver to its consumer receiver.
When a branch blocks while attempting to transfer data, it informs its branch controller by passing the branch controller the blocked receiver. If all of the branches of a controller have blocked, then we say that the branch controller is blocked and the branch controller informs the composite process director. In addition to monitoring the status of its branch controllers, a composite process director keeps track of the state of the actors that it contains. Actors can be internally or externally blocked. We say that an actor is externally blocked if it is blocked waiting to transfer tokens to or from a boundary port of its container actor. Actors that are blocked but not externally are said to be internally blocked.
Composite process directors monitor the state of the branch controllers and contained actors and when necessary invoke the _resolveDeadlock() method to deal with deadlocks. In the remainder of this paragraph we consider the case of a process-oriented opaque composite actor that is contained by another process-oriented opaque composite actor. If the actors contained by the inner composite actor are not blocked, then execution of the inner composite actor is allowed to continue independent of the state of the branch controllers. If the actors contained by the inner composite actor are internally blocked, then after the branch controllers have been deactivated, execution of the composite actor ends and postfire returns false indicating that successive iterations are not allowed. If the actors contained by the inner composite actor are externally blocked, then the composite process director waits until the branch controllers block (an inevitable condition) and registers the block with the containing (outer) composite director of the actor.
In this paragraph we consider the case of a process-oriented opaque composite actor that is contained by a schedule-oriented (non process) opaque composite actor. If the actors contained by the inner composite actor are not blocked, then execution of the inner composite actor is allowed to continue independent of the state of the branch controllers. If the actors contained by the inner composite actor are internally blocked, then after the branch controllers have been deactivated, execution of the composite actor ends and postfire returns false indicating that successive iterations are not allowed. If the actors contained by the inner composite actor are externally blocked, then the composite process director waits until the branch controllers block (an inevitable condition) and ends the iteration with postfire() returning true indicating that successive iterations are allowed.
Director
NamedObj.ContainedObjectsIterator
_newActorThreadList, _notDone
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
CompositeProcessDirector()
Construct a director in the default workspace with an empty
string as its name.
|
CompositeProcessDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
CompositeProcessDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
_areActorsExternallyBlocked()
Return true if one or more contained actor is externally
blocked; return false otherwise.
|
protected boolean |
_areThreadsDeadlocked()
Return false if the number of blocked processes is less than
the number of active actors; return true otherwise.
|
protected void |
_controllerBlocked(BranchController controller)
Register that the specified controller is blocked.
|
protected void |
_controllerUnBlocked(BranchController controller)
Unregister the specified controller as being no longer
blocked.
|
protected boolean |
_isInputControllerBlocked()
Return true if the input controller of this director is
blocked; return false otherwise.
|
protected boolean |
_isOutputControllerBlocked()
Return true if the output controller of this director is
blocked; return false otherwise.
|
protected boolean |
_resolveDeadlock()
Attempt to resolve a deadlock and return true if the deadlock
no longer exists and successive iterations are allowed; if
the deadlock still exists then return false indicating that
future iterations are not allowed.
|
protected boolean |
_resolveInternalDeadlock()
Return false indicating that resolution of an internal
deadlock was unsuccessful and execution should discontinue.
|
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace.
|
void |
createBranchController(java.util.Iterator ports)
Create a input and/or output branch controllers according to
whether the ports passed in as arguments are input or output
ports.
|
BranchController |
getInputController()
Return the input branch controller of this director.
|
BranchController |
getOutputController()
Return the output branch controller of this director.
|
void |
initialize()
Invoke the initialize() methods of all the deeply contained
actors in the container (a composite actor) of this director.
|
Receiver |
newReceiver()
Return a new receiver of a type compatible with this director.
|
boolean |
prefire()
If there are input or output ports, and this is the first iteration,
then start threads to handle the inputs and outputs.
|
void |
stopInputBranchController()
Stop the input branch controller of this director.
|
void |
stopOutputBranchController()
Stop the output branch controller of this director.
|
void |
threadBlocked(java.lang.Thread thread,
ProcessReceiver receiver)
Notify the director that the specified thread is blocked
on an I/O operation.
|
void |
threadUnblocked(java.lang.Thread thread,
ProcessReceiver receiver)
Notify the director that the specified thread is unblocked
on an I/O operation.
|
void |
wrapup()
End the execution of the model under the control of this
director.
|
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, _requestFinishOnReceivers, addThread, finish, fire, initialize, isStopFireRequested, isThreadActive, postfire, preinitialize, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, fireAt, 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, setModelTime, setTimeResolution, suggestedModalModelDirectors, supportMultirateFiring, suspend, transferOutputs
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_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
public CompositeProcessDirector() throws IllegalActionException, NameDuplicationException
NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.public CompositeProcessDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace of this object.NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.public CompositeProcessDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- Name of this director.IllegalActionException
- If the name contains a period,
or if the director is not compatible with the specified container.NameDuplicationException
- If the container not a
CompositeActor and the name collides with an entity in the container.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class ProcessDirector
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- If one of the attributes
cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void createBranchController(java.util.Iterator ports) throws IllegalActionException
ports
- The ports for which branches will be assigned.IllegalActionException
- If any of the ports are
not opaque.public BranchController getInputController()
public BranchController getOutputController()
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method
of one of the deeply contained actors throws it.public Receiver newReceiver()
newReceiver
in class Director
public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class ProcessDirector
IllegalActionException
- If a derived class throws it.public void stopInputBranchController()
public void stopOutputBranchController()
public void threadBlocked(java.lang.Thread thread, ProcessReceiver receiver)
threadBlocked
in class ProcessDirector
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.ProcessDirector.addThread(Thread)
public void threadUnblocked(java.lang.Thread thread, ProcessReceiver receiver)
threadUnblocked
in class ProcessDirector
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.*
public void wrapup() throws IllegalActionException
Prior to setting receiver flags, this method wakes up the threads if they all are stopped.
This method is not synchronized on the workspace, so the caller should be.
wrapup
in interface Initializable
wrapup
in class ProcessDirector
IllegalActionException
- If an error occurs while
accessing the receivers of all actors under the control of
this director.protected boolean _areActorsExternallyBlocked() throws InvalidStateException, IllegalActionException
IllegalActionException
InvalidStateException
protected boolean _areThreadsDeadlocked()
_areThreadsDeadlocked
in class ProcessDirector
protected void _controllerBlocked(BranchController controller)
controller
- The controller for which registration of a
blocked state will occur.protected void _controllerUnBlocked(BranchController controller)
controller
- The controller for which registration of an
unblocked state will occur.protected boolean _isInputControllerBlocked()
protected boolean _isOutputControllerBlocked()
protected boolean _resolveDeadlock() throws IllegalActionException
If the deadlock is an external deadlock and the containing model of computation is process-oriented, then register the externally blocked receivers with the composite actor that contains this director's composite actor. If the deadlock is an external deadlock and the containing model of computation is schedule-oriented, then end this iteration and return true.
While in special cases it my be useful to override this method for domain specific functionality it is more likely that this method will remain the same and the _resolveInternalDeadlock() method will be overridden for particular models of computation.
_resolveDeadlock
in class ProcessDirector
IllegalActionException
- Not thrown in this base class.protected boolean _resolveInternalDeadlock() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.