8.5 Basic Event Patterns
The simplest event patterns are called basic patterns. A basic pattern matches single events. The syntax of a basic pattern is
(list of variable declarations) action name ( list of parameter expressions )
The variables are declared in a list, followed by an action name and a list of parameters, each of which can be either a declared variable or an expression. The parameters must have types corresponding to the formal parameter declarations of the action.
A basic event pattern can match events that have the same action name. To match an event, the variables in the pattern must be replaced by data values in the event to make an instance of the pattern that is identical to the event.
Example 1: A basic pattern for money transfers
A basic pattern matching all money transfers from a given account is
(Dollars X, Account Type A) Transfer (X, Accnt#100, A)
The action name is Transfer, and the variables are X and A. The Transfer action is shown in the ATMUse example (see Section 8.3.4, Example 2). Accnt#100 is a constant account number for the From Accnt parameter. To make a match, we can replace X by any dollar amount and A by any account number. This will give us an instance of the pattern that must be identical with the event we are trying to match.
For example, the pattern matches Transfer(10, Accnt#100, Accnt#5) if X is replaced by 10 and A is replaced by Accnt#5. Similarly, the pattern matches Transfer(105, Accnt#100, Accnt#21505) if X is replaced by 105 and A is replaced by Accnt#21505. But the pattern cannot match Transfer(105, Accnt#5, Accnt#21505) because Accnt#100 = - Accnt#5.
Example 2: A basic pattern for engine parts
A basic pattern matching all orders for engine parts is
(OrderId Id, CustId Customer, AccntNo Accnt) Order(Id, Customer, EngineParts, Accnt);
The Order action is shown in the SupplyChainEvents example (Section 8.3.4, Example 3). All parameters in this pattern are variables except the PartsOrder which is a constant called EngineParts. So this pattern has an instance which matches any Order event for engine partsreplace each variable by the corresponding data parameter in the event.
The simplest case of matching is when the pattern does not contain any variablescalled a constant pattern. In this case, a basic pattern matches an event if it has the same action name as the event, and each expression in its data parameters evaluates to the corresponding value in the event's data parameters.
Example 3: A constant pattern
A constant pattern is
This basic pattern matches any single event in which the name of the action is Deposit, the Dollars amount is 1,000, and the account is Accnt#123. So it matches events like the following:
Deposit(1000, Accnt#123), Deposit(500 + 500, Accnt#123), . . .