Overview of Results Examples Using External Resources to Obtain Results

4-4 Oracle Fusion Middleware Language Reference Guide for Oracle Business Rules

4.7 Obtaining Results from a Rule Enabled Program

When you create a a rule enabled program with Oracle Business Rules, a common question is, How do I get the results of the evaluation? This section one approaches to extracting or exposing results of rule evaluation from the rule engine. This section covers the following: ■ Overview of Results Examples ■ Using External Resources to Obtain Results

4.7.1 Overview of Results Examples

The examples in this section show a highway incident notification system. These examples show the different approaches to access the results of rule engine evaluation. The examples use two Java classes: traffic.TrafficIncident and traffic.IncidentSubscription. The TrafficIncident class represents information about an incident affecting traffic and contains the following properties: ■ Which highway ■ Which direction ■ Type of incident ■ Time incident occurred ■ Estimated delay in minutes The IncidentSubscription class describes a subscription to notifications for incidents on a particular highway and contains the following properties: ■ Subscriber - the name of the subscriber ■ The highway ■ The direction In the example using these classes, when an incident occurs that affects traffic on a highway, a TrafficIncident object is asserted and rule evaluation determines to whom notifications are sent. In the examples, the sess object is a RuleSession and a number of incident subscriptions are asserted. As a simplification, it is assumed that the TrafficIncident objects are short lived. They are effectively an event that gets asserted and only those subscribers registered at that time are notified. The classes in these examples are all Java classes. However, it is possible to manipulate instances of RL classes in Java using the RL class reflection. See Also: Working with Rules SDK Decision Point API in the Oracle Business Rules Users Guide Note: The traffic. sample classes are not included in the Oracle Business Rules distribution. Using a RuleSession 4-5

4.7.2 Using External Resources to Obtain Results

This approach is similar to asserting a container for results, except that instead of a container, the object is a means to affecting resources external to the rules engine. For example, this could involve queuing up or scheduling work to be done, updating a database, sending a message. Any Java method accessible in the action may be invoked to effect the results. As with the container use case, the objects used in this example to access the external resources are not re-asserted since their content is not being reasoned on. Example 4–1 shows the IncidentDispatcher object that is asserted and then used to dispatch the notification. Example 4–1 Obtaining Results Using External Resources rule incidentAlert { if fact TrafficIncident ti fact IncidentSubscription s s.highway == ti.highway s.direction == ti.direction fact IncidentDispatcher dispatcher { dispatcher.dispatchs.subscriber, ti; } } Example 4–2 shows Java code that asserts an IncidentDispatcher and a TrafficIncident, and then invokes the rule engine. This could also be accomplished using an object that is being reasoned on, but this would require a test in the rule condition to avoid an infinite loop of rule firing. Example 4–2 Sample Showing Results with External Resources sess.callFunctionWithArgumentassert, new IncidentDispatcher; An accident has happened TrafficIncident ti = new TrafficIncident; ti.setHighwayI5; ti.setDirectionsouth; ti.setIncidentaccident; ti.setWhennew GregorianCalendar2005, 1, 25, 5, 4; ti.setDelay45; sess.callFunctionWithArgumentassert, ti; sess.callFunctionrun;

4.8 Debugging an RL Stacktrace