Facts

Facts are plain Java classes which rely on the Java Bean pattern. They are asserted into the working memory of the Drools engine. One or more rules may be true and is scheduled for execution by the agenda.

HubEvent

When an event is received by the Event Analytics subscriber, it is inserted into the stateful knowledge session as a HubEvent fact. A HubEvent fact cannot be changed in the rules (it is immutable) because several rules are triggered by the same fact.

After the rules are fired, the HubEvent fact is automatically retracted from working memory by Event Analytics.

There is a convenience method postEvent() to post a HubEvent back to the Event Hub albeit with another document name.

Shown is an example of a simple rule triggered by a HubEvent fact:

rule "MITMAS_20"
    no-loop
    when
        event: HubEvent(publisher == "M3", documentName == "MITMAS", operation == 
EventOperation.UPDATE, elementValues["STAT"] == "20", elementOldValues["STAT"] == "10")
    then
        event.postEvent("MITMAS_20");
end

Event

When you need to create a new event in a rule or modify a received HubEvent fact, you can use the class Event. There are convenience constructors to clone a HubEvent fact into an Event and also to clone another Event.

Shown is an example of a simple rule code to post a new event:

Event newEvent = new Event("MyEvent", EventOperation.CREATE);
        newEvent.setTrackingId(myTrackingId);
        newEvent.addElement("MyElement1", "MyElementValue1");
        newEvent.addElement("MyElement2", "MyElementValue2");
        newEvent.postEvent();

Start

A session Start fact is inserted into the stateful knowledge session when the Drools session starts and then all rules are fired. Then, the inserted session Start fact is retracted from the stateful knowledge session. A Start instance is immutable and cannot be changed.

Shown is an example of a simple rule that logs when the session is started:

rule "Start"
    when
        start : Start()
    then
        System.out.println("Session " + start.getSessionName() + " started: " + start.toString());
end

Stop

A session Stop fact is inserted into the stateful knowledge session when the Drools session stops and then all rules are fired. Then, the inserted session Stop fact is retracted from the stateful knowledge session. A Stop instance is immutable and cannot be changed.

Shown is example of a simple rule that logs when the session is stopped:

rule "Stop"
    when
        stop : Stop()
    then
        System.out.println("Session " + stop.getSessionName() + " stopped: " + stop.toString());
end

Time

A Time fact is inserted into the stateful knowledge session every minute and then all rules are fired. Then, the inserted Time fact is retracted from the stateful knowledge session. A Time instance is immutable and cannot be changed.

These are examples of some simple rules that log birthday greetings:

rule "AEBirthday"
    when
        time : Time(month == 3, day == 14, hour == 9, minute == 0)
    then
        System.out.println("Happy birthday Albert!");
end
 
rule "ALBirthday"
    when
        time : Time(month == 12, day == 10, hour == 9, minute == 0)
    then
        System.out.println("Happy birthday Ada!");
end