| Reference > Rule Languages > ILOG Rule Language > IRL Keywords > event (in rule actions) |
event (in rule actions) |
PREVIOUS NEXT |
A statement for declaring an event condition or an event object. This keyword is used in rule actions or functions.
insert event [(timeExpression)] object [{statement1;...;statementn}];
On the right-hand side of a rule, when an object is inserted into the working memory as an event, a timestamp is automatically associated with it. The timeExpression defines an integer value that is used as the timestamp when inserting an event. The term object must be a constructor for the desired class. To allow ILOG JRules to apply the constructor, you must declare it as public in your Java code.
The desired class may implement the IlrEvent interface. If the IlrEvent interface is not implemented, the IlrDefaultEvent class is used whenever an event object is added to the working memory.
Following the optional TimeExpression, the insert event statement may either terminate with a semicolon (;) or specify a block of executable statements. The statements are executed on the object before being inserted into the working memory.
An event object can be explicitly removed from the working memory using the retract statement or with the API method IlrContext.retract.
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 alarmManager rule prints a message when two alarms occur on the same managed object with a time difference between 1 and 5 clock ticks.
The rule contains four conditions:
?mo is matched by a ManagedObject object.
Operator objects in the variable ?operator.
?alarm1 points to an event object named Alarm with a single constraint: the value of the field managedObject is equal to the variable ?mo.
?alarm2 points to an event object named Alarm with the following constraints: the value of the field managedObject is 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.
There are two action statements:
?operator.report method using the event object variables ?alarm1 and ?alarm2.
Any alarm will be automatically retracted from the working memory 6 clock ticks after its insertion.
after, before, occursin, timeof
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |