Here is a typical code sample to set up a ruleset execution
trace on the client side.
About this task
To define a ruleset execution trace on the client side,
you create a session factory and a session request object, enable
the trace, set the input parameters, create a response object, and
retrieve the trace.
You can also trace ruleset execution on
the server side by extending the EventPlugin class. See Extending the plug-in.
Procedure
- Create a session factory and a session request object.
- Create a session request object.
IlrSessionRequest sessionRequest = sessionFactory.createRequest();
String rulesetPath = "/miniloanruleapp/miniloanrules";
}
sessionRequest.setRulesetPath(IlrPath.parsePath(rulesetPath));
- Enable the trace and retrieve all the traces on the executed
rules.
sessionRequest.setTraceEnabled(true);
sessionRequest.getTraceFilter().setInfoAllFilters(true);
- Optional: If not all XOM objects are serializable,
add the following lines.
sessionRequest.setTraceEnabled(true);
sessionRequest.getTraceFilter().setInfoBoundObjectByRule(true);
- Set the input parameters for the execution of the rules.
Map<String,Object> inputParameters = sessionRequest.getInputParameters();
inputParameters.put("loan", loan);
inputParameters.put("borrower", borrower);
IlrStatelessSession session = sessionFactory.createStatelessSession();
- Execute and get the response for this request.
IlrSessionResponse response = session.execute(sessionRequest);
- Get the execution trace and the number of rules executed.
IlrExecutionTrace sessionTrace = response.getRulesetExecutionTrace();
int rulesNumber = sessionTrace.getTotalRulesFired();
- Get the business version of the execution trace and the
list of executed rules with their business names, including the state
of the output parameters.
IlrBusinessExecutionTrace execResult = new IlrBusinessExecutionTrace(response.getRulesetExecutionTrace());
List<String> rulesFired = execResult.getRuleFiredBusinessNames();
loan = (Loan) response.getOutputParameters().get("loan");
Results
Here is the entire typical code sample for a Java SE rule session:IlrSessionFactory sessionFactory = new IlrJ2SESessionFactory();
IlrSessionRequest sessionRequest = sessionFactory.createRequest();
String rulesetPath = "/miniloanruleapp/miniloanrules";
}
sessionRequest.setRulesetPath(IlrPath.parsePath(rulesetPath));
sessionRequest.setTraceEnabled(true);
sessionRequest.getTraceFilter().setInfoAllFilters(true);
Map<String,Object> inputParameters = sessionRequest.getInputParameters();
inputParameters.put("loan", loan);
inputParameters.put("borrower", borrower);
IlrStatelessSession session = sessionFactory.createStatelessSession();
IlrSessionResponse response = session.execute(sessionRequest);
IlrExecutionTrace sessionTrace = response.getRulesetExecutionTrace();
int rulesNumber = sessionTrace.getTotalRulesFired();
IlrBusinessExecutionTrace execResult = new IlrBusinessExecutionTrace(response.getRulesetExecutionTrace());
List<String> rulesFired = execResult.getRuleFiredBusinessNames();
loan = (Loan) response.getOutputParameters().get("loan");