Filtering subroutines

You can use Erlang expressions to conditionalize the firing of subroutines. For example, a consume operation has several notify subroutines, some of which only fire if certain conditions are met.

If the subr.spec property of a subroutine notify or solicit operation contains Erlang expressions, this content is used as a predicate to determine whether the operation fires for a given call.

Note: This is similar to the way notifies on an svc_expr service are treated. See Notify triggers.

The operation only fires if the predicate returns true. This result is coerced to a boolean, so all the following results mean the same:

  • <<"true">>
  • "true"
  • 1
  • true
Table 1. Filtered subroutines example
Example Description
<service name="Subr" 
  provision="subr"/>
  <mix name="Master">
    <consume name="Master" 
      service="Subr" 
      fields="field1">
      <prop name="subr.spec" 
        function="SubrFun" 
        Field1="field1"/>
    </consume>
  </mix>
  <mix name="Slave1">
    <notify name="Slave1" 
      clients="Subr" 
      service="Sequencer" 
      fields="field1">
      <prop name="subr.spec" 
        function="SubrFun" 
        Field1="field1"><![CDATA[
Field1 == "foo".
      ]]></prop>
    </notify>
  </mix>
  <mix name="Slave2">
    <notify name="Slave2" 
      clients="Subr" 
      service="Sequencer" 
      fields="field1">
      <prop name="subr.spec" 
        function="SubrFun" 
        Field1="field1"><![CDATA[
Field1 == "bar".
      ]]></prop>
    </notify>
  </mix>
  <mix name="Slave3">
    <notify name="Slave3" 
      clients="Subr" 
      service="Sequencer" 
      fields="field1">
      <prop name="subr.spec" 
        function="SubrFun" 
        Field1="field1"/>
    </notify>
  </mix>
The fields of the operations were all bound to the same parameter, Field1.

The Master consume has the following three notify subroutines:

  • Slave1, which fires only if the value of field1 is "foo"
  • Slave2, which fires only if the value of field1 is "bar"
  • Slave3, which fires every time the consume is implemented

If a subroutine has no predicate, it is the same as having a predicate whose result is always true.