This page last changed on Jun 15, 2013 by nwe.


I have created another rule file called Debug.drl and have the following code in it

package org.openremote.controller.protocol

import org.openremote.controller.utils.Logger;
import org.openremote.controller.Constants;

function void logit(String msg)
  Logger.getLogger(Constants.CONTROLLER_ROOT_LOG_CATEGORY + ".MyBogusRule").info(msg);

rule "loggingit" 
  timer (cron: 0/5 * * * * ?) when eval(true) 
  then logit("I'm Alive! XXX");

The questions is, how do I call the "logit" function from the modeler_rules.drl file?
ie Debug.logit("Value = 123");

Thanks Neil.

I've never tried it. Searching didn't reveal any useful information about this either.

Trying to think through it, each rule file is compiled into a Java class. Since a function in any one rule file will use up the namespace (the function's name), I would assume each rule file gets compiled into its own Java class – if not, defining two functions with the same name in two separate rule files would result in a naming conflict.

The Java class compilation is transparent however, done by the rule engine, and we don't know what class names it will use (and they're likely not very readable either as they're not intended for use).

The Drools documentation is also silent about the function visibility across rule files.

What is possible however is to import Java helper classes into rules. The implementation of your log function is almost exactly the same, also instead of using the 'function' keyword, you would use 'public static' to indicate a public class method.

Then it should be possible to import the logit function into all of your rules:


And with that import you can use the logit class method across all your rule files.

This however assumes that you are comfortable in compiling a Java class into a JAR.

Posted by juha at Jun 15, 2013 14:00
Document generated by Confluence on Jun 05, 2016 09:41