ptolemy.domains.de.lib
Class PreemptableTask
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.domains.de.kernel.DEActor
ptolemy.domains.de.lib.DETransformer
ptolemy.domains.de.lib.PreemptableTask
- All Implemented Interfaces:
- Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, SequenceActor, java.io.Serializable, TimedActor, TypedActor
- public class PreemptableTask
- extends DETransformer
This actor simulates a preemptable task. The executionTime
parameter specifies the time it takes to execute the task. Tokens
received on the input port correspond to invocations of the
task.
When a token is received on the input port, the token is stored
in the actor and the actor is scheduled to fire at
executionTime time units later. When the interrupt port
receives a token, and the value is true, this task is "preempted."
Later, when the value of the token on the interrupt port
becomes false, the elapsed time is calculated and added to the
execution time of the task. The actor is scheduled to fire at this
new execution time. The saved token is emitted when the new execution
time has passed. Subsequent input tokens are queued until the actor
is done processing the current input token, in which case the actor is
scheduled to fire at the current time to respond to the next task
invocation in the queue.
- Since:
- Ptolemy II 2.0
- Version:
- $Id: PreemptableTask.java,v 1.18 2004/04/13 05:13:06 cxh Exp $
- Author:
- Elaine Cheong and Yang Zhao and Xiaojun Liu
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
| Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
|
Method Summary |
void |
attributeChanged(Attribute attribute)
If the attribute is executionTime, then check that
the value is non-negative. |
void |
fire()
If the task receives a token on the input port, queue
it inside of the actor.
|
void |
initialize()
Indicate that the task in a non-interrupted, non-executing
state. |
boolean |
postfire()
If the execution time of the task has passed, emit the saved
input token. |
| Methods inherited from class ptolemy.domains.de.kernel.DEActor |
newPort |
| Methods inherited from class ptolemy.actor.AtomicActor |
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup |
| Methods inherited from class ptolemy.kernel.Entity |
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables |
| Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
interrupt
public TypedIOPort interrupt
- The interrupt port, which has type BooleanToken. If this input
port receives a token with the value true, then the task is
"preempted." When this port receives a token with the value
false, the task resumes execution.
executionTime
public Parameter executionTime
- The executionTime parameter indicates the time it takes to
execute the task.
Note: In a future version of this actor, perhaps we want to
use a parameter expression to compute the execution time based
on the token value.
PreemptableTask
public PreemptableTask(CompositeEntity container,
java.lang.String name)
throws NameDuplicationException,
IllegalActionException
- Construct an actor with the given container and name.
- Parameters:
container - The container.name - The name of this actor.
- Throws:
IllegalActionException - If the actor cannot be contained
by the proposed container.
NameDuplicationException - If the container already has an
actor with this name.
attributeChanged
public void attributeChanged(Attribute attribute)
throws IllegalActionException
- If the attribute is executionTime, then check that
the value is non-negative.
- Overrides:
attributeChanged in class NamedObj
- Parameters:
attribute - The attribute that changed.
- Throws:
IllegalActionException - If the service time is negative.
fire
public void fire()
throws IllegalActionException
- If the task receives a token on the input port, queue
it inside of the actor.
When the actor is in a non-executing and non-interrupted
state, and there is an available input token at the
input port, begin execution of the task by scheduling
the actor to fire at executionTime time units later.
When the interrupt port receives a token, and the
value is true, this task is "preempted." Later, when the
value of the token on the interrupt port becomes
false, the elapsed time is calculated and added to the
execution time of the task. The actor is scheduled to fire
at this newly calculated execution time.
- Specified by:
fire in interface Executable- Overrides:
fire in class AtomicActor
- Throws:
IllegalActionException - If there is no director.
initialize
public void initialize()
throws IllegalActionException
- Indicate that the task in a non-interrupted, non-executing
state. Also create a new linked list to store input tokens.
- Specified by:
initialize in interface Executable- Overrides:
initialize in class AtomicActor
- Throws:
IllegalActionException - If the base class throws it.
postfire
public boolean postfire()
throws IllegalActionException
- If the execution time of the task has passed, emit the saved
input token. If the actor is in a non-executing and
non-interrupted state, and there are more input tokens to
process, schedule the actor to fire again.
- Specified by:
postfire in interface Executable- Overrides:
postfire in class AtomicActor
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException - If there is no director.