ILOG JRules User Guide > Executing Rules > Tasks > Executing a Ruleset Using Rule Execution Server > Invoking a Ruleset Using a Stateful Rule Session > Creating a Stateful Rule Session and Executing a Ruleset

To invoke a ruleset using a stateful rule session you can:

Note
The ruleset should be previously deployed.

In the following example we assume that a ruleset execution interceptor has been set on the RuleApp that redirects the RuleApp call to a ruleset of this RuleApp.

To create a stateful rule session and execute a ruleset with a RuleApp path:

// Creates the execution request
IlrSessionRequest request = new IlrSessionRequest(RULESET_PATH, resetRuleflow); 
// where resetRuleflow is a boolean to reset or not the ruleflow
 IlrSessionDescriptor desc = request.getSessionDescriptor(); desc.setUserData("testInterceptorRuleApp");
 
// Enable the interceptor
   desc.setEnableInterceptor(true);
 
// Creates the stateful rule session
   IlrStatefulRuleSession rsf = rsProvider.createStatefulRuleSession(request);
 
// Sets the IN and INOUT parameters   
   IlrSessionExecutionSettings execSettings = request.getExecutionSettings(); 
   SerializableObject so = new SerializableObject(); 
   so.value = new String("Value1"); 
   IlrSessionParameters params = execSettings.getInputParameters();
   params.setParameter("paramJava", so);
   params.setParameter("paramXml", getXmlString());
 
// Executes the ruleset with interceptor enabled  
   IlrSessionStatefulExecutionSettings execSettings =
      (IlrSessionStatefulExecutionSettings)request.getExecutionSettings();
   IlrSessionExecutionResult result = rsf.executeRules(execSettings);
 
// Gets the meta data
   IlrSessionExecutionProperties execProperties = rsf.getExecutionProperties();
 
// Finishes the session
   rsf.endSession();
 
   IlrSessionParameters outputParameters = result.getOutputParameters(); 
   System.out.println(outputParameters);
   System.out.println(" ruleset executed is " +   
                      execProperties.getCanonicalRulesetPath());

Warning
The rule session should be freed rigorously at the end of the session to prevent the application server from overloading.

Related Concepts

Rule Sessions
Stateful rule sessions

Related Tasks

Creating a POJO Client Project for RuleApps
Creating a Web Service or Monitored Transparent Decision Service Project for RuleApps
Creating an SCA Component Client Project for RuleApps
Maintaining Execution Code Generators
Invoking a Ruleset Using a Stateless Rule Session
Invoking a Ruleset Using a Message-Driven Rule Bean
Tracing Ruleset Execution
Monitoring Ruleset Execution Using the MBeans Accessor API
Handling Rule Engine Exceptions in Rule Execution Server

Related Samples and Tutorials

How to Use a Rule Session in Java SE
How to Use a Rule Session in Java EE
How to Use a Message-Driven Rule Bean