ptolemy.domains.de.lib
Class PreemptableTask

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.domains.de.kernel.DEActor
                              extended byptolemy.domains.de.lib.DETransformer
                                  extended byptolemy.domains.de.lib.PreemptableTask
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, SequenceActor, java.io.Serializable, TimedActor, ptolemy.actor.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:
Yellow (celaine)
Proposed Rating:
Yellow (celaine)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.data.expr.Parameter executionTime
          The executionTime parameter indicates the time it takes to execute the task.
 ptolemy.actor.TypedIOPort interrupt
          The interrupt port, which has type BooleanToken.
 
Fields inherited from class ptolemy.domains.de.lib.DETransformer
input, output
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
PreemptableTask(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.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.TypedAtomicActor
_addPort, attributeTypeChanged, clone, typeConstraintList
 
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.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
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.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
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
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, prefire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

interrupt

public ptolemy.actor.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 ptolemy.data.expr.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.

Constructor Detail

PreemptableTask

public PreemptableTask(ptolemy.kernel.CompositeEntity container,
                       java.lang.String name)
                throws ptolemy.kernel.util.NameDuplicationException,
                       ptolemy.kernel.util.IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.IllegalActionException
If the attribute is executionTime, then check that the value is non-negative.

Parameters:
attribute - The attribute that changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the service time is negative.

fire

public void fire()
          throws ptolemy.kernel.util.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.

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
Indicate that the task in a non-interrupted, non-executing state. Also create a new linked list to store input tokens.

Throws:
ptolemy.kernel.util.IllegalActionException - If the base class throws it.

postfire

public boolean postfire()
                 throws ptolemy.kernel.util.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.

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.