Memory ruleset execution sample details

You run this sample in the Samples Console.

Running this sample

To run this sample:

  1. Open the Samples Console.
  2. In the Samples Commands tab, expand Samples Commands > Rule Execution Server > Memory ruleset execution .
  3. Double-click the execute command.

This operation can take some time to complete. It posts messages to the console during the run, and when it finishes, it displays the following decision report:

INFO: Create engine definition in debug from DSAR
Report: Valid data true Approved false 
   - Rate 0.055
   - Monthly repayment 2,325.65	
   - Message Average risk loan
Too big Debt/Income ratio: 1.40
We are sorry. Your loan has not been approved
Completed: execute
BUILD SUCCESSFUL

This command calls the SampleClient class by using the ruleset parameter without a loan amount. Then, the sample code is called with a default loan amount.

Running the sample using a smaller loan amount as a parameter

You run the sample to process a smaller loan amount.

  1. Open the Samples Console.
  2. In the Samples Commands tab, expand Samples Commands > Rule Execution Server > Memory ruleset execution.
  3. Double-click the execute.small.loan command.

This operation can take some time to complete. It posts messages to the console during the run, and when it finishes, it displays the following decision report:

INFO: Create engine definition in debug from DSAR
Report: Valid data true Approved true 
   - Rate 0.055
   - Monthly repayment 232.56	
   - Insurance required true Insurance rate 2%	
   - Message Low risk loan
Congratulations! Your loan has been approved
Completed: execute.small.loan
BUILD SUCCESSFUL

Rebuilding the sample

To rebuild the sample:

  1. Open the Samples Console.
  2. In the Samples Commands tab, expand Samples Commands > Rule Execution Server > Memory ruleset execution.
  3. Double-click the clean command. This command removes the built classes, and the RuleApp and its XOM that the Build Command built in the lib directory.

How this sample works

The sample uses the following workflow:

  1. The ODM Java Rule session API is invoked to run the ruleset, whose ruleset path is passed as an argument, for example, /test_deployment/loan_validation_with_score_and_grade.
  2. The Rule Session API delegates the ruleset execution to the Rule Execution Server execution unit (XU).
  3. The XU fetches the ruleset from the Rule Execution Server memory persistence.
  4. As there is no such ruleset, the Rule Execution Server memory persistence looks for a matching RuleApp packaged in the application's classloader resources.
  5. The Rule Execution Server memory persistence loads the contents of the RuleApp archive test-deployment.jar.
  6. The Rule Execution Server memory persistence returns the target ruleset to the XU.
  7. The XU retrieves the Java execution object model (XOM) from the application classloader.
  8. The XU finally runs the ruleset and passes the available output results to the Rule Session API.

The sample uses the following features:

The sample architecture and workflow are as follows:

Diagram shows the architecture of the sample.

Source files

This sample is in <InstallDir>/executionserver/samples/jsedecisionservice.

You can view and modify the sample source files in Rule Designer:

  1. Open the Samples Console
  2. In the Samples and Tutorials tab, expand Samples Commands > Rule Execution Server > Samples.
  3. Under Memory ruleset execution, click Import projects.
  4. Switch to the Java perspective to view the following classes:
    • The RESJSEExecution class defines a way to call the decision service from the Java SE environment.
    • The SampleClient class shows a way to use the RESJSEExecution class.