java定时api_基于Java API的DROLS定时规则执行

我想创建一个每5分钟触发一次的基于时间的规则,Drools文档指出:

相反,当Drools引擎以被动模式运行时(即使用FireAllRules而不是FireUntilhalt),默认情况下,它不会触发定时规则的结果,除非FireAllRules不再被调用。但是,可以通过使用TimeDruleExecutionOption配置KieSession来更改此默认行为,如下例所示

KieSessionConfiguration ksconf = KieServices.Factory.get().newKieSessionConfiguration();

ksconf.setOption( TimedRuleExecutionOption.YES );

KSession ksession = kbase.newKieSession(ksconf, null);

但是,我不直接访问KieSeEnter对象,因为我正在使用Java REST API将请求发送到部署在KiRealEngServer上的DROLS项目,像这样(直接从DROLS文档中获取):

public class MyConfigurationObject {

private static final String URL = "http://localhost:8080/kie-server/services/rest/server";

private static final String USER = "baAdmin";

private static final String PASSWORD = "password@1";

private static final MarshallingFormat FORMAT = MarshallingFormat.JSON;

private static KieServicesConfiguration conf;

private static KieServicesClient kieServicesClient;

public static void initializeKieServerClient() {

conf = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD);

conf.setMarshallingFormat(FORMAT);

kieServicesClient = KieServicesFactory.newKieServicesClient(conf);

}

public void executeCommands() {

String containerId = "hello";

System.out.println("== Sending commands to the server ==");

RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);

KieCommands commandsFactory = KieServices.Factory.get().getCommands();

Command> insert = commandsFactory.newInsert("Some String OBJ");

Command> fireAllRules = commandsFactory.newFireAllRules();

Command> batchCommand = commandsFactory.newBatchExecution(Arrays.asList(insert, fireAllRules));

ServiceResponse executeResponse = rulesClient.executeCommandsWithResults(containerId, batchCommand);

if(executeResponse.getType() == ResponseType.SUCCESS) {

System.out.println("Commands executed with success! Response: ");

System.out.println(executeResponse.getResult());

} else {

System.out.println("Error executing rules. Message: ");

System.out.println(executeResponse.getMsg());

}

}

}

所以我有点困惑,我该如何将这个时间执行选项传递给会话?

我已经通过定期发送fireallrules命令找到了解决方法,但我想知道是否可以配置此会话选项,这样我就不必为我要创建的每个定时事件添加定期触发。

另外,我尝试使用firetuntilhalt而不是fireallrules,但据我所知,命令会阻塞服务器上的执行线程,我必须在某个时刻发送一个haltcommand,所有这些我都想避免,因为我有一个多线程的客户机将事件发送到服务器。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值