Using the CA Rule Engine › Construction of Java Client Applications › Acquire the RuleExecutionSet and RuleSession › Establish a Rule Session
Establish a Rule Session
To conduct inferencing through the JSR‑94 API, a rule session needs to be established, that is, an instance of either a stateless or stateful RuleSession needs to be obtained. To accomplish this, obtain an instance of the RuleRuntime first.
You can obtain a RuleRuntime instance in one of the following ways, depending upon the solution architecture of the client application:
For more information on serializing the RuleRuntime, see Acquire and Register the RuleExecutionSet.
RuleRuntime serves the following purposes:
- It provides the createRuleSession() method for obtaining a RuleSession instance.
- It provides the constants STATEFUL_SESSION_TYPE and STATELESS_SESSION_TYPE that allows the client application to specify the type of inferencing session it wishes to establish.
- It enables the programmer to retrieve the list of RuleExecutionSet URIs that are registered with the RuleAdministrator through the getRegistrations() method. This capability is important if the solution architecture involved in deserializing the RuleRuntime is on a different client application than the application that registered the RuleExecutionSet.
The createRuleSession() method requires the following parameters:
- The URI of the RuleExecutionSet that is to be used by the inference engine. This URI may be directly available in the client application from the registration of the RuleExecutionSet with the RuleAdministrator or obtained through the getRegistrations() method of the RuleRuntime instance.
- A property map. Under CA Rule Engine, the property map is used to specify the name of the RDL domain that is used with the client application when the rulebase contains more than one domain that is shared, and to specify the generation of the optional Inferencing Summary document. For more information, see Specify a Shared Domain and Obtain Rulebase Documents respectively.
- A specification of the rule session type. The method invocation should specify either STATEFUL_SESSION_TYPE or STATELESS_SESSION_TYPE as a parameter. This parameter determines how the client application interacts with the inference engine, and in particular, how application objects are passed to and retrieved from the inference engine. For more information, see Addition and Retrieval of Inference Engine Objects.
A typical creation of a (stateful) rule session can be:
StatefulRuleSession session = (StatefulRuleSession)runtime.createRuleSession(
rulesetUri, null, RuleRuntime.STATEFUL_SESSION_TYPE);
Note: The need to cast the instance returned by the createRuleSession() method. The method returns a RuleSession, but the session instance needs to be of a specific kind of session to allow the client application access to the appropriate methods to interact with the inference engine.