<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Filip_Drools_Fusion</id>
	<title>Filip Drools Fusion - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Filip_Drools_Fusion"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Filip_Drools_Fusion&amp;action=history"/>
	<updated>2026-05-13T23:42:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Filip_Drools_Fusion&amp;diff=39732&amp;oldid=prev</id>
		<title>Filip Stachecki: /* CEP example */</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Filip_Drools_Fusion&amp;diff=39732&amp;oldid=prev"/>
		<updated>2016-08-23T08:17:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;CEP example&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|Drools Filip|090}}&lt;br /&gt;
&lt;br /&gt;
== What is Drools Fusion ==&lt;br /&gt;
* module responsible for enabling event processing behaviour&lt;br /&gt;
[[File:ClipCapIt-160802-211428.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Event ==&lt;br /&gt;
* An event is a fact + information about time of occurence&lt;br /&gt;
* Events are a record of a significant change of state in the application domain e.g. change of the price, booking form arrival&lt;br /&gt;
* Rules involving events usually require the correlation of multiple events&lt;br /&gt;
&lt;br /&gt;
Drools supports the declaration and usage of events with both point-in-time events and interval-based events semantics.&lt;br /&gt;
&lt;br /&gt;
=== Declaring a fact type as an event===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
declare StockTick&lt;br /&gt;
    @role( event )&lt;br /&gt;
    @timestamp(whenReceived)&lt;br /&gt;
    @duration(howLong)&lt;br /&gt;
    @expires(1h20m)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* @role (required) defines how the engine should handle instances of that type: either as regular facts or as events&lt;br /&gt;
* @timestamp (optional) defines the moment when the event took place. If not present, the timestamp of each event instance will be the moment it was inserted into the working memory.&lt;br /&gt;
* @duration (optional) specifies the duration of the event&lt;br /&gt;
* @expires (optional)  specifies  how long this type of event should be present in the working memory before automatic deletion&lt;br /&gt;
&lt;br /&gt;
== CEP ==&lt;br /&gt;
* Complex Event Processing (CEP) - focuses on correlating and composing of atomic events into complex (compound) events&lt;br /&gt;
* Wikipedia Definition of CEP: &lt;br /&gt;
:&amp;quot;CEP is event processing that combines data from multiple sources to infer events or patterns that suggest more complicated circumstances&lt;br /&gt;
&lt;br /&gt;
:The goal of complex event processing is to identify meaningful events (such as opportunities or threats) and respond to them as quickly as possible.&amp;quot;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Event Processing Modes ==&lt;br /&gt;
=== Stream Mode ===&lt;br /&gt;
* The STREAM processing mode is the mode of choice when the application needs to process &amp;#039;&amp;#039;&amp;#039;streams of events&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
* When using the STREAM, the engine knows the concept of &amp;#039;&amp;#039;&amp;#039;flow of time&amp;#039;&amp;#039;&amp;#039; and the concept of &amp;quot;&amp;#039;&amp;#039;&amp;#039;now&amp;#039;&amp;#039;&amp;#039;&amp;quot;, i.e., the engine understands how old events are based on the current timestamp read from the Session Clock.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CEP example===&lt;br /&gt;
source: Salatino, De Maio, Aliverti, Mastering JBoss Drools 6&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
declare SuspiciousCustomerEvent&lt;br /&gt;
    @role(event)&lt;br /&gt;
    customerId: Long&lt;br /&gt;
    reason: String&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
rule &amp;quot;More than 10 transactions in an hour from one client&amp;quot;&lt;br /&gt;
    when&lt;br /&gt;
        $t1: TransactionEvent($cId: customerId)&lt;br /&gt;
        Number(intValue &amp;gt;= 10) from accumulate(&lt;br /&gt;
            $t2: TransactionEvent(&lt;br /&gt;
                this != $t1, &lt;br /&gt;
                customerId == $cId, &lt;br /&gt;
                this meets[1h] $t1&lt;br /&gt;
            ),&lt;br /&gt;
            count($t2)&lt;br /&gt;
        )&lt;br /&gt;
        not (SuspiciousCustomerEvent(customerId == $cId, reason == &amp;quot;Many transactions&amp;quot;))&lt;br /&gt;
    then&lt;br /&gt;
        insert(new SuspiciousCustomerEvent($cId, &amp;quot;Many transactions&amp;quot;));&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The meets evaluator correlates two events and matches when the current event&amp;#039;s end timestamp happens at the same time as the correlated event&amp;#039;s start timestamp.&lt;br /&gt;
** $eventA : EventA( this meets $eventB ) &lt;br /&gt;
* it means: abs( $eventB.startTimestamp - $eventA.endTimestamp ) == 0 &lt;br /&gt;
* The meets evaluator accepts one optional parameter. If it is defined, it determines the maximum distance between the end timestamp of current event and the start timestamp of the correlated event in order for the operator to match. Example:&lt;br /&gt;
** $eventA : EventA( this meets[ 5s ] $eventB ) &lt;br /&gt;
* Will match if and only if: abs( $eventB.startTimestamp - $eventA.endTimestamp) &amp;lt;= 5s&lt;br /&gt;
&lt;br /&gt;
== Example and Exercises ==&lt;br /&gt;
# See examples in the code&lt;br /&gt;
# Write a code which would turn the splrnkler on 10 sec after detecting the fire&lt;br /&gt;
# Write HeartBeat implementation (i.e. if there is no signal for 10 sec, fire the rule)&lt;/div&gt;</summary>
		<author><name>Filip Stachecki</name></author>
	</entry>
</feed>