Rulesare the heart of the Rule Engine. In rules you specify the condition and then the execution part of the condition. Below is the syntax of the rule in drools:
Facts. It can be a simple Java POJO or a complex object. Java object is synonyms to facts in Drools
Knowledge Sessionin Drools is the core component in which rules are fired. The knowledge session holds all the rules and other resources.
Knowledge Sessionis created from the
KnowledgeBase. To trigger the rules, facts are inserted into the session and when a condition of a particular rule is met, the subsequent rule gets fired.
Sessionis of two types:
a) Stateless KnowledgeSession : A Stateless knowledge session won't track the changes in the facts while the rules are being fired. In simple words once we have inserted all the facts in the session and triggered all the rules then the rules cannot be fired on the updated facts. To draw a parallel, it would be similar like a web application where we are not tracking the session.
b) Stateful Knowledge Session : In a Stateful knowledge session, once all the facts are inserted and rules are triggered and one rule is updating the fact and post the updation of fact another rule can also trigger as the fact is still in the session. Its similar where in a web application until the session is active all the items you add to the cart are visible.
Droolsthese are commonly referred to as knowledge definitions or knowledge
Activationsare placed in the agenda where the appropriate rule is fired.