Both the StatelessRuleSession and StatefulRuleSession instances provide an executeRules() method for invoking the RuleExecutionSet with which those instances were created. The signatures of this method are radically different for each of these rule session types.
A stateless rule session means that the inference engine does not maintain state. That is, the whole inferencing process is completed from a single, synchronous invocation from the client application. The client application cannot go back to the same inferencing process after the single invocation is completed. When a stateless rule session is established, Java client instances are added to and results are retrieved from the inference engine in a single executeRules() call. The executeRules() method provided by the StatelessRuleSession object takes a list of object (references) as an input argument and returns a list of (references to) objects that provide the results of the inferencing session. Once an object reference is passed to the inference engine, it is impossible to modify that reference within the stateless rule session.
Note: The StatelessRuleSession also provides an overloaded version of its executeRules() method for also passing filter objects to the inference engine for filtering the returned results. For more information on filters, see Object Filters.
For information on the StatelessRuleSession.executeRules() methods, see the StatelessRuleSessionImpl class in the Javadoc.
A stateful inferencing session allows the client application to have multiple interactions with the inference engine during the rule session. The inference engine maintains state through these interactions. Objects can be added to and removed from the inference engine in separate methods, and these methods are independent of and can be interspersed with the StatefulRuleSession.executeRules() method. The StatefulRuleSession offers a number of methods to add objects, either singly or by means of a list, and to update, retrieve, and remove objects. The executeRules() method within a stateful rule session takes no arguments and returns void.
Important: The StatefulRuleSession is not intended to be used to execute certain rules repeatedly for different combinations of precondition values, such as applying the same rules for 100 individual cases. Such operations may not yield expected results due to side effects from previous executions and behaviors will be specific to each vendor implementation. The Java application should instead repeatedly use StatelessRuleSession with each combination of preconditions instead. The StatefulRuleSession is best used in situations where a variable number of preconditions may be needed to resolve a problem depending on the values of the supplied preconditions, and it is desirable to supply certain preconditions only when it is necessary. For a use case illustrating this kind of usage of the StatefulRuleSession, see Reimbursement Example.
If it is desired to have the stateful session to resolve to the same final results compared with those from a stateless session given the exact same preconditions just all at once, the kinds of interactions allowed during a stateful session should be limited to those operations implicitly performed on behalf of the stateless session. In general, it is always safe to add new objects or to update a previously unknown field with a value during the stateful rule session, while removing an object or changing the value of a known field without resetting the session should be avoided. For more information, see the guide on engine behavior.
It is possible to reset the state of the inference engine during a stateful rule session using the reset() method. For more information on the methods of the StatefulRuleSession, see the StatefulRuleSessionImpl class in the Javadoc.
Note: The object‑add methods return Handles to the objects added to the inference engine. These handles are used to interact with those objects during the stateful rule session. For more information on Handles, see the HandleImpl class in the Javadoc.
A rule session should always be released after all interaction with the inference engine has been concluded:
session.release();
| Copyright © 2009 CA. All rights reserved. | Email CA Technologies about this topic |