Package ptolemy.actor.util
Class DFUtilities
- java.lang.Object
-
- ptolemy.actor.util.DFUtilities
-
public class DFUtilities 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.1
- Version:
- $Id$
- Author:
- Stephen Neuendorffer
- Pt.AcceptedRating:
- Red (neuendor)
- Pt.ProposedRating:
- Red (neuendor)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DFUtilities.NamedObjComparator
A comparator for named objects.
-
Constructor Summary
Constructors Constructor Description DFUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getRate(IOPort port)
Return the number of tokens that will be produced or consumed on the given port.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
getRateVariableValue(Port port, java.lang.String name, int defaultValue)
Get the integer value stored in the Variable with the specified name.static int
getTokenConsumptionRate(IOPort port)
Get the number of tokens that are consumed on the given port.static int
getTokenInitConsumption(IOPort port)
Get the number of tokens that are initially available on the given input port after initialization.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
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.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.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.static Variable
setRate(Port port, java.lang.String name, int rate)
Set the rate variable with the specified name to the specified value.static void
setRateVariable(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.static void
setTokenConsumptionRate(IOPort port, int rate)
Set the tokenConsumptionRate parameter of the given port to the given rate.static void
setTokenInitConsumption(IOPort port, int rate)
Set the tokenInitConsumption 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.static void
showRate(Port port, boolean flag)
Depending on the given flag, add an invisible, persistent variable named "_showRate" with value true to the given port that indicates to the user interface that rate parameters on the given port should be displayed in the user interface.
-
-
-
Method Detail
-
getRate
public 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.- Parameters:
port
- The given port.- Returns:
- The number of tokens that will be produced or consumed on the given port.
- 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.- See Also:
setRate(ptolemy.kernel.Port, java.lang.String, int)
-
getRateVariable
public 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. If there is no such variable, return null.- Parameters:
port
- The port.name
- The name of the variable.- Returns:
- The variable with the specified name in the given port.
- See Also:
setRateVariable(Port, String, int)
-
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
- If the variable does not contain a valid token, or the token is not an IntToken.
-
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.- Parameters:
port
- The given port.- 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.- See Also:
setTokenConsumptionRate(ptolemy.actor.IOPort, int)
-
getTokenInitConsumption
public static int getTokenInitConsumption(IOPort port) throws IllegalActionException
Get the number of tokens that are initially available on the given input port after initialization. If the port is not an input port, then presumably any initial tokens will be available on the inside. Return the value of the port's tokenInitConsumption parameter. If the parameter does not exist, then assume the port has no initial tokens. a value of zero.- Parameters:
port
- The given port.- Returns:
- The number of tokens the scheduler believes will be available at the given input port after initialization.
- Throws:
IllegalActionException
- If the tokenInitConsumption parameter has an invalid expression.- See Also:
setTokenInitConsumption(ptolemy.actor.IOPort, int)
-
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 the number of tokens is presumably the number of initial tokens produced on the inside of the port. The number of tokens returned is 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.- Parameters:
port
- The given port.- 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.- See Also:
setTokenInitProduction(ptolemy.actor.IOPort, int)
-
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.- Parameters:
port
- The given port.- 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.- See Also:
setTokenProductionRate(ptolemy.actor.IOPort, int)
-
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
- If a new parameter can not be created for the give port.
-
setIfNotDefined
public 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
- If a new parameter can not be created for the given port, or the given value is not an acceptable.
-
setOrCreate
public 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:
IllegalActionException
- If the variable exists and its value cannot be set.
-
setOrCreate
public 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:
IllegalActionException
- If the variable exists and its value cannot be set.
-
setRate
public static Variable 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.- Returns:
- The rate parameter.
- Throws:
IllegalActionException
- If the rate is a negative integer, or the rate can not be set.- See Also:
getRate(IOPort)
-
setRateVariable
public static void setRateVariable(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. Then set the value of the variable to the specified value.- Parameters:
port
- The port.name
- Name of the variable.value
- The value.- Throws:
IllegalActionException
- If a new parameter can not be created for the given port, or the given value is not an acceptable.- See Also:
getRateVariable(Port, String)
-
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.- Parameters:
port
- The given port.rate
- The given rate.- Throws:
IllegalActionException
- If the rate is negative.- See Also:
getTokenConsumptionRate(ptolemy.actor.IOPort)
-
setTokenInitConsumption
public static void setTokenInitConsumption(IOPort port, int rate) throws IllegalActionException
Set the tokenInitConsumption 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.- Parameters:
port
- The given port.rate
- The given rate.- Throws:
IllegalActionException
- If the rate is negative.- See Also:
getTokenInitConsumption(IOPort)
-
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.- Parameters:
port
- The given port.rate
- The given rate.- Throws:
IllegalActionException
- If the rate is negative.- See Also:
getTokenInitProduction(ptolemy.actor.IOPort)
-
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.- Parameters:
port
- The given port.rate
- The given rate.- Throws:
IllegalActionException
- If the rate is negative.- See Also:
getTokenProductionRate(ptolemy.actor.IOPort)
-
showRate
public static void showRate(Port port, boolean flag) throws IllegalActionException
Depending on the given flag, add an invisible, persistent variable named "_showRate" with value true to the given port that indicates to the user interface that rate parameters on the given port should be displayed in the user interface.- Parameters:
port
- The port.flag
- The flag.- Throws:
IllegalActionException
- If a new parameter can not be created for the given port, or the given flag is not an acceptable.
-
-