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

Difference between revisions of "VIATRA/CEP/Examples/ModelEvents"

< VIATRA‎ | CEP‎ | Examples
 
Line 5: Line 5:
  
 
===The underlying model and the graph patterns===
 
===The underlying model and the graph patterns===
The whole sample project for the model is available [https://github.com/david-istvan/viatra-cep-examples/tree/master/fowler/org.eclipse.viatra.cep.examples.fowler.incquery.model here].
+
The whole sample project for the model is available [http://git.eclipse.org/c/viatra/org.eclipse.viatra.examples.git/tree/cep/fowler/org.eclipse.viatra.cep.examples.fowler.incquery.model here].
  
 
First, we need an Ecore metamodel to track the changes in the room.
 
First, we need an Ecore metamodel to track the changes in the room.
Line 18: Line 18:
  
 
===Event patterns===
 
===Event patterns===
The whole sample project with the event patterns is available [https://github.com/david-istvan/viatra-cep-examples/tree/master/fowler/org.eclipse.viatra.cep.examples.fowler.incquery here].
+
The whole sample project with the event patterns is available [http://git.eclipse.org/c/viatra/org.eclipse.viatra.examples.git/tree/cep/fowler/org.eclipse.viatra.cep.examples.fowler.incquery here].
  
 
We will reuse these IncQuery graph patterns in event patterns via the [[VIATRA/CEP/Language#Query_result_change_event_patterns|QueryResultChangeEvent]] type, which is actually a special [[VIATRA/CEP/Language#Atomic_event_patterns|Atomic event pattern]]: they refer to previously defined IncQuery graph patterns and are matched if the referred graph pattern appears or disappears.
 
We will reuse these IncQuery graph patterns in event patterns via the [[VIATRA/CEP/Language#Query_result_change_event_patterns|QueryResultChangeEvent]] type, which is actually a special [[VIATRA/CEP/Language#Atomic_event_patterns|Atomic event pattern]]: they refer to previously defined IncQuery graph patterns and are matched if the referred graph pattern appears or disappears.
Line 40: Line 40:
 
  }
 
  }
  
After adding the appropriate rule and running the [https://github.com/david-istvan/viatra-cep-examples/blob/master/fowler/org.eclipse.viatra.cep.examples.fowler.incquery/src/org/eclipse/viatra/cep/examples/fowler/incquery/main/Main.java simulation], we get the expected result:
+
After adding the appropriate rule and running the [http://git.eclipse.org/c/viatra/org.eclipse.viatra.examples.git/tree/cep/fowler/org.eclipse.viatra.cep.examples.fowler.incquery/src/org/eclipse/viatra/cep/examples/fowler/incquery/main/Main.java simulation], we get the expected result:
  
 
  drawer1.setOpen(true);
 
  drawer1.setOpen(true);

Latest revision as of 06:45, 3 May 2015

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