Package ilog.rules.res.session.ruleset

Provides the interfaces for execution traces.

See: Description

Package ilog.rules.res.session.ruleset Description

Provides the interfaces for execution traces.

Overview

An execution trace is a dynamic body of information that spans the process of a ruleset going in and coming out of the rule engine.

When a trace is enabled, an execution request is notified by means of a Boolean value. The IlrSessionRequest class is initialized with a ruleset path, then the execution trace is enabled using a session descriptor. You also use this descriptor to set and retrieve the filters used for the session request.

After the ruleset is executed, the execution results are accessible in the form of an execution response. The IlrSessionResponse interface is used to access the properties and the result of the execution trace. The execution trace is gathered throughout the process of ruleset execution.

Trace filters

The following filters can be used to build the execution trace:

  • time taken to complete the ruleset execution
  • rules fired
  • rules not fired
  • tasks executed
  • tasks not executed
  • number of rules fired
  • number of rules not fired
  • number of tasks executed
  • number of tasks not executed
  • working memory as a collection

Code example

The following code example shows how to retrieve the standard and business trace information for an executed ruleset:

  IlrSessionFactory sessionFactory = getFactory();

  // Create a session request object
  IlrSessionRequest sessionRequest = sessionFactory.createRequest();
  String rulesetPath = "/miniloanruleapp/miniloanrules";
  if (!rulesetVersion.equalsIgnoreCase("Latest")) {
    rulesetPath = rulesetPath + "/" + rulesetVersion;
  }
  sessionRequest.setRulesetPath(IlrPath.parsePath(rulesetPath));
  // Enable trace to retrieve info on executed rules
  sessionRequest.setTraceEnabled(true);
  // get all traces
  sessionRequest.getTraceFilter().setInfoAllFilters(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
  IlrExecutionTrace sessionTrace = response.getRulesetExecutionTrace();

  // number of rules fired
  int rulesNumber = sessionTrace.getTotalRulesFired() ;
      
  // Get the Business version of execution trace
  IlrBusinessExecutionTrace execResult = new IlrBusinessExecutionTrace(response.getRulesetExecutionTrace());

  // Get the list of rules fired (Business names)
  List<String> rulesFired =   execResult.getRuleFiredBusinessNames();

  // including output parameters state
  loan = (Loan) response.getOutputParameters().get("loan");
Rule Execution Server API

© Copyright IBM Corp. 1987, 2020