Rules Engine Development Specification--Program Development Specifications <serial 3>

1.5 Directly pass the incoming values ​​into the calling rule package in the map method. When calling the rule package by
default , you need to pass in the corresponding values ​​one by one through the put method, and then call the rule package through the execute method, and obtain each returned value through the get method. parameter value. If the system and a map maintaining data, such as the data in the workflow, have been stored in the map in advance, then you can use the ruleEngine.executeMap method to directly use the map as all incoming values. After passing in, the map is also returned, but the returned map itself is not the original map, but a new map is generated according to the return value. For details, please refer to the code:
HashMap<String,Object> map = new HashMap<String,Object> () ;
map.put("a", 11) ;
map.put("b", 22) ;
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine();
try {
Map os = ruleEngine.executeMap("test. simpleAdd",map);
if ( os != null && !os.isEmpty() )
System.out.println(os.get("c"));
} catch (Exception e) {
e.printStackTrace();
}
1.6. Batch data call rule package
If you need to calculate a batch of data in batches, and then return the values ​​in the form of batch data. Currently, the rule engine supports storing batches of incoming data in the form of List<List> through the ruleEngine.executeBatch method. For example, in the second List, the incoming values ​​are placed in the specified position in order. After execution, the method can return a List<List> that stores the return value. The details are as follows:
ArrayList<ArrayList> inputs = new ArrayList<ArrayList>() ;
for (int i = 1 ; i <= 10 ; i++ ) {
ArrayList value = new ArrayList() ;
value.add(11*i) ;
value .add(22*i) ;
inputs.add(value);
}
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine();
try {
List<List> os = ruleEngine.executeBatch("test.simpleAdd",inputs);
if ( os != null && os.size() > 0 ) {
for ( List val : os ) {
System.out.println(StringUtil.stringValue(val));



} catch (Exception e) {
e.printStackTrace();
}
1.7. Calling the rule package with Java Bean In the
above invocation methods, it is necessary to pass parameters to the rule package, and finally get the corresponding parameter value. The ruleEngine.executeBeans method can be used to call directly by passing the class to the rule engine. The incoming and outgoing values ​​corresponding to the rule package are directly defined in the properties of the class. as follows:
public class BeanExecuteTest {

public class BeanInfo {
private double a ;
private double b ;
private double c ;
public BeanInfo() {
a = 11 ;
b = 22 ;
}
public double getA() {
return a;
}
public void setA(double a) {
this.a = a;
}
public double getB() {
return b;
}
public void setB(double b) {
this.b = b;
}
public double getC() {
return c;
}
public void setC(double c) {
this.c = c;
}
}
public static void main(String[] args) {
BeanInfo info = new BeanExecuteTest().new BeanInfo() ;
HashMap<String,Object> map = new HashMap<String,Object>() ;
map.put("a", 11) ;
map.put("b", 22) ;
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine();
try {
ruleEngine.executeBeans("test.simpleAdd",info);
System.out.println(info.getC());
} catch (Exception e) {
e.printStackTrace();
}
}
}
In this way, it can be connected with other systems, and multiple beans can be directly passed to the rule engine for processing. The rule engine automatically passes the properties of the bean as incoming values ​​to the rule package for execution. After the rule package is processed, the outgoing values ​​are copied to the property values ​​of the bean.

Guess you like

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