Subroutines pattern

Subroutines can be used to construct a complex mix. A request or consume operation of a mix can be matched to another solicit or notify operation that starts a subroutine transaction.

In the example in Table 1, there are two mixes, both in the same configuration tree. A request/reply calls on a subroutine transaction.

Table 1. svc_subr - Subroutines
Example Description
<folder name="Folder">
  <service name="Subr" provision="subr"/>
  <mix name="Mix">
    <field name="a" type="string"/>
    <field name="b" type="integer"/>
    <request name="myRequest" 
      fields="a" 
      service="Subr">
      <prop name="subr.spec" 
        function="MyFun"/>
      <prop name="params"><![CDATA[
param1:a
      ]]></prop>
      <reply name="Ok" fields="b">
        <prop name="params"><![CDATA[
param2:b
        ]]></prop>
      </reply>
    </request>
  </mix>
  
  <mix name="Mix2">
    <field name="x" type="string"/>
    <field name="y" type="integer"/>
    <solicit name="mySolicit" 
      clients="Subr" 
      fields="x"  
      service="Sequencer">
      <prop name="subr.spec" 
        function="MyFun"/>
      <prop name="params"><![CDATA[
param1:x
      ]]></prop>
      <response name="Ok" 
        fields="y">
        <prop name="params"><![CDATA[
param2:y
        ]]></prop>
      </response>
    </solicit>
  </mix>
</folder>
The request/reply can call on the subroutine solicit/response, that starts a subroutine transaction, because:
  1. The same svc_subr service supports the request/reply and is a client on the solicit/response
  2. The response and the reply are both named Ok
  3. The operations both have a subr.spec property that specifies the same function: MyFun.
  4. Each pair of input/output fields are mapped to the same parameters:
    • param1 is mapped to a and x, both of type string
    • param2 is mapped to b and y, both of type integer
    Important: If the parameterised fields are not of the same type, the value is cast using the sse_type_util:coerece/2 function.