I want to share some more tips and more realistic data and rules scenarios.

Netbeans
: If you run the java file (Run File)with the sample code instead of running the whole application, the resources and NOT rebuild, means any changes made to the rules would not be reflected. So rither Cleand and Build or run the application then resources are rebuild automatically.

Threads:
In the first sample
we did not use a separate thread to fire the rules. If you update or insert facts after the initial ksession.fireAllRules()
you will not see any output from the engine, only if you call it again. I recommend the thread approach with ksession.fireUntilHalt()
as shown in the last tutorial
.

Container
: A simple java application might be good enough for the first steps, but more realistic is the execution in a web application running in a container. I will post a separate tutorial how to run the rule engine inside a singleton EJB on Glassfish.

Rule samples and code snippets: Managing Flights and Times
The previous samples with message instances are not close to anything realistic, so I create a little airport scenario. It wont be able to run an airport’s operations but gives an idea. I skip the basic initialization etc. We will use the pseudo clock.

Arriving flights usually have this or similar sequence of events: Scheduled Time (STOA) – Estimated (ETOA) – Landed/Touchdown (LAND) – OnBlock Time (ONBL)
(in real operations you will have more events, also from different sources)

Rule 1
: Alert me if the ETOA
(often coming from automated interfaces like ATC or IATA Telex messages from the origin airport of the flight) is more than 30min
after scheduled arrival time STOA
(maybe to inform public at the airport)

Rule 2
: Alert me if the time between LAND
and ONBL
is more than 5min
.

The rule does not make much operational sense, because you want to warn someone that the aircraft is still not at the position after minutes on the ground, means it is still taxiing and you want to inform the ground crew about itRule 2b
: Alert me if there is noONBL5min
after the LAND
event.

Challenge for now: The engine looks at the timestamp of fact insertion, so I cant backdate my timestamps, which would be necessary if you get delayed updates from an interface.
Eg. at 02:00 you get LAND with timestamp 01:00 you would expect the rule to be triggered at 06:00 (01:00 + 5min) but it gets triggered at 07:00
Will explore Fusion further to cover this situation.