ptolemy.domains.sdf.kernel
Class SDFUtilities

java.lang.Object
  extended byptolemy.domains.sdf.kernel.SDFUtilities

public class SDFUtilities
extends java.lang.Object

This class factors code out of the SDF domain, for use in different schedulers, so that they can be implemented in a consistent fashion. This interface contains static methods that are often useful from outside of an SDFDirector, and so are provided here in an interface that can be imported.

Since:
Ptolemy II 4.0
Version:
$Id: SDFUtilities.java,v 1.12 2004/04/13 05:12:36 cxh Exp $
Author:
Stephen Neuendorffer
Accepted Rating:
Red (neuendor)
Proposed Rating:
Red (neuendor)

Nested Class Summary
static class SDFUtilities.NamedObjComparator
          A comparator for named objects.
 
Constructor Summary
SDFUtilities()
           
 
Method Summary
protected static int _getRate(IOPort port)
          Return the number of tokens that will be produced or consumed on the given port.
static int _getRateVariableValue(Port port, java.lang.String name, int defaultValue)
          Get the integer value stored in the Variable with the specified name.
protected static void _setIfNotDefined(Port port, java.lang.String name, int value)
          If a variable with the given name does not exist, then create a variable with the given name and set the value of that variable to the specified value.
protected static void _setOrCreate(NamedObj container, java.lang.String name, int value)
          If the specified container does not contain a variable with the specified name, then create such a variable and set its value to the specified integer.
protected static void _setOrCreate(NamedObj container, java.lang.String name, java.lang.String expression)
          If the specified container does not contain a variable with the specified name, then create such a variable and set its expression to the specified string.
protected static void _setRate(Port port, java.lang.String name, int rate)
          Set the rate variable with the specified name to the specified value.
static Variable getRateVariable(Port port, java.lang.String name)
          Get the Variable with the specified name in the given port, or with the specified name preceded by an underscore.
static int getTokenConsumptionRate(IOPort port)
          Get the number of tokens that are consumed on the given port.
static int getTokenInitProduction(IOPort port)
          Get the number of tokens that are produced on the given port during initialization.
static int getTokenProductionRate(IOPort port)
          Get the number of tokens that are produced on the given port.
static void setExpressionIfNotDefined(Port port, java.lang.String name, java.lang.String value)
          If a variable with the given name does not exist, then create a variable with the given name and set the value of that variable to the specified value.
static void setTokenConsumptionRate(IOPort port, int rate)
          Set the tokenConsumptionRate parameter of the given port to the given rate.
static void setTokenInitProduction(IOPort port, int rate)
          Set the tokenInitProduction parameter of the given port to the given rate.
static void setTokenProductionRate(IOPort port, int rate)
          Set the tokenProductionRate parameter of the given port to the given rate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SDFUtilities

public SDFUtilities()
Method Detail

getRateVariable

public static Variable getRateVariable(Port port,
                                       java.lang.String name)
                                throws IllegalActionException
Get the Variable with the specified name in the given port, or with the specified name preceded by an underscore. If there is no such variable, return null;

Parameters:
port - The port.
name - The name of the variable.
Throws:
IllegalActionException

getTokenConsumptionRate

public static int getTokenConsumptionRate(IOPort port)
                                   throws IllegalActionException
Get the number of tokens that are consumed on the given port. If the port is not an input port, then return zero. Otherwise, return the value of the port's tokenConsumptionRate parameter. If this parameter does not exist, then assume the actor is homogeneous and return one.

Returns:
The number of tokens the scheduler believes will be consumed from the given input port during each firing.
Throws:
IllegalActionException - If the tokenConsumptionRate parameter has an invalid expression.

getTokenInitProduction

public static int getTokenInitProduction(IOPort port)
                                  throws IllegalActionException
Get the number of tokens that are produced on the given port during initialization. If the port is not an output port, then return zero. Otherwise, return the value of the port's tokenInitProduction parameter. If the parameter does not exist, then assume the actor is zero-delay and return a value of zero.

Returns:
The number of tokens the scheduler believes will be produced from the given output port during initialization.
Throws:
IllegalActionException - If the tokenInitProduction parameter has an invalid expression.

getTokenProductionRate

public static int getTokenProductionRate(IOPort port)
                                  throws IllegalActionException
Get the number of tokens that are produced on the given port. If the port is not an output port, then return zero. Otherwise, return the value of the port's tokenProductionRate parameter. If the parameter does not exist, then assume the actor is homogeneous and return a rate of one.

Returns:
The number of tokens the scheduler believes will be produced from the given output port during each firing.
Throws:
IllegalActionException - If the tokenProductionRate parameter has an invalid expression.

setTokenConsumptionRate

public static void setTokenConsumptionRate(IOPort port,
                                           int rate)
                                    throws IllegalActionException
Set the tokenConsumptionRate parameter of the given port to the given rate. If no parameter exists, then create a new one. The new one is an instance of Variable, so it is not persistent. That is, it will not be saved in the MoML file if the model is saved. The port is normally an input port, but this is not checked.

Throws:
IllegalActionException - If the rate is negative.

setTokenInitProduction

public static void setTokenInitProduction(IOPort port,
                                          int rate)
                                   throws IllegalActionException
Set the tokenInitProduction parameter of the given port to the given rate. If no parameter exists, then create a new one. The new one is an instance of Variable, so it is not persistent. That is, it will not be saved in the MoML file if the model is saved. The port is normally an output port, but this is not checked.

Throws:
IllegalActionException - If the rate is negative.

setTokenProductionRate

public static void setTokenProductionRate(IOPort port,
                                          int rate)
                                   throws IllegalActionException
Set the tokenProductionRate parameter of the given port to the given rate. If no parameter exists, then create a new one. The new one is an instance of Variable, so it is transient. That is, it will not be exported to MoML files. The port is normally an output port, but this is not checked.

Throws:
IllegalActionException - If the rate is negative.

_getRate

protected static int _getRate(IOPort port)
                       throws NotSchedulableException,
                              IllegalActionException
Return the number of tokens that will be produced or consumed on the given port. If the port is an input, then return its consumption rate, or if the port is an output, then return its production rate.

Throws:
NotSchedulableException - If the port is both an input and an output, or is neither an input nor an output.
IllegalActionException - If a rate does not contain a valid expression.

_getRateVariableValue

public static int _getRateVariableValue(Port port,
                                        java.lang.String name,
                                        int defaultValue)
                                 throws IllegalActionException
Get the integer value stored in the Variable with the specified name. If there is still no such variable, then return the specified default.

Parameters:
port - The port.
name - The name of the variable.
defaultValue - The default value of the variable.
Returns:
A rate.
Throws:
IllegalActionException

_setIfNotDefined

protected static void _setIfNotDefined(Port port,
                                       java.lang.String name,
                                       int value)
                                throws IllegalActionException
If a variable with the given name does not exist, then create a variable with the given name and set the value of that variable to the specified value. The resulting variable is not persistent and not editable, but will be visible to the user.

Parameters:
port - The port.
name - Name of the variable.
value - The value.
Throws:
IllegalActionException

setExpressionIfNotDefined

public static void setExpressionIfNotDefined(Port port,
                                             java.lang.String name,
                                             java.lang.String value)
                                      throws IllegalActionException
If a variable with the given name does not exist, then create a variable with the given name and set the value of that variable to the specified value. The resulting variable is not persistent and not editable, but will be visible to the user.

Parameters:
port - The port.
name - Name of the variable.
value - The value.
Throws:
IllegalActionException

_setOrCreate

protected static void _setOrCreate(NamedObj container,
                                   java.lang.String name,
                                   int value)
                            throws IllegalActionException
If the specified container does not contain a variable with the specified name, then create such a variable and set its value to the specified integer. The resulting variable is not persistent and not editable, but will be visible to the user. If the variable does exist, then just set its value.

Parameters:
container - The container.
name - Name of the variable.
value - The value.
Throws:
If - the variable exists and its value cannot be set.
IllegalActionException

_setOrCreate

protected static void _setOrCreate(NamedObj container,
                                   java.lang.String name,
                                   java.lang.String expression)
                            throws IllegalActionException
If the specified container does not contain a variable with the specified name, then create such a variable and set its expression to the specified string. The resulting variable is not persistent and not editable, but will be visible to the user. If the variable does exist, then just set its expression.

Parameters:
container - The container.
name - Name of the variable.
expression - The expression.
Throws:
If - the variable exists and its value cannot be set.
IllegalActionException

_setRate

protected static void _setRate(Port port,
                               java.lang.String name,
                               int rate)
                        throws IllegalActionException
Set the rate variable with the specified name to the specified value. If it doesn't exist, create it.

Parameters:
port - The port.
name - The variable name.
rate - The rate value.
Throws:
IllegalActionException