Managing RuleApps by using the MBeans accessor API

By using the JMX MBeans accessor API, you can add and register a new RuleApp or ruleset, and remove or unregister a RuleApp. You can also retrieve the RuleApp MBean name. If Rule Execution Server is deployed to a server cluster, you can register the model on another server.

Before you begin

Before you use the JMX API, make sure that the necessary JAR file is added to your class path and that you have sufficient access rights:
  • You must include the <InstallDir>/executionserver/lib/jrules-res-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 META-INF/lib directory of your web application.
  • To access an MBean server, you must have access rights equivalent to administrator rights.

About this task

Decision Server provides a server-side MBean accessor API for you to deploy each entity, and a notification mechanism for model changes.

The API consists of the following interfaces:

Procedure

  1. Package the classes.
  2. Wrap the instance of ruleAppObjectName.
    IlrJMXRuleAppMBean ruleAppWrapper = getRuleAppMBean(ruleAppObjectName);

    where getRuleAppMBean is the following method:

    public IlrJMXRuleAppMBean getRuleAppMBean(ObjectName ruleappMBeanName) {
           return (IlrJMXRuleAppMBean) Proxy.newProxyInstance(IlrJMXRuleAppMBean.class.getClassLoader(),
                                                              new Class[] { IlrJMXRuleAppMBean.class },
                                                              createHandler(ruleappMBeanName));
       } 
  3. Load a ruleset archive file.
    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);
  4. Write the code that is appropriate for the management action on your RuleApps and rulesets.
    • To add and register a new RuleApp on the MBean Server where the model is registered.
      IlrJMXRepositoryMBean repository = createJMXRepository();
          ObjectName ruleAppObjectName =  repository.addRuleApp("test_ruleapp", "1.0");
    • To add a ruleset with a ruleset archive in the Rule Execution Server model and register it on the MBean Server where the model is registered.
      ruleAppWrapper.addRuleset("test_ruleset", "1.0", bos.toByteArray());

      Then, you can call the execution unit (XU).

    • To remove a RuleApp and unregister the MBean on the MBean Server.
      repository.removeRuleApp("test_ruleapp", "1.0");

      When a RuleApp is removed, all links to the rulesets in the RuleApp are also removed.

    • You can retrieve the RuleApp MBean name.
      ObjectName ruleAppMBeanName = (ObjectName) connection.invoke(resMBeanName, 
      "getRuleAppObjectName", 
                new Object[] { ruleAppName, majorVersion + “.” + minorVersion },
                new String[] { "java.lang.String", "java.lang.String" });