我不得不创建成对的规则来撤回我的事件。好像没有过期。我想要一次性完成的活动。你可以在下面看到,他们使用默认的持续时间,零。
例如,如果我排除撤回规则,然后先插入 RemoveConnectionEvent,然后再插入 CreateConnectionEvent,RemoveConnection 规则仍然会触发。(在我的单元测试中使用议程监听器)
我对事件的期望是 RemoveConnectionEvent 将被忽略,如果它的条件没有立即满足,它不会做任何事情。当 NewConnection 规则响应 CreateConnectionEvent 时,一旦满足规则条件,我没想到它会挂起并触发 RemoveConnection 规则。
为了让我的规则按预期运行,我创建了 RetractedCreation、RetractedRemoval 和 RetractedUpdate。这似乎是一个黑客。我在想象一个宣布我的事件是错误的。
有任何想法吗?
ps 这是一个很好的问答,但我没有使用 Windows。它可能会推断出我的 hack 可能是一个“明确的过期策略”。
Drools Fusion CEP测试事件到期中的测试事件到期
这是我的规则。
package com.xxx
import com.xxx.ConnectedDevice
import com.xxx.RemoveConnectionEvent
import com.xxx.CreateConnectionEvent
import com.xxx.UpdateConnectionEvent
declare CreateConnectionEvent @role( event ) end
declare UpdateConnectionEvent @role( event ) end
declare RemoveConnectionEvent @role( event ) end
rule NewConnection
when
$connection : CreateConnectionEvent($newChannel : streamId)
not ConnectedDevice( streamId == $newChannel )
then
insert( new ConnectedDevice($newChannel) );
end
rule RetractedCreation
when
$creationEvent : CreateConnectionEvent($newChannel : streamId)
exists ConnectedDevice(streamId == $newChannel)
then
retract($creationEvent)
end
rule RemoveConnection
when
$remove : RemoveConnectionEvent($newChannel : streamId)
$connection : ConnectedDevice( streamId == $newChannel )
then
retract( $connection );
end
rule RetractedRemoval
when
$removalEvent : RemoveConnectionEvent($newChannel : streamId)
not ConnectedDevice(streamId == $newChannel)
then
retract($removalEvent)
end
rule UpdateConnection
when
$connectionUpdate : UpdateConnectionEvent($newChannel : streamId)
$connection : ConnectedDevice( streamId == $newChannel )
then
$connection.setLastMessage();
end
rule RetractedUpdate
when
$removalEvent : UpdateConnectionEvent($newChannel : streamId)
not ConnectedDevice(streamId == $newChannel)
then
retract($removalEvent)
end