Rules engine development specification--program development specification <serial 2>

1.3. Calling the rule package asynchronously The rule package can be called asynchronously

through the ruleEngine.executeSynchronized(String) function.
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine();
ruleEngine.put("export_0", "test");
try {
ruleEngine.executeSynchronized("simple.helloworld");
} catch (Exception e) {
e.printStackTrace( );
}
Asynchronous calls cannot retrieve the return value from the map, so it is necessary to pass the object to the rule package through the put method. After the rule package obtains the reference to the object, it can be modified directly to realize the function of asynchronously modifying the value.
After executing the ruleEngine.executeSynchronized method, the system will generate an instance of the RuleEngineInfo class, and then hand it over to the RuleRecordServer class for execution. RuleRecordServer will generate a new RuleRecordServer instance according to the current thread, which will start a RuleRecordServer.ExeThread thread pool.
Each time the ruleEngine.executeSynchronized method is executed, idle threads will be executed from the thread pool in the RuleRecordServer instance corresponding to the current thread. If there is no idle thread, and the number of thread pools is less than the maximum number of threads set, a new thread will be created. thread and then execute.
RuleRecordServer.getInstance().waitThread() can be used to wait for all child threads to complete execution. When calling this method, it will judge whether there is an executing thread in the thread pool of the RuleRecordServer instance. If it is executing, the current thread waits, otherwise Go ahead.
RuleRecordServer.getInstance().setMaxThread(int), you can set the size of the thread pool.

1.4. Calling a rule package with dynamic parameters

Generally , when calling a rule package, you need to first know the name of the parameter received by the rule package, and use the put method to pass in the value according to the parameter name; and you need to know the name of the outgoing parameter, which is obtained by using the get method according to the outgoing parameter. return value.
In this default calling method, the parameter name must be specified before the value can be passed. Assuming that we know the number and location of incoming values ​​in advance, as well as the number and location of outgoing values, we can directly use the ruleEngine.executeDynamic method to invoke the rule package with dynamic parameters.
For example, the test.simpleAdd rule package has two incoming parameters and one outgoing parameter. As shown in the figure:




If you need to pass in two values, a=11 b=22, and then call the rule package and return the result value c, you can call it in the following way:
RuleEngine ruleEngine = RuleEngineFactory.newInstance().getRuleEngine();
try {
Object [] os = ruleEngine.executeDynamic("test.simpleAdd",new Object[]{11,22});
if ( os != null && os.length > 0 )
System.out.println(os[0]);
} catch (Exception e) {
e.printStackTrace();
}
Through the above code, the call can be realized without specifying the parameter name of the rule package.
This call method is used in relation to the order of the parameters.

Guess you like

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