Home > Articles > Programming

This chapter is from the book

8.3 Types

Rapide-EPL is strongly typed, much like most modern object-oriented languages. It may seem odd to impose strong typing on patterns, but it turns out to help users avoid all kinds of silly errors in patterns, such as typos. Such errors show up as type mismatches in the pattern. Types also play a powerful role in restricting the context in which a pattern can match. This makes pattern matching more efficient.

There are three kinds of types: data types, event types, and execution types.

When we write a pattern, we must first declare the types of data in the pattern and the types of events we expect to match the pattern against. A set of type declarations is called a type context.

Example 1: Defining Warning events

If we want to write patterns that will match Warning events, either about the loads on routes in a network or about the distance between aircraft, we first define the types of these Warning events:

//    type declarations preceding a pattern
typedef Network Path . . . ;                    – –  data type
typedef Aircraft . . . :                                         – –  data type
action Warning (Network Path P1, Real P2);   – –  event type
action Warning (Aircraft P1, Feet P2);             – –  event type

This type context declares two types of Warning events. It defines a global type context for patterns that follow it. Following these type declarations (that is, in the scope of the global type context), we can write a pattern such as this:

// pattern that matches network Warning events. 
(Network Path Route; Real Load) Warning(Route, Load); 

This a basic event pattern that can match single events. It consists of declarations of the types of parameters in the pattern followed by an event template. The type declarations of the parameters are a local type context for the pattern that restricts the types of parameters only in this pattern.

As the example shows, a pattern consists of two parts: first a list in parentheses of the variables in the pattern together with their types, and then the pattern part—the part that describes the events to be matched. Events have names called action names followed by a list of parameters. The name of an event is in fact a parameter of the event that we give a special syntactic emphasis by putting it first. It is similar to the subject of a message. The name of an event must match the action name in the event pattern in order for a match to be possible. So, for example, a Warning(. . .) pattern cannot match a ConnectTime event.

Here, the pattern matches events with the action name, Warning, and parameters Route (which is of type Network Path) and Load (which is a Real number).

Patterns are checked for type consistency before they are compiled for matching. This is where typos and other errors are caught.

Matching must be consistent with the types of the parameters in the pattern, and this restricts the events that can match the pattern. Our Warning pattern will match events like Warning(London–NewYork, 0.75), which is the kind of event we are looking for. London–NewYork is a Route and 0.75 is a Real number giving a measure of urgency.

If we omitted the typed parameter list from the pattern and just wrote the pattern part, we might get matches of Warning events from a different type of Warning event, like Warning(UA51, 5000), a warning of an aircraft within 5,000 feet. Although this may be an interesting match, it isn't a network warning, which is the kind of event our pattern is intended to match.

A pattern has both a global type context, where the types of events it can match are declared, and a local type context, where its variables and their types are declared. Because different types of events can have the same action name, the local context is important in disambiguating action names and specifying the types of events a pattern is intended to match. The data types in the local context must be subtypes of data types in the global context.

8.3.1 Predefined Types

Rapide-EPL has a set of predefined types. These are very common data types that appear in the events generated by many systems.

The predefined types include Boolean, Character, String, Integer, Float, and so on. Each predefined type comes with a set of operations. For example, Integers have the usual operations "+", "-", "=", and so on. Strings have a rich set of predefined operations—for example, comparison operations, such as S < T; selection operations, such as S [2 . . 4], which returns the substring consisting of the second, third, and fourth characters of S; and concatenation, &, which lets us construct a new string, S&T, from strings S and T.

8.3.2 Structured Types

Structured types are composed from other types. They let us define objects that have other objects as components.

Common kinds of structured types that are in many languages are pre-defined: record (record types), array (array types), enum (enumeration types), and some special types that we will describe later. Each of these structured types has predefined selection operations that let us select out the components of structured objects. To construct a structured object, we can assign objects as its components.

Structured types are defined by using type definitions. A type definition lets us define a type and give it a name. We can then use that name in declaring parameters of that type. The form of a type definition is typedef type-expression name ;

Example 1: The record type definition

An example of a record type definition is

typedef record {Node N1; Connection C; Node N2} Network Path; 

Here we have defined Network Path to be a record type with three components: two nodes and a connection. We can select components of a record object using the parameters of the type definition and the "." selection operation. So, if Route is an object of type Network Path, "Route . N1" is the first Node of Route, and so on.

Example 2: The array type definition

An example of an array type definition is

typedef array [1, 2, 3] of String Triplet; 

The index type in "[ , ]" must be an enumeration type, such as Integer. All the components of an array type must be of the same type—in this example, String.

Selection of components is done by applying a value of the index type to an object of the array type using "( )" notation. For example, if ThreeSome is of type Triplet, then ThreeSome(1) is its first string component.

8.3.3 Event Types

Events are objects that are tuples of data. An event contains the values of predefined attributes (such as its action name and its timestamps) as well as additional data parameters.

In Rapide-EPL there is a predefined event type, Event, which is the type of all events. This is the type of all events with any name, any parameter list (which can be empty), and the predefined attributes (which may have undefined values).

It is useful—for example, for efficient pattern matching—to be able to classify events into subtypes. Subtypes of events are declared by action declarations.

An action declaration specifies a subtype of events. An action declaration has the format

action identifier (list of parameter declarations ) ; 

where the identifier is the action name, and the list of parameters in para en-theses declares the tuple of data in the events. The parameter list is a list of declarations that consist of the type of a parameter followed by the name of the parameter. The predefined attributes are always implied members of the list of parameters and are not explicitly declared. An action declaration specifies the set of those events that have the action's name as their action name attribute and contain a tuple of data parameters that conform to the types of the action's parameter declarations.

Example 1: A Warning event

A type of Warning event is

action Warning( Network Path Route; Real Load ); 

Examples of events in this action type are

Warning(London-NewYork, 0.75)
Warning(Paris-London, 0.92) 

However, the following events are not members of this action type:

ConnectTime(London-NewYork, 02.56) -because the action name is not "Warning" 
Warning(UA51, 5000) -because the data parameters are of the wrong types 

Example 2: An Order event

A type of order event in a supply chain system is

action Order(Cust Id Customer, Parts Order Data, Accnt no Accnt, . . . ); 

Here we specify a subtype of events that contain the customer's Id, the order form in a required Parts Order format, the account number, and other data. Order events will also contain the attributes they inherit from the Rapide-EPL event type, such as timestamps.

Figure 8.1 shows three subtypes of events that can be defined by action declarations. Each event subtype defines events from a particular system, or problem domain. The DTP events are the kind of events created by a distributed transaction system, the FAA events are the type of events created in air traffic control, and SPARC V9 events are created by a simulation of a CPU architecture. In each subtype, the events inherit the attributes of the basic event type and contain additional data specific to a particular kind of system.

Figure 8.1Figure 8.1: Subtypes of the RAPIDE event type

The subtype of XML events—that is, events having an XML format—is another example of an event subtype.

The idea behind actions is very simple. We think of an activity in the target system as leading to the creation of an event. We call such an activity an action. We give it a name—its action name—and a list of parameter declarations. The action declaration defines the subtype of the forms of events1 that signify the system activity.

8.3.4 Execution Types

An execution is a poset of events. Its type is called an execution type. An execution type is a set of action declarations specifying the types of events that can happen in an execution. We can define execution types using the keyword execution:

typedef execution {list of action declarations } Name; 

As we shall see, execution types are useful in ensuring the correct use of event processing agents, particularly connecting them to work together.

Example 1: The NetMngmt execution type

If a network monitoring system generates load warnings, connect times, and messages on various topics, we can specify its execution type as consisting of the following event types:

typedef execution {
         action Warning(Network Path Route; Real Load); 
         action Alert(Node Type Node; Real CPU Load, Memory Allocation;
                                                            Int 1 .. 5 Severity; Time Type Time);
         action ConnectTime(Network Path Route; Time Type Time);
         action Send(Subject Type Subject; String Message, Id; Time Type Time);
         action Acknowledge(String Id; Time Type Time) 
      }  NetMngmt ; 

Suppose NetMngmt is the type of execution a network monitor is expected to deal with. Its events are classified into five subtypes, with the action names Warning, Alert, ConnectTime, Send, and Acknowledge. These are the types of events it expects to deal with and should be programmed to handle.

Example 2: The ATM-Use execution type

A similar example is a simple automated bank teller system (ATM). Its execution type might be specified according to three actions that it allows customers to perform at the ATMs:

typedef execution {
     action Deposit(Dollars Amount; Account Type Accnt);
     action Withdraw(Dollars Amount; Account Type Accnt);
     action Transfer(Dollars Amount; Account Type From Accnt, To Accnt) 
   }  ATM-Use ; 

If an ATM's execution type is ATM-Use, we know that its executions can consist only of events with the action names Deposit, Withdraw, and Transfer.

Example 3: The SupplyChainEvents execution type

An execution type for a supply chain

typedef execution {
     action RFQ(RFQId Id; ProdSpec Spec; Dollars Price; Quantity Num; Schedule . . . );
     action Bid(Vendor VId; BidId Id; ProdSpec Spec; Dollars Price; Quantity Num; . . . )
     action Order(OrderId Id; CustId Customer; PartsOrder Data; AccntNo Accnt; . . . );
     action Confirm(OrderId Id; PartsOrder Data; AccntNo Accnt; Schedule Dates; . . . );
      . . . 
}   SupplyChainEvents;

The supply chain execution type defines the types of events that we used in Chapter 2 to illustrate the global event cloud. In real life, of course, it will have many more action types in it. Execution types will eventually be the subject of standardization for particular industries, analogously to the standards for sets of message types today—for example, the ISO 15022 standard for for messaging to execute transactions in financial markets.

8.3.5 Subtyping of Executions

Execution types have a simple subtyping rule:

type T 1 is a subtype of T 2 if T 2  T 1 -- T 1 contains T 2. 

This rule means that T1 is a subtype of T2 if the set of actions in T1 contains all the actions in T2.

This is very similar to the object-oriented subtyping rule: type colored point is a subtype of type point. A colored point contains the X and Y coordinates of a point and the additional color component. The importance in object-oriented programs is that any function that computes on points also computes on colored points because colored points contain all the data it needs—but not conversely. The O-O rule is that you can always evaluate a function on an object of a subtype of a function's input type.

Execution types turn out to be useful when we build networks of agents. Event processing agents (EPAs) are typed with their input and output execution types. This lets us analyze whether or not it is sensible to feed the output of one agent into the input of another. Here's how we do it. Composition of EPAs follows the same rule as function composition in typed languages. Namely, if EPA1 outputs to EPA2, the execution type of the output of EPA1 must be a subtype of the execution type of input expected by EPA2. So, it's just as if EPA1 is pumping out colored points and EPA2 is computing on points.

It is easy to see that we shouldn't try, for example, to hook up a network monitor agent and an ATM agent, because they process entirely different types of events. Such a hookup would be a complete waste of time.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020