Skip to content

Commit 6520036

Browse files
d-leroydvojtise
andauthored
Event management integration (#210)
* instantiate event manager when relationships are provided in .dsl file * queue event occurrences received before engine initialization * add scenario to event metamodel * configure event manager when scenario is provided as part of launch configuration * event manager visible and configurable in engine addons tab * sort event occurrence args to match parameters order * clean up unused code * Update pom.xml * removed plugin from feature Signed-off-by: Dorian Leroy <[email protected]> Co-authored-by: Dorian Leroy <[email protected]> Co-authored-by: Didier Vojtisek <[email protected]>
1 parent c7271dc commit 6520036

File tree

175 files changed

+436
-12509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+436
-12509
lines changed

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.engine/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Require-Bundle: org.eclipse.gemoc.xdsmlframework.api,
1414
org.eclipse.gemoc.trace.gemoc.api;bundle-version="1.0.0",
1515
fr.inria.diverse.k3.al.annotationprocessor.plugin,
1616
org.eclipse.gemoc.trace.commons.model;bundle-version="0.1.0",
17-
org.eclipse.gemoc.executionframework.event.model,
1817
org.eclipse.gemoc.dsl,
1918
org.eclipse.emf.ecore,
2019
org.eclipse.debug.core,

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Require-Bundle: org.eclipse.gemoc.executionframework.event.model;bundle-version=
1010
org.eclipse.ocl.ecore,
1111
org.eclipse.gemoc.dsl,
1212
org.eclipse.gemoc.opsemanticsview.model;bundle-version="3.0.0",
13-
org.eclipse.gemoc.xdsmlframework.api;bundle-version="3.0.0"
13+
org.eclipse.gemoc.xdsmlframework.api;bundle-version="3.0.0",
14+
org.eclipse.gemoc.executionframework.engine,
15+
com.google.guava
1416
Bundle-ManifestVersion: 2
1517
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1618
Automatic-Module-Name: org.eclipse.gemoc.executionframework.event.manager

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/plugin.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@
55
<extension-point id="org.eclipse.gemoc.executionframework.event.implementationrelationship" name="Implementation Relationship" schema="schema/org.eclipse.gemoc.executionframework.event.implementationrelationship.exsd"/>
66
<extension-point id="org.eclipse.gemoc.executionframework.event.subtypingrelationship" name="Subtyping Relationship" schema="schema/org.eclipse.gemoc.executionframework.event.subtypingrelationship.exsd"/>
77
<extension-point id="org.eclipse.gemoc.executionframework.event.metalanguage_rule_executor" name="Metalanguage Rule Executor" schema="schema/org.eclipse.gemoc.executionframework.event.metalanguageruleexecutor.exsd"/>
8+
9+
<extension point="org.eclipse.gemoc.gemoc_language_workbench.engine_addon">
10+
<addon
11+
addonGroupId="General.AddonGroup"
12+
class="org.eclipse.gemoc.executionframework.event.manager.GenericEventManager"
13+
default="false"
14+
id="org.eclipse.gemoc.executionframework.event.manager"
15+
name="Event Manager"
16+
openViewIds="org.eclipse.gemoc.executionframework.event.ui.views.EventManager"
17+
shortDescription="Event handling for any language">
18+
</addon>
19+
</extension>
820
</plugin>

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/schema/org.eclipse.gemoc.executionframework.event.metalanguageruleexecutor.exsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
</appinfo>
6060
</annotation>
6161
</attribute>
62+
<attribute name="metaprog" type="string" use="required">
63+
<annotation>
64+
<documentation>
65+
66+
</documentation>
67+
</annotation>
68+
</attribute>
6269
</complexType>
6370
</element>
6471

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/src/org/eclipse/gemoc/executionframework/event/manager/GenericEventManager.java

Lines changed: 113 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import org.eclipse.emf.ecore.EReference;
2020
import org.eclipse.emf.ecore.resource.Resource;
2121
import org.eclipse.emf.ecore.util.EcoreUtil;
22+
import org.eclipse.gemoc.dsl.Dsl;
23+
import org.eclipse.gemoc.dsl.Entry;
2224
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.BehavioralInterface;
2325
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.Event;
26+
import org.eclipse.gemoc.executionframework.engine.commons.DslHelper;
2427
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrence;
2528
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrenceType;
2629
import org.eclipse.gemoc.executionframework.event.model.event.StopEventOccurrence;
@@ -37,33 +40,81 @@
3740
public class GenericEventManager implements IEventManager {
3841

3942
private final LinkedTransferQueue<ICallRequest> callRequestQueue = new LinkedTransferQueue<>();
43+
44+
private final LinkedTransferQueue<EventOccurrence> eventOccurrenceQueue = new LinkedTransferQueue<>();
4045

4146
private boolean canManageEvents = true;
4247

4348
private boolean waitForCallRequests = false;
4449

4550
private IExecutionEngine<?> engine;
51+
52+
private boolean initialized = false;
4653

4754
private final RelationshipManager relationshipManager;
4855

49-
private IntegrationFacade integrationFacade = null;
50-
51-
public GenericEventManager(String languageName, Resource executedResource,
52-
List<IImplementationRelationship> implementationRelationships,
53-
List<ISubtypingRelationship> subtypingRelationships) {
56+
private final Map<String, IMetalanguageRuleExecutor> metalanguageIntegrations = new HashMap<>();
57+
58+
public GenericEventManager() {
5459
relationshipManager = new RelationshipManager(this);
55-
implementationRelationships.forEach(r -> relationshipManager.registerImplementationRelationship(r));
56-
subtypingRelationships.forEach(r -> relationshipManager.registerSubtypingRelationship(r));
5760
}
58-
61+
5962
public RelationshipManager getRelationshipManager() {
6063
return relationshipManager;
6164
}
6265

66+
@Override
67+
public void engineAboutToStart(IExecutionEngine<?> engine) {
68+
configure(engine);
69+
}
70+
71+
private void configure(IExecutionEngine<?> engine) {
72+
final Dsl dsl = DslHelper.load(engine.getExecutionContext().getLanguageDefinitionExtension().getName());
73+
final Entry implementationRelationshipEntry = dsl.getEntry("implementation_relationships");
74+
if (implementationRelationshipEntry != null) {
75+
final Entry subtypingRelationshipEntry = dsl.getEntry("subtyping_relationships");
76+
List<IImplementationRelationship> implementationRelationships = Arrays.stream(implementationRelationshipEntry.getValue()
77+
.split(",")).map(s -> getImplementationRelationship(s.trim()))
78+
.filter(r -> r != null).collect(Collectors.toList());
79+
List<ISubtypingRelationship> subtypingRelationships = subtypingRelationshipEntry != null
80+
? Arrays.stream(subtypingRelationshipEntry.getValue()
81+
.split(",")).map(s -> getSubtypingRelationship(s.trim()))
82+
.filter(r -> r != null).collect(Collectors.toList())
83+
: Collections.emptyList();
84+
implementationRelationships.forEach(r -> relationshipManager.registerImplementationRelationship(r));
85+
subtypingRelationships.forEach(r -> relationshipManager.registerSubtypingRelationship(r));
86+
}
87+
}
88+
89+
private IImplementationRelationship getImplementationRelationship(String relationshipId) {
90+
IConfigurationElement[] implementationRelationships = Platform.getExtensionRegistry()
91+
.getConfigurationElementsFor("org.eclipse.gemoc.executionframework.event.implementationrelationship");
92+
return Arrays.stream(implementationRelationships).filter(r -> r.getAttribute("id").equals(relationshipId)).findFirst().map(c -> {
93+
try {
94+
return (IImplementationRelationship) c.createExecutableExtension("class");
95+
} catch (CoreException e) {
96+
e.printStackTrace();
97+
}
98+
return null;
99+
}).orElse(null);
100+
}
101+
102+
private ISubtypingRelationship getSubtypingRelationship(String relationshipId) {
103+
IConfigurationElement[] subtypingRelationships = Platform.getExtensionRegistry()
104+
.getConfigurationElementsFor("org.eclipse.gemoc.executionframework.event.subtypingrelationship");
105+
return Arrays.stream(subtypingRelationships).filter(r -> r.getAttribute("id").equals(relationshipId)).findFirst().map(c -> {
106+
try {
107+
return (ISubtypingRelationship) c.createExecutableExtension("Class");
108+
} catch (CoreException e) {
109+
e.printStackTrace();
110+
}
111+
return null;
112+
}).orElse(null);
113+
}
114+
63115
@Override
64116
public void engineInitialized(IExecutionEngine<?> executionEngine) {
65117
engine = executionEngine;
66-
integrationFacade = new IntegrationFacade(engine);
67118
relationshipManager.setExecutedResource(engine.getExecutionContext().getResourceModel());
68119
IConfigurationElement[] eventEmitters = Platform.getExtensionRegistry()
69120
.getConfigurationElementsFor("org.eclipse.gemoc.executionframework.event.event_emitter");
@@ -75,15 +126,23 @@ public void engineInitialized(IExecutionEngine<?> executionEngine) {
75126
e1.printStackTrace();
76127
}
77128
});
129+
initialized = true;
130+
EventOccurrence eventOccurrence = eventOccurrenceQueue.poll();
131+
while (eventOccurrence != null) {
132+
processEventOccurrence(eventOccurrence);
133+
eventOccurrence = eventOccurrenceQueue.poll();
134+
}
78135
}
79136

80137
@Override
81138
public void processEventOccurrence(EventOccurrence eventOccurrence) {
82139
if (eventOccurrence instanceof StopEventOccurrence) {
83140
processCallRequest(new StopRequest());
84-
} else {
141+
} else if (initialized) {
85142
convertEventToExecutedResource(eventOccurrence, engine.getExecutionContext().getResourceModel());
86143
relationshipManager.notifyEventOccurrence(eventOccurrence);
144+
} else {
145+
eventOccurrenceQueue.add(eventOccurrence);
87146
}
88147
}
89148

@@ -145,25 +204,29 @@ public void waitForCallRequests() {
145204

146205
@Override
147206
public void aboutToExecuteStep(IExecutionEngine<?> engine, Step<?> stepToExecute) {
148-
final MSEOccurrence mseOccurrence = stepToExecute.getMseoccurrence();
149-
final String behavioralUnit = mseOccurrence.getMse().getCaller().eClass().getInstanceClassName()
150-
+ "." + mseOccurrence.getMse().getAction().getName();
151-
final Map<String, Object> argsMap = getArguments(mseOccurrence);
152-
final CallNotification callNotification = new CallNotification(behavioralUnit, argsMap);
153-
relationshipManager.notifyCall(callNotification);
154-
processCallRequests();
207+
if (initialized) {
208+
final MSEOccurrence mseOccurrence = stepToExecute.getMseoccurrence();
209+
final String behavioralUnit = mseOccurrence.getMse().getCaller().eClass().getInstanceClassName()
210+
+ "." + mseOccurrence.getMse().getAction().getName();
211+
final Map<String, Object> argsMap = getArguments(mseOccurrence);
212+
final CallNotification callNotification = new CallNotification(behavioralUnit, argsMap);
213+
relationshipManager.notifyCall(callNotification);
214+
processCallRequests();
215+
}
155216
}
156217

157218
@Override
158219
public void stepExecuted(IExecutionEngine<?> engine, Step<?> stepExecuted) {
159-
final MSEOccurrence mseOccurrence = stepExecuted.getMseoccurrence();
160-
final String behavioralUnit = mseOccurrence.getMse().getCaller().eClass().getInstanceClassName()
161-
+ "." + mseOccurrence.getMse().getAction().getName();
162-
final Map<String, Object> argsMap = getArguments(mseOccurrence);
163-
final ReturnNotification returnNotification = new ReturnNotification(behavioralUnit, argsMap,
164-
mseOccurrence.getResult());
165-
relationshipManager.notifyCall(returnNotification);
166-
processCallRequests();
220+
if (initialized) {
221+
final MSEOccurrence mseOccurrence = stepExecuted.getMseoccurrence();
222+
final String behavioralUnit = mseOccurrence.getMse().getCaller().eClass().getInstanceClassName()
223+
+ "." + mseOccurrence.getMse().getAction().getName();
224+
final Map<String, Object> argsMap = getArguments(mseOccurrence);
225+
final ReturnNotification returnNotification = new ReturnNotification(behavioralUnit, argsMap,
226+
mseOccurrence.getResult());
227+
relationshipManager.notifyCall(returnNotification);
228+
processCallRequests();
229+
}
167230
}
168231

169232
private Map<String, Object> getArguments(MSEOccurrence mseOccurrence) {
@@ -204,11 +267,34 @@ private void handleCallRequest(ICallRequest callRequest) {
204267
((CompositeCallRequest) callRequest).getCallRequests().forEach(cr -> handleCallRequest(cr));
205268
} else if (callRequest instanceof SimpleCallRequest) {
206269
final SimpleCallRequest simpleCallRequest = (SimpleCallRequest) callRequest;
207-
integrationFacade.handleCallRequest(simpleCallRequest);
270+
final IMetalanguageRuleExecutor ruleExecutor = metalanguageIntegrations
271+
.computeIfAbsent(simpleCallRequest.getMetalanguage(), m -> findMetalanguageRuleExecutor(m));
272+
if (ruleExecutor != null) {
273+
ruleExecutor.handleCallRequest(simpleCallRequest);
274+
} else {
275+
throw new IllegalArgumentException(
276+
"No metalanguage rule executor was found for metalanguage " + simpleCallRequest.getMetalanguage());
277+
}
208278
}
209279
}
210280
}
211281

282+
private IMetalanguageRuleExecutor findMetalanguageRuleExecutor(String metalanguage) {
283+
return Arrays
284+
.stream(Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.gemoc.executionframework.event.metalanguage_rule_executor"))
285+
.filter(c -> c.getAttribute("metaprog").equals(metalanguage))
286+
.findFirst().map(c -> {
287+
IMetalanguageRuleExecutor result = null;
288+
try {
289+
result = (IMetalanguageRuleExecutor) c.createExecutableExtension("class");
290+
result.setExecutionEngine(engine);
291+
} catch (CoreException e) {
292+
e.printStackTrace();
293+
}
294+
return result;
295+
}).orElse(null);
296+
}
297+
212298
@SuppressWarnings({ "rawtypes", "unchecked" })
213299
private void convertReferences(EObject object, Resource executedResource, String executedResourceURI) {
214300
final List<EReference> references = object.eClass().getEAllReferences();
@@ -305,4 +391,5 @@ public void emitEventOccurrence(EventOccurrence eventOccurrence) {
305391
public void processCallRequest(ICallRequest callRequest) {
306392
callRequestQueue.put(callRequest);
307393
}
394+
308395
}

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/src/org/eclipse/gemoc/executionframework/event/manager/IEventManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import java.util.Set;
44

5-
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrence;
6-
import org.eclipse.gemoc.xdsmlframework.api.engine_addon.IEngineAddon;
75
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.BehavioralInterface;
86
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.Event;
7+
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrence;
8+
import org.eclipse.gemoc.xdsmlframework.api.engine_addon.IEngineAddon;
99

1010
public interface IEventManager extends IEngineAddon {
1111

@@ -28,4 +28,5 @@ public interface IEventManager extends IEngineAddon {
2828
void emitEventOccurrence(EventOccurrence eventOccurrence);
2929

3030
void processCallRequest(ICallRequest callRequest);
31+
3132
}

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.manager/src/org/eclipse/gemoc/executionframework/event/manager/SimpleImplementationRelationship.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrenceArgument;
1414
import org.eclipse.gemoc.executionframework.event.model.event.EventOccurrenceType;
1515
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.BehavioralInterface;
16+
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.BehavioralInterfacePackage;
1617
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.Event;
18+
import org.eclipse.gemoc.executionframework.behavioralinterface.behavioralInterface.EventParameter;
1719

1820
public class SimpleImplementationRelationship implements IImplementationRelationship {
1921

@@ -84,8 +86,11 @@ public SimpleImplementationRelationship(BehavioralInterface behavioralInterface,
8486
if (eventOccurrence.getType() == EventOccurrenceType.ACCEPTED) {
8587
final String eventName = eventOccurrence.getEvent().getName();
8688
final String name = eventNameToExecutionRule.computeIfAbsent(eventName, s -> s.substring(5));
87-
89+
final List<EventParameter> eventParameters = eventOccurrence.getEvent().getParams();
8890
final List<Object> arguments = eventOccurrence.getArgs().stream()
91+
.sorted((arg1, arg2) -> {
92+
return eventParameters.indexOf(arg1.getParameter()) - eventParameters.indexOf(arg2.getParameter());
93+
})
8994
.map(a -> EventManagerUtils.convertValueToObject(a.getValue())).collect(Collectors.toList());
9095

9196
final boolean rtc = this.runToCompletionSet.contains(name);
@@ -95,7 +100,7 @@ public SimpleImplementationRelationship(BehavioralInterface behavioralInterface,
95100
return null;
96101
};
97102
}
98-
103+
99104
@Override
100105
public BehavioralInterface getBehavioralInterface() {
101106
return behavioralInterface;

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.model.edit/.classpath

Lines changed: 0 additions & 7 deletions
This file was deleted.

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.model.edit/.project

Lines changed: 0 additions & 28 deletions
This file was deleted.

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.event.model.edit/META-INF/MANIFEST.MF

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)