Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

VIATRA/CEP/Examples/ModelEvents

< VIATRA‎ | CEP‎ | Examples

Example #2: Processing model change events

A unique feature of the VIATRA-CEP framework is the seamless integration with the model management framework EMF and the incremental graph pattern matcher EMF-IncQuery. This enables observing special events, which depict compound model changes in an underlying EMF model. A compound model change is a series of elementary model changes (ADD, MODIFY, DELETE, etc). To depict compound model changes, the EMF-IncQuery framework is used.

To demonstrate this scenario, we take the previous example and will model the SC3O complex event.

The underlying model and the graph patterns

The whole sample project for the model is available here.

First, we need an Ecore metamodel to track the changes in the room.

Fowler-meta.PNG

Using a Generator Model, we generate the model code.

Now we can define graph patterns via EMF-IncQuery. To simplify the example, we only want to observe the states of drawers. Therefore, we define the following graph patterns.

Fowler-iq.PNG

Event patterns

The whole sample project with the event patterns is available here.

We will reuse these IncQuery graph patterns in event patterns via the QueryResultChangeEvent type, which is actually a special Atomic event pattern: they refer to previously defined IncQuery graph patterns and are matched if the referred graph pattern appears or disappears.

QueryResultChangeEvent drawerOpens(id: String){
     query: drawerIsOpen(_, id)
     resultChangeType: NEW_MATCH_FOUND
}

The above event pattern will match if a new match of the drawerIsOpen graph pattern is found. Its counterpart is one being matched if an existing graph pattern is lost:

QueryResultChangeEvent drawerClosing(id: String){
     query: drawerIsClosed(_, id)
     resultChangeType: NEW_MATCH_FOUND
}

The complex event pattern for opening and closing the same drawer twice will look like this:

ComplexEvent SC3O_3(drawerId: String){
     definition: (drawerOpens(id) -> drawerClosing(id)){2}
}

After adding the appropriate rule and running the simulation, we get the expected result:

drawer1.setOpen(true);
drawer1.setOpen(false);
drawer1.setOpen(true);
drawer1.setOpen(false);
Opening compartment #3

Back to the top