Drools:如何编写在入口点没有数据时会命中的规则

问题描述

我是流口水的新手。我希望传感器数据能够从跟踪设备(例如标签设备)发送数据。我正在使用Drools 入口来跟踪传感器数据。我需要基于此传感器数据对某些事件进行警报。

DRL文件如下

import com.sample.AlertRuleModel;

declare AlertRuleModel 
    @role( event )
    @timestamp( timespamp )
end

rule "No signals are coming from any entry-point for more than 10s"
     when
        $f : AlertRuleModel() from entry-point "AlertRuleStream"
        not(AlertRuleModel(this != $f,this after[0s,10s] $f) from entry-point "AlertRuleStream")
    then
        $f.setRuleId(1);
        <Do alert here>
end

rule "Rule on Tag1 has not been in zone1 for more than 1 minutes"
     when
         $f : AlertRuleModel( tagId == 1,zoneId == 1 ) from entry-point "AlertRuleStream"
         not(AlertRuleModel(this != $f,tagId == 1,zoneId != 1,1m] $f) from entry-point "AlertRuleStream")
    then
         $f.setRuleId(2);
        <Do alert here>
end

Java代码

    kSession = RuleExecutionService.getKieSession(packetProcessorData.getAlertRuleDrlPath());
    ruleStream = kSession.getEntryPoint("AlertRuleStream");
    kSession.addEventListener(new DefaultAgendaEventListener() {
        public void afterMatchFired(AfterMatchFiredEvent event) {
            super.afterMatchFired(event);
            onPostExecution(event,RuleTypeEnum.ALERT_RULE.getName());
        }
    });
    
    new Thread() {
        @Override
        public void run() {
            kSession.fireUntilHalt();
        }
    }.start();

流数据插入部分

private BlockingQueue<AlertRuleModel> alertFactQueue;
.
.
AlertRuleModel alertRuleModel = null;
while (true) {
    alertRuleModel = alertFactQueue.poll(1,TimeUnit.SECONDS);
    if (alertRuleModel != null) {
        //LOGGER.debug("Inserting alertRuleModel into \"AlertRuleStream\"");
        ruleStream.insert(alertRuleModel);
        continue;
    } 

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        LOGGER.error("Exception while sleeping thread during alertFactQueue polling..",e);
    }

}

但是当我运行应用程序时,

  1. 一个规则“在10s内没有任何信号从任何入口点发出”根本没有命中。我不知道为什么,请告诉我我做错了什么还是语法错误是第一个规则。
  2. 在第二条规则“ Tag1不在zone1中超过1分钟”的情况下,当我通过tagId == 1和zoneId == 1传递事实时,它总是立即被击中。我尝试了不同的时间间隔,例如之后[0s,10m] 。但是在传递具有上述值的事实后,它仍然会立即命中。

请告诉我我在哪里犯错误..?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...