wait

The wait keyword incorporates time as a rule parameter.

Purpose

This keyword is used in the condition part of rules to add time as a rule parameter.

Context

Rule conditions

Syntax

(1) wait [[until] expression] {condition}; 
(2) wait logical [[until] expression] [{condition}]; 
(3) ?variable
: wait [logical] [until] expression {condition}
              ... 
         then ... 
             timeout ?variable {action} 

Description

Deprecated as of V7.5.

Use the wait statement in the condition part of rules to test whether conditions become valid during a specified waiting period or whether conditions remain true for a waiting period. The waiting period or time frame can be an absolute time or a specific duration relative to the current time. If you provide no expression parameter, the wait is indefinite.

The wait statement creates a timer that delays the execution of a rule. You can include multiple timers in a rule and, optionally, a timeout statement for each timer.

In syntaxes (2) and (3), the logical keyword is used to specify that the previously realized conditions must remain true for the wait statement to become true. If the logical keyword is not used, all the previously realized conditions are ignored, that is, they might become false during the waiting period and the wait statement might succeed.

The keyword until is used to designate that the expression specifies an absolute time by which the wait statement must succeed. If until is not used, the expression specifies a relative time, that is, a specific duration as the waiting period. The expression must return an integer value.

The wait statement (3) might include a timeout statement that is part of the action part of a rule. If the wait statement fails, the timeout statement is executed.

The rule engine has a time counter that is updated by the application according to the application requirements. The initial value of the time counter is 0.

You can synchronize the time counter of the rule engine with an external clock by using the following methods of IlrContext:

  • The IlrContext#time() method returns the current time.

  • The IlrContext#nextTime() method increments time by 1.

  • The IlrContext#nextTime(long%20increment) method increments time by the specified increment.

  • The IlrContext#setTime(long%20time) method sets time to a specified time.

    Note:

    It is the developer’s responsibility to synchronize the time counter with any external clock according to the application requirements.

Example

Example 1

In this example, the DisplayScreen rule displays either a user-defined screen or a default screen.

The rule contains two condition statements and two action statements.

  1. The first condition matches a Display object.

  2. The second condition is a wait statement which specifies a wait duration of 5 time units. This condition tests whether a User object is not found in the working memory within the 5 time units.

  3. The first action launches a displayScreen method applied to the user’s response, represented by the variable ?r. This statement is executed if the wait statement succeeds.

  4. If the wait statement fails, that is, a User object is not found in the working memory within the 5–unit time duration, the second action executes the timeout statement which calls the defaultScreen method.

rule DisplayScreen {
   when {
      Display();
      ?to: wait 5 {User(?r:response);}
   }
   then {
      displayScreen(?r); 
      timeout ?to { defaultScreen(); }
   }
};
Example 2

In this example, the NetworkMonitoring rule checks the traffic load of network elements and inserts an alarm if an element load passes 95% of its maximum load value.

This rule contains six condition statements and two action statements.

  1. The first condition matches a Network object with variable ?e returning the value of field element, the field status being equal to alive and the variable ?m returning the value of the field maxLoad.

  2. The second condition tests that an Alarm object for the element referenced by variable ?e does not exist in the working memory.

  3. The third condition returns the Traffic object in variable ?t, where the field element is equal to variable ?e and the variable ?l returns the value of the field load.

  4. The first wait logical statement simply causes a wait of one time unit.

  5. The second wait logical statement matches the object Traffic within one time unit, as in the third condition, and the current value of the field load, returned in variable ?l2, is verified to be less than 95% of the maxLoad, using variable ?m.

  6. If the load is below this threshold, the first action statement applies a modify statement on object Traffic with the calculated derivative of the load change.

  7. If the wait statement fails, that is, the load is above 95% for over one time unit, the timeout statement inserts an Alarm object with the element pointed to by the variable ?e, using the insert statement.

rule NetworkMonitoring {
   when {
      Network(?e:element; status == alive; ?m:maxLoad);
      not Alarm(?e);
      ?t:Traffic(element == ?e; ?l:load );
      wait logical 1;
      ?a:wait logical 1 {Traffic(element == ?e; ?l2:
      load && ?l2 < 0.95*?m);}
   }
   then {
      modify ?t {?t.derivative = ?l2-?l}
      timeout ?a  {insert Alarm(?e);}
   }
}
Example 3

The WatchDogSample rule checks whether an Alarm exists for a network element and tests whether the problem is regulated within 10 time units.

This rule contains two condition statements and two action statements.

  1. In the first condition, the variable ?a points to an Alarm object with the following constraints: variable ?id contains the value of the field networkElement, the value of the field severity is either LOW or MEDIUM, and variable ?t contains the value of the field time.

  2. The second condition is a wait statement. This statement does not use the keyword logical. As a consequence, the previous conditions might turn false and the rule might still succeed. The until keyword means that the expression value is an absolute time and not a relative time. Therefore, the wait condition must become valid by time ?t+10, 10 time units past the value of ?t. The wait condition tests for an Alarm object with the value of the field networkElement equal to ?id, the field severity equal to CLEAR, and field time greater than ?t. If within 10 time units an Alarm object is found that fulfills these conditions, the retract action statement is executed.

  3. The retract statement removes the Alarm object pointed to by ?a from the working memory. If the wait statement fails, the timeout statement is executed. The variable ?to designates the corresponding timeout statement for the wait statement.

  4. The timeout statement prints a message We have a problem with ?id at time: ?t.

rule WatchDogSample {
   when {
      ?a: Alarm(?id:networkElement; severity == LOW || 
                 severity == MEDIUM; ?t:time;)
      ?to: wait until ?t+10 {Alarm(networkElement == ?id; 
                 severity == CLEAR; time > ?t);}
   }
   then {
      retract ?a;
      timeout ?to {
          System.out.println("We have a problem with "
                             + ?id " at time: " +?t);}
   }
};