...
When a ruleset is installed in a pico, the event wrangler:ruleset_addedinstalled
is sent to the pico (because the UI does this by sending it the event wrangler:new_ruleset
, and that event raises the wrangler
event "ruleset_addedinstalled
" when the job is done).
Programmatic creation of the router pico
...
Code Block | ||
---|---|---|
| ||
ruleset bofm.main { ... rule initialize { select when wrangler ruleset_addedinstalled where rids >< meta:rid pre { bofmBase = meta:rulesetURI; bofmURL = "bofm.router.krl"; } engine:registerRuleset(bofmURL,bofmBase); fired { raise wrangler event "new_child_request" attributes { "dname": "bofm router", "color": "#87cefa", "rids": "bofm.router;io.picolabs.subscription" }; raise wrangler event "install_rulesets_requested" attributes { "rids": "io.picolabs.subscription" }; } } ... } |
...
Code Block | ||
---|---|---|
| ||
ruleset bofm.router { ... rule initialize { select when wrangler ruleset_addedinstalled where rids >< meta:rid fired { ent:consumers := {}; } } ... } |
...
A more realistic ruleset might, at least, store away the incoming verses, for some future use. This code shows one way of doing that. The rule initialize sets up a couple of maps. Notice the alternate event pico:ruleset_addedinstalled
with a slightly different where clause (in line 4). This is for backwards compatibility, for pico engines of earlier versions. The rule bofm_verse
selects when a bofm:verse
event arrives, and it reacts by handling each event, setting
the name txt
to the value of the (single) attribute and ref
to the name of the (single) attribute. Finally, it makes an entry in the ent:refs
map with the current time as the key and the verse reference as the value. It also adds an entry to the ent:txts
map with the verse reference as the key and the text of the verse as the value.
Code Block | ||
---|---|---|
| ||
ruleset bofm.consumer { rule initialize { select when wrangler ruleset_addedinstalled where rids >< meta:rid or pico ruleset_added where rid == meta:rid fired { ent:refs := {}; ent:txts := {}; } } rule bofm_verse { select when bofm verse foreach event:attrs() setting(txt,ref) fired { ent:refs{time:now()} := ref; ent:txts{ref} := txt; } } } |
...