Tutorial2 (No Rum for Two)

In Tutorial2 instead of getting yourself a beer you treat someone else to a bottle of rum. You send a message containing the field rum to SPARKL. The message, this time, is sent via a different operation to a different recipient.

The mix

The mix in Tutorial2 comprises a notify and a consume operation.

The notify operation is used to kick off the transaction in SPARKL. The service that processes the transaction, using the initial notify as its starting point, is the Sequencer service.

The Sequencing Graph is derived from all the operations in the mix.

The mix has the following components:

Sequencer
Sequencer, a service provisioned using the Sequencer extension processes the transaction starting with the initial operation.
WilliamKidd
A service that implements the consume operation. This service is provisioned using the Expressions extension.
GiveRum
An operation comprising a notify, implemented by the Sequencer.
DrinkRum
An operation comprising a consume, implemented by the WilliamKidd service.
rum
A field sent to and from the operations. The field contains data in the form of a string.

Figure: Tutorial2 - The mix


Explanation

Table 1 summarises the key components of this mix and explains their role in a transaction.

Table 1. Tutorial2 - Component roles
Component Markup Description
GiveRum
<notify 
  name="GiveRum" 
  service="Sequencer" 
  fields="rum"/>
You, again acting as a client, invoke the GiveRum notify.

The notify outputs the field rum. The Sequencer receives the field and uses the notify as the starting point of a new transaction.

DrinkRum
<consume 
  name="DrinkRum" 
  service="WilliamKidd" 
  fields="rum">
  <prop 
    name="expr.src"><![CDATA[
NewMode = "Drunk".
  ]]></prop>
</consume>

The DrinkRum consume forms a goal event which the Sequencer tries to satisfy.

The consume expects the field rum, which the Sequencer already has.

Therefore, the Sequencer demands that SPARKL invoke the DrinkRum consume.

The WilliamKidd service implements the consume and thus receives the field rum.

As the Sequencer cannot do anything else with the field it has, it discards the field and the transaction ends.

WilliamKidd
<service 
  name="WilliamKidd" 
  provision="expr">
  <prop 
    name="expr.state" 
    Mode="NewMode"/>
  <prop 
    name="expr.src"><![CDATA[
NewMode = "Sober".
  ]]></prop>
</service>
The WilliamKidd service has a state, called Mode. This state can be updated by NewMode.

When the service starts, its expr.src property initialises the service's state to Sober.

The expr.src property on the consume is used to update this state. Whenever the WilliamKidd service implements the DrinkRum consume, the service's state is changed to Drunk.