イベントを撤回するには、ルールのペアを作成する必要がありました。有効期限はないようです。私はワン・アンド・ダン・イベントを望んでいました。以下に示すように、デフォルトのデュレーションであるゼロを使用しています。
したがって、たとえば、撤回ルールを除外してから、最初に RemoveConnectionEvent を挿入し、次に CreateConnectionEvent を挿入すると、RemoveConnection ルールは引き続き実行されます。(単体テストで議題リスナーを使用する)
イベントに対する私の期待は、RemoveConnectionEvent が無視されることでした。その条件がすぐに満たされない場合は何もしません。NewConnection ルールが CreateConnectionEvent に応答したときにルール条件が満たされると、それがハングアップして RemoveConnection ルールをトリガーするとは思っていませんでした。
ルールを期待どおりに動作させるために、RetractedCreation、RetractedRemoval、および RetractedUpdate を作成しました。これはハックのようです。私は自分のイベントが間違っていると宣言したと想像しています。
何か案は?
ps これはかなり良い Q&A でしたが、私は Windows を使用していません。おそらく私のハックは「明示的な有効期限ポリシー」であると推測できます。
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