Class PublishingVariableTable
java.lang.Object
com.singularsys.jep.VariableTable
com.singularsys.jep.misc.DecoratingVariableTable
com.singularsys.jep.misc.publishingvariable.PublishingVariableTable
- All Implemented Interfaces:
JepComponent,Serializable
A VariableTable which publishes changes to its content.
This uses the
Flow
system of publishers and subscribers. Changes to the table,
such as adding and removing variables, and changing the value of a variable
are published as VariableTableActions.
Two statics factories can be used for creating SubmissionPublishers,
createDefaultPublisher() and createCurrentThreadPublisher().
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.VariableTable
table, vf -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with a specified publisher. -
Method Summary
Modifier and TypeMethodDescriptionaddConstant(String name, Object value) Adds a constant to the table.addVariable(String name) Adds a variable to the table.addVariable(String name, Object value) Adds a variable to the table.voidclear()Clears all variables from the table, removes all subscribers and publishes aVariableTableAction.Actions.CLEAR_TABLEto indicate the table has been cleared.Creates a SubmissionPublisher with anExecutorwhich uses the current thread, and the default buffer capacity.Create a defaultSubmissionPublisher.static PublishingVariableTableCreates a decorating instance This used the defaultSubmissionPublisherCreates a new PublishingVariableTable with a null publisher.Get the publisher for this variable table.Remove a variable with a given name from the table.voidClears all non constant variables from the table, removes all subscribers and publishes aVariableTableAction.Actions.CLEAR_NON_CONSTANTto indicate the table has been cleared.voidsetPublisher(SubmissionPublisher<VariableTableAction> publisher) Set the publisher for this variable table.voidSet the publisher for all variables in this variable table.Methods inherited from class com.singularsys.jep.misc.DecoratingVariableTable
clearValues, containsKey, containsVariable, copyConstantsFrom, copyVariablesFrom, getBase, getVariable, getVariableFactory, getVariables, init, isEmpty, keySet, remove, setVariableFactory, size, toString, values
-
Constructor Details
-
PublishingVariableTable
Constructor with a specified publisher.- Parameters:
publisher- the publisher
-
-
Method Details
-
decoratorInstance
public static PublishingVariableTable decoratorInstance(VariableTable base, SubmissionPublisher<VariableTableAction> pub) Creates a decorating instance This used the defaultSubmissionPublisher- Parameters:
base- base VariableTable- Returns:
- a new PublishingVariableTable
-
addVariable
Adds a variable to the table.- Overrides:
addVariablein classDecoratingVariableTable- Parameters:
name- variable name, will be converted to lower case- Returns:
- the variable
- Throws:
IllegalStateException- if the publisher is closed.
-
addVariable
Adds a variable to the table.- Overrides:
addVariablein classDecoratingVariableTable- Parameters:
name- variable name, will be converted to lower casevalue- initial value- Returns:
- the variable
- Throws:
IllegalStateException- if the publisher is closed.JepException- if an attempt is made to set the value of a constant variable
-
addConstant
Adds a constant to the table.- Overrides:
addConstantin classDecoratingVariableTable- Parameters:
name- variable namevalue- variable value- Returns:
- the corresponding Variable object
- Throws:
IllegalStateException- if the publisher is closed.JepException- if an attempt is made to set the value of an existing constant variable
-
remove
Description copied from class:VariableTableRemove a variable with a given name from the table.- Overrides:
removein classDecoratingVariableTable- Parameters:
name- name of the variable to remove- Returns:
- the removed variable or null if the variable does not exist in the table.
-
clear
public void clear()Clears all variables from the table, removes all subscribers and publishes aVariableTableAction.Actions.CLEAR_TABLEto indicate the table has been cleared.- Overrides:
clearin classDecoratingVariableTable
-
removeNonConstants
public void removeNonConstants()Clears all non constant variables from the table, removes all subscribers and publishes aVariableTableAction.Actions.CLEAR_NON_CONSTANTto indicate the table has been cleared.- Overrides:
removeNonConstantsin classDecoratingVariableTable
-
getPublisher
Get the publisher for this variable table.- Returns:
- the publisher
-
setPublisher
Set the publisher for this variable table. This will not change the publisher for any existing variables in the table which can be achieved using thesetPublisherForAllVariables(SubmissionPublisher)method. Nor will it change the publisher for new variables, for that use thePublishingVariableFactory.setPublisher(SubmissionPublisher).- Parameters:
publisher-
-
setPublisherForAllVariables
Set the publisher for all variables in this variable table. This will not change the publisher for this variable table, which can be achieved using thesetPublisher(SubmissionPublisher), nor will it change the publisher for new variables, for that use thePublishingVariableFactory.setPublisher(SubmissionPublisher).- Parameters:
publisher-
-
getLightWeightInstance
Creates a new PublishingVariableTable with a null publisher.- Specified by:
getLightWeightInstancein interfaceJepComponent- Overrides:
getLightWeightInstancein classDecoratingVariableTable- Returns:
- a new VariableTable
- See Also:
-
createDefaultPublisher
Create a defaultSubmissionPublisher.- Returns:
- the publisher
-
createCurrentThreadPublisher
Creates a SubmissionPublisher with anExecutorwhich uses the current thread, and the default buffer capacity.- Returns:
- the publisher
-