public class ThreadedComposite extends MirrorComposite
A paper describing the use of this actor is found at http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-151.html.
This actor automatically creates input and output ports to match those of the inside actor. Input events provided at those input ports are provided as input events to the contained actor. Outputs provided by the contained actor become output events of this actor. The time stamp of the input events is provided by the container of this actor. The time stamp of the output events depends on the delay parameter, as explained below.
The inside thread blocks waiting for inputs or pure events. Inputs are provided to that thread when the fire() method of this actor is invoked by the director thread. Pure events are provided after fireAt(), fireAtCurrentTime(), or fireAtFirstValidTimeAfter() are called by either the inside thread or the director thread. When the time of those firing requests becomes current time, the container will (presumably) fire this actor, and this actor will provide a pure event to the inside thread, causing it to fire the contained actor.
If the synchronizeToRealTime parameter is true, then when the inside thread encounters an input or pure event with time stamp t, it stalls until real time matches or exceeds t (measured in seconds since the start of execution of the inside thread). In contrast for example to the synchronizeToRealTime parameter of the DEDirector, this enables construction of models where only a portion of the model synchronizes to real time.
When the wrapup() method of this actor is called, the inside thread is provided with signal to terminate rather than to process additional inputs. The inside thread will also exit if stop() is called on this actor; however, in this case, which iterations are completed is nondeterminate (there may be inputs left unprocessed).
The parameters of this actor include all the parameters of the contained actor, and setting those parameters automatically sets the parameters of the contained actor.
In addition to the parameters of the contained actor, this actor has a delay parameter. This parameter is a double that be any nonnegative value or the special value UNDEFINED. If it is given a nonnegative value, then the value specifies the model-time delay between input events and the output events that result from reacting to those input events. That is, if this actor is given an input event with time stamp t, then if the contained actor produces any output events in reaction to that event, those output events will be produced by this actor with time stamp t + delay.
If delay has value UNDEFINED, then outputs are produced at the current model time of the executive director when the inside thread happens to produce those events, or if synchronizeToRealTime, at the greater of current model time and current real time (measured in seconds since the start of execution). This is accomplished by the inside thread calling fireAtFirstValidTimeAfter() of the enclosing director, and then producing the outputs when the requested firing occurs in the director thread. Note that with this value of the delay, it is possible for the inside thread to continue to execute and respond to input events after the wrapup phase of the director thread has been entered. The wrapup phase will stall until the inside thread has completed its processing of its inputs, but any outputs it produces after the wrapup phase has started will be discarded.
The most common use of this actor is in the DE domain, although it can also be used in CT, SR, SDF, and other domains, with some care. See the above referenced memo. Regardless of the value of delay, this actor is treated by DE as introducing a delay, much like the TimedDelay actor. In fact, if delay is 0.0, there will be a one tick delay in superdense time, just as with the TimedDelay actor. If the inside model also has a time delay (e.g. if you put a TimedDelay actor inside a ThreadedComposite), then the total delay is the sum of the two delays.
Discussion:
There are several useful things you can do with this model. We describe some use cases here:
Background execution. When delay is greater than or equal to 0.0, then when this actor is fired in response to input events with time stamp t, the actual processing of those events occurs later in a separate thread. The director thread is not blocked, and can continue to process events with time stamps less than or equal to t + delay. The director thread is blocked from processing events with larger time stamps than that because this is necessary to preserve DE semantics. To implement this, this actor uses fireAt() to request a firing at time t + delay, and when that firing occurs, it blocks the director thread until the reaction is complete.
Parallel firing. Note that if delay is set to 0.0, it may seem that there is no point in using this actor, since model time will not be allowed to increase past t until the contained actor has reacted to events with time stamp t. However, there is actually exploitable concurrency if there are other actors in the model that also have pending input events with time stamp t. Those event can be processed concurrently with this actor reacting to its input event. A typical use case will broadcast an event to several instances of ThreadedComposite, in which case each of those several inside threads can execute concurrently in reaction to those input events.
Real-time source. If the contained actor (and hence this actor) has no inputs and synchronizeToRealTime is true, then the contained actor must call fireAt() or one of its variants so that the inside thread will be provided with pure events. The behavior depends on which variant of the fireAt() methods is used by the inside actor. There are three cases: FIXME: Described these. In particular, delay needs to specify the minimum increment between these or fireAt() could result in an exception. Do we want a parameter to relax that?
On subtlety of this actor is that it cannot expose instances of ParameterPort without introducing nondeterminacy in the execution. A ParameterPort is an input port that sets the value of a parameter with the same name. Upon receiving a token at such a port, if this actor were to set a parameter visible by the inside thread, there is no assurance that the inside thread is not still executing an earlier iteration. Thus, it could appear to be sending a message backward in time, which would be truly bizarre. To prevent this error, this actor does not mirror such ports, and hence they appear on the outside only as parameters.
Red (eal) |
Yellow (eal) |
Modifier and Type | Class and Description |
---|---|
protected static class |
ThreadedComposite.TokenFrame
Bundle data associated with ports and a time stamp.
|
MirrorComposite.MirrorCompositeContents
ReflectComposite.ReflectCompositeContents
CompositeEntity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
delay
The model-time delay between the input events and the
output events.
|
Parameter |
synchronizeToRealTime
If set to true, the inside thread stalls until real time matches
the time stamps of input events or pure events for each firing.
|
_inAddPort, _inRemoveEntity, _mirrorParameterPorts
_actorFiringListeners, _causalityInterface, _derivedPiggybacks, _initializables, _notifyingActorFiring, _piggybacks, _publishedPorts, _publisherRelations, _stopRequested, _subscribedPorts
_levelCrossingLinks
_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 |
---|
ThreadedComposite(CompositeEntity container,
java.lang.String name)
Create an actor with a name and a container.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute.
|
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace.
|
CausalityInterface |
getCausalityInterface()
Override the base class to return a causality interface that
indicates that the output does not depend (immediately) on
the input.
|
boolean |
iterateContainedActors()
Iterate the contained actors of the
container of this director.
|
_addPort
_addEntity, _exportMoMLContents, _removeEntity, _removePort, newParameterPort, newPort
_addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newRelation, resolveTypes, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, fire, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort, wrapup
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, clone, 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, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, initialize, preinitialize, removeInitializable, wrapup
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public Parameter delay
public Parameter synchronizeToRealTime
public ThreadedComposite(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container actor.name
- The name of this actor.IllegalActionException
- If the container is incompatible
with this actor.NameDuplicationException
- If the name coincides with
an actor already in the container.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class TypedCompositeActor
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class ReflectComposite
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If a derived class has
has an attribute that cannot be cloned.CompositeEntity.exportMoML(Writer, int, String)
public CausalityInterface getCausalityInterface()
getCausalityInterface
in interface Actor
getCausalityInterface
in class CompositeActor
public boolean iterateContainedActors() throws IllegalActionException
IllegalActionException
- If any called method of
of the contained actor throws it, or if the contained
actor is not opaque.