Coordination rules internal visit

In the 'First Steps' example, we saw that our application was not correct because a connection resource was consumed when used by a customer. This is clearly a problem... Indeed, in a normal metro network, a connection is still available even when you have used it ;-)

Correction of the problem

If we examine our trom.ls script we can see that the problem comes from the 3rd token in the performance part.

 {*,!}["Test","Customer"].rd(name,departure) &
 {*,!}["Test","Destination"].rd(name,arrival) &
 {*,!}["Test","Connection"].rd(departure,arrival)
 ::
 {
 ["Test","Customer"].get(name,departure);
 ["Test","Destination"].get(name,arrival);
 ["Test","Connection"].get(departure,arrival); <- houston we got a problem
 ["Test","Customer"].put(name,arrival) ;
 ["Test","Travel"].put(departure,arrival,name)
 }.

What we would like is for the resources contained in the Connection bag to not be physically consumed when the rule is triggered. This way, the same resource could also be used for alice and for bob.

This can be done by modifying the Coordination rule as follows:

 {*,!}["Test","Customer"].rd(name,departure) &
 {*,!}["Test","Destination"].rd(name,arrival) &
 {*,!}["Test","Connection"].rd(departure,arrival)
 ::
 {
 ["Test","Customer"].get(name,departure);
 ["Test","Destination"].get(name,arrival);
 ["Test","Connection"].rd(departure,arrival); <-------/we use a .rd() instead a .get()
 ["Test","Customer"].put(name,arrival) ;
 ["Test","Travel"].put(departure,arrival,name)
 }.

Now, in the performance phase of the rule, as the resource is only retrieved (read) from the bag but not removed (as the get operation did), it remains unchanged in the bag, thus available for any "customer" requiring it.

Save the corrected trom_1/trom.ls file (or move to the trom_2/ directory) and start the new version of the program to check the result.

From the console window, enter the following command :

python quinoa.py --go

This command combines, in the same line, the launch of the object (or all the objects of a more complex application) and the execution of all the scripts.

Now, use the monitor as described in the first lesson to inspect the content of the Test object, starting from the following URL :

http://localhost:9999/NameServer/MONITOR

| Customer| Destination| Connection| Travel| |---|---|---|---|---| | ('bob','B')| ('bob','D')| ('A','B')| ('A','D','alice')| | ('denis','D')|| ('A','D')| ('C','D','charles')| | ('alice','D')|| ('C','D')| ('A','D','denis')| | ('charles','D')|||

This time : * alice, charles and denis have reached their destinations * the Connection bag contains, in the end, the same resources as during its initialization. Our application works as expected !

Another way to correct the 'First Steps' example application is described in the next lesson.

Please stop your application before navigating to another lesson.

python quinoa.py --stop_all