ILOG JRules User Guide > Deploying Rules > Tasks > Managing RuleApps Using the MBeans Accessor API

This section describes a number of RuleApp management activities that you can carry out using the MBeans Accessor API. JRules provides a server-side API to deploy each entity, and a notification mechanism for model changes.

Note
To use the JMX API you must include the <InstallDir>/lib/jrules-bres-manage-tools.jar file in the class path of your application. For example, if you use this API in a Servlet, put the file in the directory META-INF/lib of your Web application.

The MBean accessor API consists of:

To use the JMX MBean:

  1. Package the classes.
  2. Include the jrules-bres-manage-tools.jar file in the class path of your application. For example, if you use this API in a Servlet, put the file in the directory META-INF/lib of your Web application.
    Warning
    To access an MBean Server you must have access rights equivalent to an administrator.
  3. Wrap the ruleAppObjectName using the following code:
IlrJmxMutableRuleApp ruleAppWrapper = modelWrapper.
                                      wrapRuleApp(ruleAppObjectName);
  1. Load a ruleset archive file, using the following code:
InputStream is = new FileInputStream("rulesetarchive.jar");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int read = 0;
while ((read = is.read(buffer)) != -1)
bos.write(buffer, 0, read);

Using the MBeans Accessor API, you can add a new RuleApp in the Rule Execution Server model and register it on the MBean Server where the model is registered. The model can be registered on another server in a cluster use case.

To add a new RuleApp and register it on the MBean Server:

IlrJmxMutableModel modelWrapper = new IlrJmxMutableModel();
ObjectName ruleAppObjectName = modelWrapper.addRuleApp("test_ruleapp", "1.0");

You can also add a new ruleset with a ruleset archive in the Rule Execution Server model and register it on the MBean Server where the model is registered. The model can be registered on another server in a cluster use case.

To add a new ruleset and register it on the MBean Server:

ruleAppWrapper.addRuleset("test_ruleset", "1.0", bos.toByteArray());
You can then invoke the Execution Unit (XU).

You can remove a RuleApp from the model and deregister the MBean on the MBean Server where it is registered.

To remove a RuleApp and deregister the MBean on the MBean Server:

modelWrapper.removeRuleApp("test_ruleapp", "1.0");
Suppressing the RuleApp also removes all links to the rulesets in the RuleApp.

To retrieve the ruleAppMBeanName:

ObjectName ruleAppMBeanName = (ObjectName) connection.invoke(bresMBeanName, "getRuleAppObjectName", 
          new Object[] { ruleAppName, majorVersion + "." + minorVersion },
          new String[] { "java.lang.String", "java.lang.String" });

Related Concepts

RuleApps and RuleApp Projects
Rule Execution Server Management Model

Related Tasks

Deploying and Exporting RuleApps

Related Samples and Tutorials

Tutorial: RuleApp Management
How to Automate Ruleset Management

Reference

RuleApp Management Using MBeans Accessor API