Pattern Matcher Grammar
A pattern string has four main clauses: define pattern, using, with, and starts with clause. These clauses define the patterns that need to be identified with specified streams.
The following figure displays the process flow of the four different clauses:
Syntax Example
The following is a simple example to illustrate the four clauses of a pattern. This example checks for an incorrect order of events in an order fulfillment and shipping flow.
define pattern /OrderTracker using /Order as order and /Fulfillment as fulfillment and /Shipment as shipment with order.customerId and fulfillment.customerId and shipment.customerId starts with order then fulfillment then shipment
The example demonstrates how Pattern Matcher correlates events across three different event streams. The pattern listens to all three streams (Order, Fulfillment and Shipment).
A pattern listens only to events that are sent to the Pattern Matcher service. See Send Events to the Service.
Syntax Diagrams
The syntax diagrams show the structure of a pattern and of each clause in a pattern.
Read the syntax diagrams from left to right. Items above or below a main line are optional. Items that can repeat are shown by lines that loop back from the end to the beginning of the repeating section, along with the separator character or word if one is required.
alias | Alias for an event in the pattern. |
identifier | A string that represents the name of a pattern or the URI of an entity. Identifiers |
time unit | Allowable time units are as follows:
|
Names
- Pattern names (URIs) and event name can be any character inside double quotes, except double quote itself. Pattern URI needs quotes only if there is a space in the URI.
- Field and property names must be valid Java identifiers.
- Each alias must be globally unique in the whole pattern.
- To escape a keyword, use the pound sign (
# —
also known as a hash sign) before the keyword, for example,#define
. - Alias name, field name, property name, subscription field and bind variables can be use any of the following:
- alphanumeric
- digit
- underscore ('_')
- slash ('/')
- Escaped keywords.
Bind Variables
Variables begin with the dollar sign ($
). The value is provided at deploy time. See Create the Pattern String.
You cannot use bind variables with the datetime()
or date()
functions. For example, it is not possible to use this type of call:
$datetime($year,$day,$month,....)
You can, however, use bind variables using the following function:
Pattern.Manager.setParameterDateTime()
For example:
Pattern.Manager.setParameterDateTime(patternSc14, "javaUtilDate", date);
Not (Negation) Scenarios
Although the language has no explicit operator for Negation or Not, negative scenarios can be implemented in other ways such as:
- Subscribe to the event type on which is not expected to occur.
- Do not describe it in the pattern.
So, when the undesired event does occur due to the subscription, the pattern instance will fail. The following pattern example demonstrates a negation scenario:
define pattern OrderFullfilment using Order as order and Fulfillment as fulfillment and Cancellation as cancellation where order.customerId and fulfillment.customerId and cancellation.customerId starts with order then within 10 minutes fulfillment then after 5 minutes
This pattern subscribes to Cancellation events but does not use them in the pattern. After the Order and the Fulfillment events arrive within the times specified, the pattern waits for another five minutes, during which it does not expect any input. If during this or any other time the Cancellation event occurs, then the pattern fails.