Class VariableTableSubscriber
java.lang.Object
com.singularsys.jep.misc.publishingvariable.VariableTableSubscriber
- All Implemented Interfaces:
Flow.Subscriber<VariableTableAction>
- Direct Known Subclasses:
PublishingVariableTest.MyVariableTableSubscriber,VariableTableUpdater
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
ConstructorsConstructorDescriptionDefault Constructor that requests one item at a time.VariableTableSubscriber(int numRequests) Constructor with a specific number of initial requests. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels the subscription.protected voidCalled when the non-constant variables have been removed.protected voidconstantAdded(String name, Object value) Called when a constant is addedvoidMethod 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.voidMethod invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.voidonNext(VariableTableAction item) Method invoked with the next item from the Publisher.voidonSubscribe(Flow.Subscription subscription) Method invoked when the Subscription is created.protected voidCalled when the variable table has been cleared.protected voidvariableAdded(String name, Object value) Called when a variable is added to the table.protected voidvariableChanged(String name, Object oldValue, Object newValue) Called when a variable value has changed.protected voidvariableRemoved(String name) Called when a variable is removed from the table.
-
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
Method invoked when the Subscription is created. Requests the initial number of items specified by numRequests.- Specified by:
onSubscribein interfaceFlow.Subscriber<VariableTableAction>- Parameters:
subscription- the subscription
-
onNext
Method invoked with the next item from the Publisher. Calls the appropriate method based on the action of the item. For example thevariableChanged(String, Object, Object)method is called if the action is VARIABLE_VALUE_CHANGED.- Specified by:
onNextin interfaceFlow.Subscriber<VariableTableAction>- Parameters:
item- the item
-
onError
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:
onErrorin interfaceFlow.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:
onCompletein interfaceFlow.Subscriber<VariableTableAction>
-
variableChanged
Called when a variable value has changed. Intended to be overridden by subclasses. Default implementation does nothing.- Parameters:
name- name of the variableoldValue- previous value of the variablenewValue- value of the variable after the change
-
variableAdded
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
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
Called when a constant is added- Parameters:
name- name of variablevalue- value of variable
-
cancel
public void cancel()Cancels the subscription.
-