Class VariableTableSubscriber

java.lang.Object
com.singularsys.jep.misc.publishingvariable.VariableTableSubscriber
All Implemented Interfaces:
Flow.Subscriber<VariableTableAction>
Direct Known Subclasses:
PublishingVariableTest.MyVariableTableSubscriber, VariableTableUpdater

public class VariableTableSubscriber extends Object implements Flow.Subscriber<VariableTableAction>
Convenience class for implementing a Subscriber of VariableTableActions. Depending on the action the appropriate method, like variableAdded(String, Object), is called. This class is intended to be extended by the user to provide the desired functionality. The default implementation of each method does nothing.

An example implementation that sends messages to a queue is:

public class MyVariableTableSubscriber extends VariableTableSubscriber {
    LinkedBlockingQueue<String> actions = new LinkedBlockingQueue<>();

    public MyVariableTableSubscriber() {
        super();
    }

    @Override
    protected void variableChanged(String name, Object oldValue, Object newValue) {
        actions.add("VAR_CHANGED " + name +" " + oldValue + " " + newValue);
    }

    @Override
    protected void variableAdded(String name, Object value) {
        actions.add("VAR_ADD " + name + " " + value);
    }

    @Override
    protected void constantAdded(String name, Object value) {
        actions.add("CONST_ADD " + name + " " + value);
    }

    @Override
    protected void variableRemoved(String name) {
        actions.add("VAR_DEL " + name);
    }

    @Override
    public void clearNonConstants() {
        actions.add("CLEAR_NON_CONST");
    }

    @Override
    protected void tableCleared() {
        actions.add("TBL_CLEAR");
    }

    @Override
    public void onComplete() {
        actions.add("COMPLETE");
    }

    @Override
    public void onError(Throwable throwable) {
        actions.add("ERROR "+throwable.toString());
    }
}
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default Constructor that requests one item at a time.
    VariableTableSubscriber(int numRequests)
    Constructor with a specific number of initial requests.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancels the subscription.
    protected void
    Called when the non-constant variables have been removed.
    protected void
    constantAdded(String name, Object value)
    Called when a constant is added
    void
    Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription.
    void
    onError(Throwable throwable)
    Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.
    void
    Method invoked with the next item from the Publisher.
    void
    Method invoked when the Subscription is created.
    protected void
    Called when the variable table has been cleared.
    protected void
    variableAdded(String name, Object value)
    Called when a variable is added to the table.
    protected void
    variableChanged(String name, Object oldValue, Object newValue)
    Called when a variable value has changed.
    protected void
    Called when a variable is removed from the table.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VariableTableSubscriber

      public VariableTableSubscriber()
      Default Constructor that requests one item at a time.
    • VariableTableSubscriber

      public VariableTableSubscriber(int numRequests)
      Constructor with a specific number of initial requests.
      Parameters:
      numRequests - the number of items to request
  • Method Details

    • onSubscribe

      public void onSubscribe(Flow.Subscription subscription)
      Method invoked when the Subscription is created. Requests the initial number of items specified by numRequests.
      Specified by:
      onSubscribe in interface Flow.Subscriber<VariableTableAction>
      Parameters:
      subscription - the subscription
    • onNext

      public void onNext(VariableTableAction item)
      Method invoked with the next item from the Publisher. Calls the appropriate method based on the action of the item. For example the variableChanged(String, Object, Object) method is called if the action is VARIABLE_VALUE_CHANGED.
      Specified by:
      onNext in interface Flow.Subscriber<VariableTableAction>
      Parameters:
      item - the item
    • onError

      public void onError(Throwable throwable)
      Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. The default implementation does nothing.
      Specified by:
      onError in interface Flow.Subscriber<VariableTableAction>
      Parameters:
      throwable - the exception
    • onComplete

      public void onComplete()
      Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. The default implementation does nothing.
      Specified by:
      onComplete in interface Flow.Subscriber<VariableTableAction>
    • variableChanged

      protected void variableChanged(String name, Object oldValue, Object newValue)
      Called when a variable value has changed. Intended to be overridden by subclasses. Default implementation does nothing.
      Parameters:
      name - name of the variable
      oldValue - previous value of the variable
      newValue - value of the variable after the change
    • variableAdded

      protected void variableAdded(String name, Object value)
      Called when a variable is added to the table. Intended to be overridden by subclasses. Default implementation does nothing.
      Parameters:
      name - the name of the variable which has been added.
      value - the value of the variable which has been added.
    • variableRemoved

      protected void variableRemoved(String name)
      Called when a variable is removed from the table. Intended to be overridden by subclasses. Default implementation does nothing.
      Parameters:
      name - the name of the variable which has been removed.
    • tableCleared

      protected void tableCleared()
      Called when the variable table has been cleared. Intended to be overridden by subclasses. Default implementation does nothing.
    • clearNonConstants

      protected void clearNonConstants()
      Called when the non-constant variables have been removed. Intended to be overridden by subclasses. Default implementation does nothing.
    • constantAdded

      protected void constantAdded(String name, Object value)
      Called when a constant is added
      Parameters:
      name - name of variable
      value - value of variable
    • cancel

      public void cancel()
      Cancels the subscription.