State Change Trigger pattern

When an svc_expr service has states, the notify operations on the service can be conditionalized to trigger on state changes.

In the example in Table 1, a notify operation is triggered as soon as the Count state variable exceeds 5.

Table 1. State Change Trigger
Example Description
<service name="Expr"  
  provision="expr">  
  <prop name="expr.state"    
    Count="NewCount"/>
</service>  

<notify name="myNotify"  
  service="Sequencer"  
  clients="Expr"  
  fields="TRIGGER">  
  <prop name="expr.state"    
    Count="OldCount"/>  
  <prop name="expr.src"    
    content-type="text/x-erlang"><![CDATA[
Count > 5.  
  ]]></prop>
</notify>
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.
The myNotify operation specifies the Expr service as a client. The Expr service has Count as a state variable.

When the Count state variable is changed by any other operation, the expression list in the myNotify operation is evaluated and the notify is triggered.

Note: The old value of the Count state variable is available in the OldCount variable which can be used by any expression in the expressions list.

If the final expression value is true, that is, Count is bigger than 5, the notify is fired.

If the value of the final expression is any value other than boolean true, the notify event is not fired

The myNotify operation ignores all other state variables that may exist on the mix. This operation is only listening for changes to the Count variable and is only triggered whenever this variable changes.

If more than one variable is specified in the expr.state property, then the notify is triggered by a change in any one of those variables.