Knowledge Seeking

Drools Fusion – What is it and how can it help us? October 14, 2010

Filed under: Drools — nicozan @ 8:39 pm

Drools Fusion is a Module from the JBoss Drools Project. The idea of this module is to put our java application into a CEP (Complex Event Processing) scenario. In this scenario we’ll be able to manage different Events that come from various entry-points such as JMS Queues, Sockets, Files, just to mention some.

In this post we won`t go too deep into the code, the target of this lines is to help you understand the concepts that the Drools Fusion Module uses.

First of all lets define our main concept: THE EVENT. An Event in drools fusion is considered a special type of fact, so we can assume every event is a fact, but not every fact is an event. As it`s seen as a special type of fact, the event has some deterministic characteristics:

Usually Inmutables: Events are record of a state change in our application domain, a record of something that already happened, and THE PAST CAN`T BE CHANGED.

Strong Temporal Constraints: Rules involving events usually require the correlation of multiple events, specially temporal correlations where events are said to happen at some point in time relative to other events.

Managed Lifecycle:Events usually will only match other events and facts during a limited window of time, making it possible for the engine to manage the lifecycle of the events automatically.

Use Of Sliding Windows: Every event has a TimeStamp associated to it, so it`s possible to use and define sliding windows over them. For example, count the number of events that happened in the last 10 minutes.

Another concept that will be useful to understand is the TimeStamp. All the events have a timestamp, Drools fusion give us the possibility to set it Implicitly or Explicitly. The first possibilty is when the event is inserted into the Session (WorkingMemory) and the timestamp is set with the Session Clock. The second one is to declare an attribute of the Object declared as an Event to be the timeStamp and has to be set by the user before is inserted into the WorkingMemory.

The Session Clock allows the engine to know what time is now. The Session Clock was designed using a strategy pattern, allowing different type of clocks to be plugged and used by the engine.  The available Clock implementations are Real Time Clock and Pseudo Clock.

  • Real Time Clock: This implementation uses internally the system clock to determine the current timestamp.
  • Pseudo Clock: An Implementation of the clock that is controlled by the application, it is very useful for testing temporal rules.

Drools Fusion has two Event Processing Modes:

  • Cloud Mode: It`s the default processing mode. In this mode the engine considers all the objects  in the working memory as facts, does not matter if they are regular facts or events, as a whole. There is no notion of time.
  • Stream Mode: It`s used when the application needs to process streams of events. Events in each stream must be time-ordered.The session clock is responsible for keeping the current timestamp, and based on it, the engine does all the temporal calculations on event’s aging, synchronizes streams from multiple sources, schedules future tasks and so on.

So this are the main concepts of  Drools Fusion, in further posts we’ll be digging into the code… 🙂