ptolemy.domains.sdf.kernel
Class CachedSDFScheduler

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.sched.Scheduler
              extended by ptolemy.domains.sdf.kernel.BaseSDFScheduler
                  extended by ptolemy.domains.sdf.kernel.SDFScheduler
                      extended by ptolemy.domains.sdf.kernel.CachedSDFScheduler
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, ValueListener

public class CachedSDFScheduler
extends SDFScheduler

The CachedSDFScheduler extends the SDFScheduler by caching schedules. The cached schedules are labeled by their corresponding rate signatures, with the most recently used at the beginning of the cache queue. If the rate signatures are contained in the cache keys, then the corresponding schedule in the cache is used. Therefore, we do not need to recompute the schedule again.

The size of the cache in the CachedSDFScheduler is usually set by its containing director when constructing this scheduler. If the cache is full, the least recently used schedule (at the end of the cache) is discarded.

Since:
Ptolemy II 5.2
Version:
$Id: CachedSDFScheduler.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Ye Zhou. Contributor: Brian K. Vogel
See Also:
SDFScheduler, Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (zhouye)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  int _cacheSize
           
private  java.util.Map _externalRatesCache
           
private  java.util.List _inputPortList
           
private  java.lang.String _mostRecentRates
           
private  java.util.List _outputPortList
           
private  java.util.Map _scheduleCache
           
private  java.util.List _scheduleKeyList
           
private  long _workspaceVersion
           
 
Fields inherited from class ptolemy.domains.sdf.kernel.SDFScheduler
_externalRates, _firingVector, _rateVariables, constrainBufferSizes
 
Fields inherited from class ptolemy.domains.sdf.kernel.BaseSDFScheduler
VERBOSE
 
Fields inherited from class ptolemy.actor.sched.Scheduler
_DEFAULT_SCHEDULER_NAME
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
CachedSDFScheduler()
          Construct a scheduler with no container(director) in the default workspace, the name of the scheduler is "Scheduler".
CachedSDFScheduler(Director container, java.lang.String name, int cacheSize)
          Construct a scheduler in the given container with the given name and given cache size.
CachedSDFScheduler(Workspace workspace)
          Construct a scheduler in the given workspace with the name "Scheduler".
 
Method Summary
private  java.util.List _getInputPortList()
          Return a list of all the input ports contained by the deeply contained entities of the container of this director.
private  java.util.List _getOutputPortList()
          Return a list of all the output ports contained by the deeply contained entities of the container of this director.
protected  Schedule _getSchedule()
          Return the scheduling sequence.
 void clearCaches()
          Clear the schedule cache, cache keys and cache for external rates of this scheduler.
 void constructCaches(int cacheSize)
          Construct the caches of this scheduler with the given cache size.
 
Methods inherited from class ptolemy.domains.sdf.kernel.SDFScheduler
_checkDynamicRateVariables, _computeMaximumFirings, _countUnfulfilledInputs, _getFiringCount, _simulateExternalInputs, _simulateInputConsumption, _solveBalanceEquations, _vectorizeFirings, clone, declareRateDependency, getExternalRates, getFiringCount, valueChanged
 
Methods inherited from class ptolemy.domains.sdf.kernel.BaseSDFScheduler
_declareDependency, _saveBufferSizes, _saveContainerRates, _saveFiringCounts
 
Methods inherited from class ptolemy.actor.sched.Scheduler
getSchedule, isValid, setContainer, setValid
 
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, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, 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, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_cacheSize

private int _cacheSize

_scheduleCache

private java.util.Map _scheduleCache

_scheduleKeyList

private java.util.List _scheduleKeyList

_externalRatesCache

private java.util.Map _externalRatesCache

_mostRecentRates

private java.lang.String _mostRecentRates

_inputPortList

private java.util.List _inputPortList

_outputPortList

private java.util.List _outputPortList

_workspaceVersion

private long _workspaceVersion
Constructor Detail

CachedSDFScheduler

public CachedSDFScheduler()
Construct a scheduler with no container(director) in the default workspace, the name of the scheduler is "Scheduler". The cache size is the default value of 0.


CachedSDFScheduler

public CachedSDFScheduler(Workspace workspace)
Construct a scheduler in the given workspace with the name "Scheduler". The cache size is the default value of 0. If the workspace argument is null, use the default workspace. The scheduler is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - Object for synchronization and version tracking.

CachedSDFScheduler

public CachedSDFScheduler(Director container,
                          java.lang.String name,
                          int cacheSize)
                   throws IllegalActionException,
                          NameDuplicationException
Construct a scheduler in the given container with the given name and given cache size. The container argument must not be null, or a NullPointerException will be thrown. This attribute will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of this attribute.
cacheSize - The cache size of this scheduler.
Throws:
IllegalActionException - If the super class throws it.
NameDuplicationException - If the super class throws it.
Method Detail

clearCaches

public void clearCaches()
Clear the schedule cache, cache keys and cache for external rates of this scheduler.


constructCaches

public void constructCaches(int cacheSize)
Construct the caches of this scheduler with the given cache size.

Parameters:
cacheSize - The given cache sie.

_getSchedule

protected Schedule _getSchedule()
                         throws NotSchedulableException,
                                IllegalActionException
Return the scheduling sequence. If the schedule exist in the cache (schedules are identified by the rate signatures of ports), then return the corresponding schedule in the cache. Otherwise, compute the schedule and return it.

Overrides:
_getSchedule in class SDFScheduler
Returns:
A schedule of the deeply contained opaque entities in the firing order.
Throws:
NotSchedulableException - If the super class throws it.
IllegalActionException - If the super class throws it.
See Also:
CompositeEntity.deepEntityList()

_getInputPortList

private java.util.List _getInputPortList()
Return a list of all the input ports contained by the deeply contained entities of the container of this director.

Returns:
The list of input ports.

_getOutputPortList

private java.util.List _getOutputPortList()
Return a list of all the output ports contained by the deeply contained entities of the container of this director.

Returns:
The list of output ports.