Class MetroIIPNDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.actor.process.ProcessDirector
-
- ptolemy.actor.process.CompositeProcessDirector
-
- ptolemy.domains.pn.kernel.PNDirector
-
- ptolemy.domains.metroII.kernel.MetroIIPNDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Executable
,Initializable
,GetFirable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class MetroIIPNDirector extends PNDirector implements GetFirable
MetroIIPNDirector extends PNDirector and implements the MetroIIEventHandler interface. In addition to being blocked on read or write, the actors governed by MetroIIPNDirector may be blocked by MetroII events: 'Get.End' or 'Put.Begin'. 'Get.End' is PROPOSED after a token is successfully obtained from the receiver. And the actor is blocked until 'Get.End' is NOTIFIED. 'Put.Begin' is PROPOSED before trying to put a token into the receiver. Similarly, the actor is blocked until 'Put.Begin' is NOTIFIED.
Known issue: threads created by Yieldadapter correctly stop but the ones created by ProcessDirector do not. It seems stop() is called for each thread in ProcessDirector.stop() but no effect can be observed. Don't know why. BTW, stop() is a deprecated function in java.
The implementation is obsolete and needs to be updated.
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Liangpeng Guo
- Pt.AcceptedRating:
- Red (glp)
- Pt.ProposedRating:
- Red (glp)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set
_metroIIEventBlockedThreads
The set of threads that are blocked on an MetroII event.-
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 MetroIIPNDirector(CompositeEntity container, java.lang.String name)
Constructs a director in the given container with the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_getMetroIIEventBlockedThreadsCount()
Returns the number of threads that are currently blocked on a MetroII event.protected void
_requestFinishOnReceivers()
Notifies all the threads blocked on MetroII events.net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>>
adapter()
Returns the iterator for the caller function of getfire().void
addProposedMetroIIEvent(metroIIcomm.Event.Builder e)
Adds a proposed MetroII event into the director's event list.java.lang.Object
clone(Workspace workspace)
Clones the director into the specified workspace.void
getfire(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler)
Implements fire() with MetroII event handling.Receiver
newReceiver()
The same as super class except replacing the PNQueueReceiver by MetroIIPNQueueReceiver.void
proposeMetroIIEvent(java.lang.String suffix)
Creates a MetroII event with the name: thread.getName()+suffix Add the MetroII event into the director's event list.-
Methods inherited from class ptolemy.domains.pn.kernel.PNDirector
_incrementLowestWriteCapacityPort, _resolveInternalDeadlock, addProcessListener, initialize, postfire, preinitialize, removeProcessListener, suggestedModalModelDirectors, supportMultirateFiring, threadBlocked, threadUnblocked
-
Methods inherited from class ptolemy.actor.process.CompositeProcessDirector
_areActorsExternallyBlocked, _areThreadsDeadlocked, _controllerBlocked, _controllerUnBlocked, _isInputControllerBlocked, _isOutputControllerBlocked, _resolveDeadlock, createBranchController, getInputController, getOutputController, prefire, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked, wrapup
-
Methods inherited from class ptolemy.actor.process.ProcessDirector
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, 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, 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, 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
-
-
-
-
Constructor Detail
-
MetroIIPNDirector
public MetroIIPNDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Constructs 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. Initialize an eventLock vector.- Parameters:
container
- Container of the director.name
- Name of this director.- Throws:
IllegalActionException
- If the director is not compatible with the specified container. 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
Clones the director into the specified workspace.- Overrides:
clone
in classPNDirector
- Parameters:
workspace
- The workspace for the new object.- Returns:
- a new MetroIIPNDirector.
- 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)
-
newReceiver
public Receiver newReceiver()
The same as super class except replacing the PNQueueReceiver by MetroIIPNQueueReceiver.- Overrides:
newReceiver
in classPNDirector
- Returns:
- A new PNQueueReceiver.
-
addProposedMetroIIEvent
public void addProposedMetroIIEvent(metroIIcomm.Event.Builder e)
Adds a proposed MetroII event into the director's event list.- Parameters:
e
- the event to be added.
-
adapter
public net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>> adapter()
Returns the iterator for the caller function of getfire().- Specified by:
adapter
in interfaceGetFirable
- Returns:
- iterator the iterator for the caller function of getfire()
-
getfire
public void getfire(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler) throws net.jimblackler.Utils.CollectionAbortedException
Implements fire() with MetroII event handling. In each iteration, getfire() waits until all other threads are blocked and yield returns MetroII events. When getfire() continues, notify the threads blocked on MetroII events based on the event status. A thread blocked on MetroII event is not notified until the blocking MetroII event is NOTIFIED. The rest of the function is copied from fire() of ProcessDirector- Specified by:
getfire
in interfaceGetFirable
- Parameters:
resultHandler
- iterable of events 'yield returned'.- Throws:
net.jimblackler.Utils.CollectionAbortedException
-
proposeMetroIIEvent
public void proposeMetroIIEvent(java.lang.String suffix) throws java.lang.InterruptedException
Creates a MetroII event with the name: thread.getName()+suffix Add the MetroII event into the director's event list. Block the thread calling proposeMetroIIEvent().- Parameters:
suffix
- The suffix of MetroII event name- Throws:
java.lang.InterruptedException
-
_getMetroIIEventBlockedThreadsCount
protected final int _getMetroIIEventBlockedThreadsCount()
Returns the number of threads that are currently blocked on a MetroII event.- Returns:
- Return the number of threads that are currently blocked on a MetroII event.
-
_requestFinishOnReceivers
protected void _requestFinishOnReceivers()
Notifies all the threads blocked on MetroII events. Request finish on all the receivers.- Overrides:
_requestFinishOnReceivers
in classProcessDirector
-
-