event (in rule conditions)
event keyword declares an event condition
or an event object.
Purpose
This keyword is used for declaring an event condition or an event object in rule conditions.
Context
Rule conditions
Syntax
[?var:] event className (test1;...;testn);
where a temporal test test i has the form:
{after|before|occursin} [interval]
Description
Deprecated as of V7.5.
On the side of a rule, an event condition can be bound to a variable. The event class name is defined in the statement together with tests.
Tests can be temporal or nontemporal.
In a temporal test, you can use the following keywords: The interval, when provided, restricts the allowed delay between the events.
To express a temporal constraint, use the test operators
after,before, oroccursin.To express temporal constraints between two events, use the
afterandbeforeoperators.To express a temporal constraint on a single event, use the
occursinoperator. Anoccursintest is satisfied if the timestamp of the event is included in the interval.
Do not write references to bound variables or in other event conditions in the expression. The expression is evaluated once, when the events occurring as operands of the temporal constraint operator are inserted.
You can combine nontemporal tests and temporal constraints as shown in the following code lines:
?a: event Alarm(); ?b: event Alarm(sev >= HIGH || ?this after[1,5] ?a);
Example
The alarmManager rule
prints a message when two alarms occur on the same managed object
with a time difference between 1 and 5 clock ticks.
rule alarmManager {
when {
?mo: ManagedObject();
?operator: Operator() in ?mo.subscribers();
?alarm1: event Alarm(managedObject == ?mo);
?alarm2: event Alarm(managedObject == ?mo; ?this after[1, 5]
?alarm1);
}
then {
System.out.println("Seen two alarms on " + ?mo.name);
?operator.report(?alarm1, ?alarm2);
}
}The when keyword
introduces four conditions:
In the first condition, a variable
?mois matched by aManagedObjectobject.The second condition returns the subscribed
Operatorobjects in the variable?operator.The third condition is an event statement. The variable
?alarm1points to an event object namedAlarmwith a single constraint: the value of the fieldmanagedObjectis equal to the variable?mo.The fourth condition is also an event statement, where the variable
?alarm2points to an event object namedAlarmwith the following constraints: the value of the fieldmanagedObjectis equal to the variable?moand the difference between the first event object timestamp and the second event object timestamp is greater than, or equal to, 1 and less than, or equal to, 5 clock ticks.
The then keyword
introduces two actions:
The first action prints a message that names a managed object.
The second action executes an
?operator.reportmethod using the event object variables?alarm1and?alarm2.
Any alarm is automatically retracted from the working memory 6 clock ticks after its insertion.