공통 규칙 유형

규칙에는 여러 가지 유형이 있습니다. 특정 목표를 선택하고 성취하기 위해 공통 유형 목록을 참조하십시오.

이벤트 발생 시 작동

이러한 규칙은 특정 유형의 이벤트가 발생할 때 수행할 조치를 정의합니다. 다음 규칙은 이 규칙 유형의 간단한 예제를 보여줍니다.

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 유형의 이벤트가 두 번 발생할 때 수행하는 규칙을 보여줍니다.

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!";

다음 예는 1분 내에 Purchase event 유형의 이벤트가 두 번 발생하는 경우 같은 내용을 수행하는 두 개의 약간 다른 규칙을 보여줍니다.

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";