event (in rule actions)
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 actions.
Context
Functions or rule actions
Syntax
insert event [(timeExpression)] object [{statement1;...;statementn}];
Description
Deprecated as of V7.5.
Next
to a rule, when an object is inserted into the working memory as an
event, a timestamp is automatically associated with it. The timeExpression argument
defines an integer value which is used as the timestamp when an event
is inserted. The term object must be a constructor for the class.
For the constructor to apply, you must declare it as public in
your Java™ code.
Following the
optional timeExpression, the insert event statement
can either terminate with a semicolon (;) or specify
a block of executable statements. The statements are executed on the
object before this object is inserted into the working memory.
You
can remove an event object explicitly from the working memory by using
the retract statement or the IlrContext. IlrContext#retract method.
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?mo, and 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 naming a managed object.
The second action executes an
?operator.reportmethod that uses the event object variables?alarm1and?alarm2.
Any alarm is automatically retracted from the working memory 6 clock ticks after its insertion.