Rules Engine Development Specifications--Program Development Specifications <serial 1>

1.1. Java program calling rules

   Java programs can call the rule package or the first-level rules in the rule package through the API provided in engine.jar. When calling, the simple calling code is as follows:
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine() ;
ruleEngine.put("export_0", "test");
try {
ruleEngine.execute("simple.helloworld");
System.out.println(ruleEngine.get("export"));
} catch (Exception e) {
e.printStackTrace();
}
The above is the standard calling method.
RuleEngineFactory.newInstance().getRuleEngine() is to get an engine instance, and each engine instance will allocate a separate map to receive the data called by the java side.
The ruleEngine.put method is used to store the called data in the map. After ruleEngine.execute is executed, it will find the specific rule package according to the incoming rule package name, and pass all the data in the map to this rule package. When all the rules of the rule package are executed, the executed value will be written back to the map. An exception will occur when ruleEngine.execute is executed. If com.flagleader.engine.RuleEngineException: 103: import the rule package simple.helloworld, and find that there is no such error in the /simple/helloworld.rsc file in the path, check whether the classpath exists simple/ Check whether the helloworld.rsc file or the simple/helloworld.rsc file exists in the ruleEngineClassDir directory specified in the engine.conf configuration file.
The ruleEngine.get method can read the return value in the map.
Therefore, if you need to call two rule packages in a row, you need to execute RuleEngineFactory.newInstance().getRuleEngine() twice, otherwise the two calls will share the same map, unless the rule package called for the second time needs to use the previous one call result.

1.2. Java program calls the internal rules in the rule package

If you want to call the internal rules in the rule package, you can use the ruleEngine.execute(String) method, the rule package name in this method can use @ to access the internal rules in the rule package , for example:
ruleEngine.execute("simple.helloworld@rule 1");
means to execute the rule 1 sub-rule under the simple.helloworld rule package.
Note that sub-rules can be called at most two levels, that is, the third-level sub-rules cannot be accessed.
For example, rulesets@rulesets@rules cannot be accessed.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326708107&siteId=291194637