svc_expr properties

The Expressions extension supports the use of Erlang expressions in SPARKL.

expr.auto

Use this property to specify how many times, and how frequently a notify is triggered by the svc_expr service. If this property is not specified, default values apply.

<notify name="myNotify"  
  service="Sequencer"  
  clients="Expr"  
  fields="PING">  
  <prop name="expr.auto"    
    interval="5s"    
    count="4"/>    
</notify>

count

The total times the notify is triggered.

Table 1. Attribute values
Value Description
"-1" The default value. The notify is triggered an unlimited number of times.
"0" The notify is never triggered.
"n" The notify is triggered an "n" number of times.

interval

The time between each triggering of the notify.

Table 2. Attribute values
Value Description
"30s" This is the default value. The notify is triggered every 30 seconds.
"n" The notify is triggered every "n" seconds.
"n<timeunit>" The notify is triggered every "n" time unit specified. Supported time units, besides seconds, are:
  • milliseconds(ms)
  • minutes(m)
  • hours(h)

expr.init

Use this property to give variables an initial value. Depending on their use, the variables can be state or static variables.

<service 
  name="Bartender" 
  provision="expr">
  <prop 
    name="expr.init" 
    GinsServed="0"/>
  <prop 
    name="expr.state" 
    GinsServed="NewGinsServed"/>
</service>
Tip: An expression in expr.src can also initialise a state variable. For example, NewFoo = 0. This leads to a state change, as opposed to using expr.init, with the attribute Foo="0".

expr.init.[Var]

Use this property to contain variables that are longer Erlang terms, such as maps #{...}, and lists [...].

The expr.init property is appended with the name of the variable.
<service 
  name="Database" 
  provision="expr">
  <prop name="expr.init.Table"
    content-type="text/x-erlang"><![CDATA[
#{
  0 => "Foo",
  1 => "Bar"}
  ]]></prop>
</service>
Important: Do not use a full stop at the end of the term, like in the case of expressions contained in expr.src.
Tip: To get syntax highlighting, use the content-type="text/x-erlang" attribute.

expr.src

Use this property to add Erlang expressions either to a service or an operation. The content is rendered as a CDATA section.

<request name="AddUp"
  service="Math"
  fields="n m">
  <prop name="expr.src"
    content-type="text/x-erlang"><![CDATA[
% Add up the field values using a function of the Math service.
Value = AddUpFun(get("n"), get("m")),
                  
% Assign the result to the value field.
put("value", Value),
                  
% Send the Ok reply.
"Ok".
  ]]></prop>
  <reply name="Ok"
    fields="value"/>
</request>

Use the built-in Erlang functions put/2 and get/1 to access or manipulate the values carried in the SPARKL fields.

Important: The expressions list must end with a full stop.

expr.state

Use this property on a service to define state variables and other state variables that update them. Use it on a notify operation to trigger it on a particular state change.

<mix name="Mix">
  <field name="count"  
    type="integer"/>
  <field name="INCREMENT"/>  

  <service name="Expr"  
    provision="expr">  
    <prop name="expr.state"    
      Count="NewCount"/>  
    <prop name="expr.init"
      Count = "0"/>
  </service>  

  <request name="Increment"  
    service="Expr"  
    fields="INCREMENT">  
    <prop name="expr.src"
      content-type="text/x-erlang"><![CDATA[
  put("count", Count),
  NewCount = Count + 1,
  "Ok".  
    ]]></prop>  
    <reply name="Ok"    
      fields="count"/>
  </request>
</mix>
Note: Variable names must start with a capital letter.