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:

The createRuleSession() method requires the following parameters:

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.