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.
Value | Description |
---|---|
|
The default value. The notify is triggered an unlimited number of times. |
|
The notify is never triggered. |
"n" |
The notify is triggered an "n" number of times. |
interval
The time between each triggering of the notify.
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:
|
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>
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
[...]
.
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>
expr.src
.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.
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>