Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在一段时间内没有遵守规则_Java_Spring Boot_Streaming_Drools_Rules - Fatal编程技术网

Java 在一段时间内没有遵守规则

Java 在一段时间内没有遵守规则,java,spring-boot,streaming,drools,rules,Java,Spring Boot,Streaming,Drools,Rules,我不太会流口水。我需要用springboot&Drools(7.40.0.Final)构建一个应用程序,其中springboot应用程序流式传输一个外部源,该外部源将持续触发数据包(跟踪与实体移动相关的数据)到我的应用程序。我需要使用评估所有这些流数据 我正在使用一个“geofence_rule.drl”文件来保存与地理位置相关的规则 rule "Rule for Tag position in room 1" when model : ComponentModel(

我不太会流口水。我需要用springboot&Drools(7.40.0.Final)构建一个应用程序,其中springboot应用程序流式传输一个外部源,该外部源将持续触发数据包(跟踪与实体移动相关的数据)到我的应用程序。我需要使用评估所有这些流数据

我正在使用一个“geofence_rule.drl”文件来保存与地理位置相关的规则

rule "Rule for Tag position in room 1"
when
    model : ComponentModel(positionValue <= 50)
then
    model.setRoomId(1);
end

rule "Rule for Tag position in room 2"
when
    model : ComponentModel(positionValue > 50)))
then
    model.setRoomId(2);
end
我可能会得到“n”个标签的位置相关数据,比如tag1、tag2、tag3等等。我需要计算tag1是否在1号房间缺席(这意味着tag-1的数据在过去5分钟内未达到“1号房间中标签位置规则”)。Drools中是否支持这种计算

我在drools文档中看到过“not”关键字。但它只是否定了规则的条件。我需要在最后几分钟检查规则命中性质,此时间限制在应用程序中是可配置的。

您正在查找和。这些链接指向官方Drools文档

流模式是Drools中两种事件模式之一。默认情况下是“云”模式,在此模式下,您可以预先了解所有事实,并自动做出决策。另一种模式“流”模式用于处理时态流,听起来很像您的“ping”应用程序。在流模式下,Drools在每个事实出现时对其进行评估,并知道时间——即其他事实出现的时间

流模式中的否定模式是
not
关键字的逻辑时间扩展。正如您正确指出的,在云模式下,它只是否定一个条件(例如,“工作内存中没有与此条件匹配的条件”)。然而,在流模式下,您可以更新这些模式以在一段时间内生效

Drools文档提供了以下示例:

rule "Sound the alarm"
when
  $h: Heartbeat() from entry-point "MonitoringStream"
  not(Heartbeat(this != $h, this after[0s,10s] $h) from entry-point "MonitoringStream")
then
  // Sound the alarm.
end
“when”子句中的第一行标识心跳的实例(
$h
)。第二个标识在10秒内未接收到心跳的情况。如果这两个条件都为真,则执行规则——在本例中,将触发报警

这与您应用规则的模式相同

rule "Tag has not been in Room 1 for 5 minutes"
when
  // Tag with ID 1, present in Room 1 -- First instance
  $tag: ComponentModel( tagId == 1, roomId == 1 ) from entry-point "TrackingStream"

  // Trigger if this condition hasn't been met a second time within 5 minutes
  not( ComponentModel( 
    this != $tag, 
    tagId == 1,
    roomId == 1,
    this after[0s, 5m] $tag ) from entry-point "TrackingStream")
then
  // Do whatever it is you need to do for this condition
end
在本例中,我利用了临时操作符(链接到Drools文档)

基本上这就是它的工作原理--

第一个条件标识场景,在本例中,房间1中存在ID 1。它确定了我们正在跟踪的当前情况。由于这是一个时间流,很容易将其视为“标记的实体(1)刚刚进入房间1”

这就是神奇发生的地方,语法需要一点时间来适应。第二个条件是等待下一个时态,然后检查条件。检查的条件包括:

  • TagID是1
  • 室友5岁
时间约束(
this after[0s,5m]$tag
)表示等待检查此条件。如果在
$tag
之后在此时间范围内收到第二个ComponentModel,则规则将不会触发,场景将重复等待长达5分钟。由于时间范围
[0s,5m]
立即开始检查,我们需要在
not(…)
子句(
this!=$tag
中明确地从匹配中排除
$tag


为了说明这一点,以下是它的执行方式(简化):

  • 0m:00s-收到事件A(id=1,房间=1)<代码>$tag=事件A。我们开始检查第二个条件的传入流
  • 0米:30秒-收到事件B(id=2,房间=1)。ID不匹配;忽略
  • 0m:45s-收到事件C(id=1,房间=1)。事件A规则匹配“已取消”。现在检查
    $tag
    =事件C
  • 5m:45s-5分钟内未收到匹配的事件,事件C的规则触发右侧

感谢@Roddy的回复。负面模式现在很明显。我还想再加一个检查,这是否定规则的条件。在流模式下,就像“缺勤”检查一样,需要如下检查,规则“标签连续出现在房间1中5分钟”结束时,我们如何实施此类规则?简单,只需更改规则中的roomId检查。如果标签从未出现在该窗口的任何其他房间,则标签会在1号房间中出现五分钟。所以只要检查一下
roomId!=1
处于状态,因为这将表明标记1位于不同的房间。根据您的第一条评论,在“0m:45s-事件C~收到(id=1,房间=1)。事件规则匹配“已取消”,并检查$Tag=EventC”。但当我自己尝试时,EventA并没有被取消。最终结果显示EventA和eventC已触发。
rule "Tag has not been in Room 1 for 5 minutes"
when
  // Tag with ID 1, present in Room 1 -- First instance
  $tag: ComponentModel( tagId == 1, roomId == 1 ) from entry-point "TrackingStream"

  // Trigger if this condition hasn't been met a second time within 5 minutes
  not( ComponentModel( 
    this != $tag, 
    tagId == 1,
    roomId == 1,
    this after[0s, 5m] $tag ) from entry-point "TrackingStream")
then
  // Do whatever it is you need to do for this condition
end
$tag: ComponentModel( tagId == 1, roomId == 1 ) from entry-point "TrackingStream"
not( ComponentModel( 
  this != $tag, 
  tagId == 1,
  roomId == 1,
  this after[0s, 5m] $tag 
) from entry-point "TrackingStream")