Information Technology Reference
In-Depth Information
rules added to the KIE session configuration). We will now concentrate on the extra fea-
tures needed to configure temporal-based rules for our runtime.
The first consideration that we need to take into account is a special configuration we
need to add to the KIE base that we build our KIE session from, to be able to manage the
concept of now (used for sliding windows) and get an understanding of events as such, in-
stead of just facts. This special configuration is called the STREAM mode, and by de-
fault, the rule engine works in the CLOUD mode. The STREAM mode provides a way
for the engine to understand the concept of time and events and keep a reference of when
are events added to the rule engine memory. The CLOUD mode doesn't understand these
concepts and treats all elements added to the rule engine memory as simply facts, with no
temporal data associated to them. The STREAM mode can be configured to the KIE base
programmatically as follows:
KieServices ks = KieServices.Factory.get();
KieBaseConfiguration kbconf =
ks.newKieBaseConfiguration();
kbconf.setOption(EventProcessingOption.STREAM);
KieBase kbase =
ks.getKieClasspathContainer().newKieBase(kbconf);
The KIE base can also be configured through the kmodule.xml file with the
eventProcessingMode attribute of the kbase tag. Please refer to the process-
cep-examples project to see a full example of such a configuration.
Another configuration item, related in this case to the KIE session object, is the clock
type. By default, the KIE session will understand how much time goes by between events
by the internal clock of the computer it is running in. This might be good for productive
environments, but it is definitely problematic for rule testing purposes.
During a test, we might want to debug our code, and if we depend on the internal clock of
the computer to determine time correlations, we might find ourselves breaking rule condi-
tions by debugging the code. Also, if we want to test a rule that correlates two events with
a big time difference between insertions, we would need a lot of time to test it.
In order to avoid this problem, the KIE session can be configured to run with a pseudo
clock , that is, an implementation which will have to be advanced at will. In order to con-
figure it, you can use the following code:
Search WWH ::




Custom Search