Reference > Rule Languages > ILOG Rule Language > IRL Keywords > event (in rule actions)

Summary

A statement for declaring an event condition or an event object. This keyword is used in rule actions or functions.

Syntax

insert event [(timeExpression)] object [{statement1;...;statementn}];

Description

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.

Example

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:

There are two action statements:

Any alarm will be automatically retracted from the working memory 6 clock ticks after its insertion.

See Also

after, before, occursin, timeof