event (in rule conditions)

The 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, or occursin.

    • To express temporal constraints between two events, use the after and before operators.

    • To express a temporal constraint on a single event, use the occursin operator. An occursin test 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:

  1. In the first condition, a variable ?mo is matched by a ManagedObject object.

  2. The second condition returns the subscribed Operator objects in the variable ?operator.

  3. The third condition is an event statement. The variable ?alarm1 points to an event object named Alarm with a single constraint: the value of the field managedObject is equal to the variable ?mo.

  4. The fourth condition is also an event statement, where the variable ?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.

The then keyword introduces two actions:

  1. The first action prints a message that names a managed object.

  2. The second action executes an ?operator.report method using the event object variables ?alarm1 and ?alarm2.

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