wait
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
DisplayScreenrule displays either a user-defined screen or a default screen.The rule contains two condition statements and two action statements.
The first condition matches a
Displayobject.The second condition is a
waitstatement which specifies a wait duration of5time units. This condition tests whether aUserobject is not found in the working memory within the5time units.The first action launches a
displayScreenmethod applied to the user’s response, represented by the variable?r. This statement is executed if thewaitstatement succeeds.If the
waitstatement fails, that is, aUserobject is not found in the working memory within the 5–unit time duration, the second action executes thetimeoutstatement which calls thedefaultScreenmethod.
rule DisplayScreen { when { Display(); ?to: wait 5 {User(?r:response);} } then { displayScreen(?r); timeout ?to { defaultScreen(); } } };- Example 2
In this example, the
NetworkMonitoringrule 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.
The first condition matches a
Networkobject with variable?ereturning the value of fieldelement, the fieldstatusbeing equal toaliveand the variable?mreturning the value of the fieldmaxLoad.The second condition tests that an
Alarmobject for the element referenced by variable?edoes not exist in the working memory.The third condition returns the
Trafficobject in variable?t, where the fieldelementis equal to variable?eand the variable?lreturns the value of the fieldload.The first
wait logicalstatement simply causes a wait of one time unit.The second
wait logicalstatement matches the objectTrafficwithin one time unit, as in the third condition, and the current value of the fieldload,returned in variable?l2, is verified to be less than 95% of themaxLoad, using variable?m.If the load is below this threshold, the first action statement applies a
modifystatement on objectTrafficwith the calculated derivative of the load change.If the
waitstatement fails, that is, the load is above 95% for over one time unit, thetimeoutstatement inserts anAlarmobject with the element pointed to by the variable?e, using theinsertstatement.
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
WatchDogSamplerule checks whether anAlarmexists 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.
In the first condition, the variable
?apoints to anAlarmobject with the following constraints: variable?idcontains the value of the fieldnetworkElement, the value of the fieldseverityis eitherLOWorMEDIUM, and variable?tcontains the value of the fieldtime.The second condition is a
waitstatement. This statement does not use the keywordlogical. As a consequence, the previous conditions might turn false and the rule might still succeed. Theuntilkeyword means that the expression value is an absolute time and not a relative time. Therefore, thewaitcondition must become valid by time?t+10,10time units past the value of?t. The wait condition tests for anAlarmobject with the value of the fieldnetworkElementequal to?id, the fieldseverityequal toCLEAR, and fieldtimegreater than?t. If within10time units anAlarmobject is found that fulfills these conditions, theretractaction statement is executed.The
retractstatement removes theAlarmobject pointed to by?afrom the working memory. If thewaitstatement fails, thetimeoutstatement is executed. The variable?todesignates the correspondingtimeoutstatement for thewaitstatement.The
timeoutstatement prints a messageWe have a problem with?idat 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);} } };