ILOG JRules User Guide > Executing Rules > Tasks > Executing a Ruleset Using a Native Rule Engine > Getting Notification During Ruleset Execution

To get notification from the rule engine during ruleset execution you need to attach a notification observer to the rule engine.

To get notification from the rule engine during ruleset execution:

  1. Load the ruleset, create an engine based on the ruleset, set ruleset parameters and insert objects in the working memory, as described in steps 1, 2, and 3 of Writing a Ruleset Execution Method.
  2. Attach a notification observer to the rule engine, as follows:
// Attach an observer to the engine 
IlrToolAdapter engineObserver = new IlrToolAdapter() {
 
   // override some of the notification methods
   public void notifyAssertObject(Object object) {
      //invoked when an object is added
      System.out.println(object + " is added");
   }
 
   public void notifyRetractObject(Object object) {
      //invoked when an object is retracted
      System.out.println(object + " is retracted");
   }
 
   public void notifyBeginInstance(IlrRuleInstance instance) {
      // invoked when the engine executes a rule instance
      // with the RetePlus algorithm
      System.out.println(instance.getRuleName());
   }
 
   public void notifyBeginSequentialInstance(		
               IlrRule rule,Object[] objs,int arg) {
      // invoked when the engine executes 
      // a rule in sequential mode
      System.out.println(rule.getName());
   }
};
try {
   engine.connectTool(engineObserver);
} catch (IlrToolConnectionException e) {
   e.printStackTrace();
}
  1. Run the engine, prepare the rule engine for another execution, terminate the rule engine and free the memory, as described in steps 4 to 6 of Writing a Ruleset Execution Method.

Note
In Sequential and Fastpath modes, you should turn on debug mode when the rules are compiled, for the notification mechanism (IlrTool) to be available at runtime. To turn the debug mode on, add the following task property specification: property ilog.rules.engine.sequential.debug = true;

For information on the classes, interfaces and methods available with the JRules API, see Rule Engine API.

Related Concepts

The Engine Application Programming Interface (API)

Related Tasks

Writing a Ruleset Execution Method

Related Samples and Tutorials

Rule Engine Integration