JBoss.orgCommunity Documentation

Chapter 2. Drools Fusion Features

2.1. Events
2.1.1. Event Semantics
2.1.2. Event Declaration
2.1.3. Event Metadata
2.2. Session Clock
2.2.1. Available Clock Implementations
2.2.2. How to implement new Clocks
2.3. Streams Support
2.3.1. Streams of Events
2.3.2. Declaring and Using Streams
2.4. Temporal Reasoning
2.4.1. Temporal Operators
2.4.2. Available Temporal Operators
2.5. Event Processing Modes
2.5.1. Cloud Mode
2.5.2. Stream Mode
2.6. Sliding Windows
2.6.1. Sliding Time Windows
2.6.2. Sliding Length Windows
2.7. Rulebase Partitioning
2.7.1. Multithreading management
2.7.2. When partitioning is useful
2.7.3. How to configure partitioning
2.8. Memory Management
2.8.1. Explicit expiration policy
2.8.2. Inferred expiration policy
2.8.3. How expiration policy is implemented
2.9. Examples

Events, from a Drools perspective are just a special type of fact. In this way, we can say that all events are facts, but not all facts are events. In the next few sections the specific differences that characterize an event are presented.

An event is a fact that present a few distinguishing characteristics:

Drools supports the declaration and usage of events with both semantics: point-in-time events and interval-based events.

All events have a set of metadata associated to them. Most of the metadata values have defaults that are automatically assigned to each event when they are inserted into the working memory, but it is possible to change the default on an event type basis, using the metadata tags listed bellow.

For the examples, lets assume the user has the following class in the application domain model:


Reasoning over time requires a reference clock. Just to mention one example, if a rule reasons over the average price of a given stock over the last 60 minutes, how the engine knows what stock price changes happened over the last 60 minutes in order to calculate the average? The obvious response is: by comparing the timestamp of the events with the "current time". How the engine knows what time is now? Again, obviously, by querying the Session Clock.

The session clock implements a strategy pattern, allowing different types of clocks to be plugged and used by the engine. This is very important because the engine may be running in an array of different scenarios that may require different clock implementations. Just to mention a few: