Information Technology Reference
In-Depth Information
Value definitions introduce event and fact names. Rule r 1 formalizes that if a
grant ( t, r ) is observed, and no Granted ( t, r ) fact exists in the fact memory
(with the same task t and resource r ), then a Granted ( t, r )factisinserted
in the fact memory to record that the grant event occurred. Rule r 2 expresses
that if a Granted ( t, r ) fact exists in the fact memory, and a release event occurs
with matching arguments, then the Granted fact is removed. The remaining
rules express the error situations - r 3 : granting an already granted resource, r 4 :
ending monitoring with a non-released resource, and r 5 : releasing a resource not
granted to the releasing task. LogFire allows to write any Scala code on the
right-hand side of a rule, just as any Scala definitions are allowed in LogFire
monitors, including local variables and methods. We can create an instance of
this monitor and submit events to it (not shown here), which then get verified
for conformance with the rules. Any errors will be documented with an error
trace illustrating what events caused what rules to fire.
2.2 Meaning
Each rule definition in the class ResourceProperties is effectively a method call,
or rather: a chain of method calls (commonly referred to as method chaining ),
whichgetcalledwhentheclass gets instantiated (a Scala class body can contain
statements). Note that Scala allows to omit dots and parentheses in method
calls. As an example, the definition of rule r 2 is equivalent to the statement:
R( r2 ).
−−
(C('Granted)('t, 'r)).&(C('release)('t, 'r )).
| > {
remove('Granted)
}
The functions R (standing for Rule )and C (standing for Condition )areso-
called implicit functions . An implicit function in Scala is defined as part of the
program (in this case in the class Monitor ), but is not explicitly called. Such
functions are instead applied by the compiler in cases where type checking fails
but where it succeeds if one such (unique) implicit function can be applied. In the
statement above we have inserted them explicitly for illustration purposes, as the
compiler will do. The function R takes a string as argument and returns an object
of a class, which defines a function -- , which as argument takes a condition, and
returns an object, which defines a method & , which takes a condition, and returns
an object defining a method |-> ,whichtakesaScala statement (passed call
by name, hence not yet executed), and finally creates a rule internally.
Creating the rules internally means building the Rete network as an internal
data structure in the instantiated ResourceProperties object, representing the
semantics of the rules. Figure 1 illustrates the network created by the definitions
of rules r 2 , r 3 ,and r 4 (rules r 1 and r 5 contain negated conditions which are
slightly complicated, and therefore ignored in this short exposition). When events
and facts are added to the network, they sift down from the top. For example,
a Granted (7 , 32) event will end up in the lower grey buffer, from which three
join nodes lead to different actions depending on what the next event is: release ,
grant ,or end . The join nodes perform matching on arguments.
 
Search WWH ::




Custom Search