共通ルール・タイプ

ルールには多数のタイプが存在します。タイプを選択し、特定の目標を達成できるようにするために、共通タイプのリストを参照してください。

イベント発生時にアクションを実行する

これらのルールは、特定のタイプのイベントが発生したときに実行するアクションを定義します。以下のルールは、このルール・タイプのシンプルな例を示します。

when a Purchase occurs
then
   print "A purchase order has been sent";

イベント発生時にエンティティーを作成する

これらのルールは、特定のタイプのイベントが発生したときに、エンティティーのバインド・インスタンスを作成します。次の例では、new 演算子を使用して、Customer のインスタンスを作成し、属性を取り込みます。
when a Purchase event occurs
if
   'the customer' is null
then
   print "Creating a new entity using key: " + the eventKey of this Purchase event;
   set 'the customer' to a new Customer where
      the key is the eventKey of this Purchase event;
else
   print "The agent is already bound using key: " + the eventKey of this Puchase event;

イベント発生時にエンティティーを削除する

これらのルールは、特定のタイプのイベントが発生したときに、エンティティーのバインド・インスタンスを削除します。次の例は、バインド変数を null に設定する方法を示しています。

when an account closure event occurs
if 'the account' is not null
then
   print "Deleting the entity with key: " + the eventKey;
   set 'the account' to null;

期間内に複数のイベントが発生した場合にアクションを実行する

これらのルールは、特定のタイプのイベントが期間内に複数回発生したときに実行するアクションを定義します。次の例は、過去 10 秒以内にタイプが Purchase event のイベントが 2 つ発生した場合に実行するルールを示しています。

when a Purchase event occurs
if
   the number of Purchase events during the last period of 10 seconds is more than 1
then
   print "We have already seen a purchase event within the last period!";

次の例は、見た目がわずかに異なる 2 つのルールを示していますが、どちらも 1 分経過しないうちにタイプが Purchase event のイベントが 2 つ発生した場合に同じことを行います。

when a Purchase event occurs
if
   the number of Purchase events after 60 seconds before now is more than 1
then
   print the name of this rule + " Found more than one" ;
when a Purchase event occurs
if
   the number of Purchase events during the last period of 60 seconds is more than 1
then
   print the name of this rule + " Found more than one" ;

イベントの内容に基づいてバインド・エンティティーを更新する

これらのルールは、特定のタイプのイベントが発生したときに、エンティティーのバインド・インスタンスを更新します。次の例で、エンティティーは the most recent order というフィールドを含んでおり、イベントは the amount というフィールドを含んでいます。Purchase event が発生すると、the amount は、Purchase event の内容で更新されます。

when a Purchase event occurs
then
   set the most recent order of 'the customer' to the amount;

関心があるものを含んだイベント発生時にアクションを実行する

イベントが発生しても、必ずアクションを実行する必要があるとは限りません。次の例で、ルールは着信イベントをフィルターに掛け、product 属性が Car と等しい場合にのみ実行されます。

when a Purchase event occurs
   where the product is "Car"
then
   print "We've sold a car!";

イベント処理を遅らせる

設定時間を使用して、イベントの処理を遅らせることができます。次の例の場合、ルールは 10 秒待機します。言い換えれば、ルールは、イベント発生の 10 秒後に実行するようにスケジュールされています。

when a Purchase event has occurred 10 seconds ago
then
   print "An purchase event happened 10 seconds ago";