To fire all the rules that match the given input data, you need to use the `fireAllRules` method provided by the KIE engine. Here's an example of how you can achieve this:
```java
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
public class RulesFiringExample {
public static void main(String[] args) {
// Load the KIE base and session
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieContainer.newKieSession();
// Create the input object
ActualPrice actualPrice = new ActualPrice();
actualPrice.setCustomer("ramanathan");
actualPrice.setDiscount("15");
// Insert the input object into the session
kieSession.insert(actualPrice);
// Fire all the rules
kieSession.fireAllRules();
// Print the updated object
System.out.println("Actual Price: " + actualPrice.getActualPrice());
System.out.println("Coupon: " + actualPrice.getCoupon());
// Dispose the session
kieSession.dispose();
}
}
```
In this example, we first load the KIE base and create a new KIE session. Then, we create an instance of the `ActualPrice` class and set the customer and discount values.
Next, we insert the `ActualPrice` object into the KIE session using the `insert` method. This makes the object available for pattern matching in the rules.
After that, we call the `fireAllRules` method, which will fire all the rules that match the inserted object. This method will continue firing rules until no more rules can be fired (a fixed-point is reached).
Finally, we print the updated values of the `ActualPrice` object and dispose of the KIE session.
When you run this code with the input `customer = "ramanathan"` and `discount = "15"`, it should fire all the rules that match this input and print the final values of `actualPrice` and `coupon` after applying all the matching rules.
Note that the order in which the rules are fired is not guaranteed, as the rule engine uses an optimized algorithm to determine the firing order based on the input data and rule conditions.
Thanks and Regards!!!
Ajay C. Kandula