Package com.singularsys.jep.misc.publishingvariable

# Class PublishingVariable

java.lang.Object
com.singularsys.jep.Variable
com.singularsys.jep.misc.publishingvariable.PublishingVariable

All Implemented Interfaces:
  `Serializable`

public class PublishingVariable extends Variable
A Variable that can publish messages when its value is changed. These are normally created by a `PublishingVariableFactory` which sets the publisher in the constructor.

See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.Variable

  `keys, keyVals, name`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PublishingVariable(String name, Object value, SubmissionPublisher<VariableTableAction> pub)`
  Create a variable with a given publisher
  `PublishingVariable(String name, SubmissionPublisher<VariableTableAction> pub)`
  Create a variable with a given publisher

- ## Method Summary

  Modifier and Type
  Method
  Description
  `SubmissionPublisher<VariableTableAction>`
  `getPublisher()`
  Get the publisher for this variable.
  `void`
  `setPublisher(SubmissionPublisher<VariableTableAction> publisher)`
  Set the publisher for this variable.
  `boolean`
  `setValue(Object object)`
  Sets the value of the variable and publishes a message if the publisher is not null.

  ### Methods inherited from class com.singularsys.jep.Variable

  `copyPropertiesFrom, getHook, getName, getValue, hasValidValue, hookKeys, isConstant, removeHook, setHook, setIsConstant, setValidValue, setValueRaw, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PublishingVariable

    public PublishingVariable(String name, SubmissionPublisher<VariableTableAction> pub)
    Create a variable with a given publisher
    Parameters:
      `name` - name of variable
      `pub` - the SubmissionPublisher

  - ### PublishingVariable

    public PublishingVariable(String name, Object value, SubmissionPublisher<VariableTableAction> pub)
    Create a variable with a given publisher
    Parameters:
      `name` - name of variable
      `value` - initial value of the variable
      `pub` - the SubmissionPublisher

- ## Method Details

  - ### setValue

    public boolean setValue(Object object)
    Sets the value of the variable and publishes a message if the publisher is not null.
    Overrides:
      `setValue` in class `Variable`
    Parameters:
      `object` - the new value
    Returns:
      false if tried to change a constant value.
    Throws:
      `IllegalStateException` - if the publisher is closed.

  - ### getPublisher

    public SubmissionPublisher<VariableTableAction> getPublisher()
    Get the publisher for this variable.
    Returns:
      the publisher

  - ### setPublisher

    public void setPublisher(SubmissionPublisher<VariableTableAction> publisher)
    Set the publisher for this variable. If you just need to watch a subset of variables, you can use create a `PublishingVariableFactory` with null `SubmissionPublisher` and then set the publisher for the variables you want to watch.
    Parameters:
      `publisher` - the publisher to set