Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: (Classic)

...

The component labeled the “personal data manager” (PDM) in Foursquare post is a perfect, small example of a PCOS service. The PDM service uses a combination of rules, functions, and entity variables to create an effective service for storing simple elements of personal data. Beyond simple storage, however, the service acts as a full-fledged actor in personal cloud because it listens for and emits relevant events. We review the design of the prototype PDM service below.  

PCOS Service Principles

To understand the pattern more fully, here are a few principles that guide service development and operation:

...

The key to understanding how a PCOS service is implemented in KRL is to realize that KRL rulesets create entity-specific closures over the persistent data declared within. Thus the rules and functions declared in the ruleset implementing the service automatically have access to a bundle of state for whichever user the service is running for.

PDM as a PCOS Service

Let’s review the design of the PDM service to see how this works. The PDM service has a rule, add_location_item, that is used to add a new location waypoint for the user. Theadd_location_item rule listens for the pds:new_location_available event.

Code Block
languagejavascript
themeConfluencelanguagejavascript
rule add_location_item {
  select when pds new_location_available
  always {
    set ent:location{event:attr("key")} 
        event:attr("value");
    log "Saw " + event:attr("key") + " data";
    raise pds event new_location_item_added 
      with key = event:attr("key");
  }
}

...

Later, this item can be used by other applications through the get_location() function:

Code Block
languagejavascript
themeConfluencelanguagejavascript
meta {
  name "Personal Data Manager"
  provides get_location
}

global { 
  get_location = function (k) {
    ent:location{k};
  };
}

...