Skip to content

Commit 07a4daa

Browse files
committed
Refactor to support MEP at engine level
1 parent 98866bf commit 07a4daa

File tree

5 files changed

+136
-139
lines changed

5 files changed

+136
-139
lines changed

java_engine/pomfirst/org.eclipse.gemoc.execution.sequential.javaengine.headless/src/main/java/org/eclipse/gemoc/execution/sequential/javaengine/headless/HeadlessPlainK3ExecutionEngine.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44

55
import java.io.ByteArrayOutputStream;
6+
import java.io.EOFException;
67
import java.io.IOException;
78
import java.io.ObjectInputStream;
89
import java.io.ObjectOutputStream;
910
import java.io.PrintStream;
1011
import java.lang.reflect.InvocationTargetException;
1112
import java.lang.reflect.Method;
13+
import java.net.ConnectException;
1214
import java.net.ServerSocket;
1315
import java.net.Socket;
1416
import java.util.ArrayList;
@@ -31,7 +33,6 @@
3133
import org.eclipse.core.runtime.spi.RegistryStrategy;
3234
import org.eclipse.emf.common.util.BasicEList;
3335
import org.eclipse.emf.common.util.EList;
34-
import org.eclipse.emf.common.util.TreeIterator;
3536
import org.eclipse.emf.common.util.URI;
3637
import org.eclipse.emf.ecore.EObject;
3738
import org.eclipse.emf.ecore.resource.Resource;
@@ -50,16 +51,21 @@
5051
import org.eclipse.gemoc.execution.sequential.javaengine.headless.commands.StopCommand;
5152
import org.eclipse.gemoc.execution.sequential.javaengine.headless.commands.StopCondition;
5253
import org.eclipse.gemoc.execution.sequential.javaengine.headless.commands.StopEvent;
53-
import org.eclipse.gemoc.execution.sequential.javaengine.headless.commands.StopReason;
5454
import org.eclipse.gemoc.execution.sequential.javaengine.headless.commands.ToggleBreakpointCommand;
5555
import org.eclipse.gemoc.executionframework.debugger.DefaultDynamicPartAccessor;
5656
import org.eclipse.gemoc.executionframework.debugger.IDynamicPartAccessor;
5757
import org.eclipse.gemoc.executionframework.debugger.MutableField;
58+
import org.eclipse.gemoc.executionframework.engine.commons.EngineContextException;
5859
import org.eclipse.gemoc.executionframework.engine.commons.GenericModelExecutionContext;
5960
import org.eclipse.gemoc.executionframework.engine.commons.K3DslHelper;
6061
import org.eclipse.gemoc.executionframework.engine.commons.sequential.ISequentialRunConfiguration;
6162
import org.eclipse.gemoc.executionframework.engine.core.AbstractCommandBasedSequentialExecutionEngine;
6263
import org.eclipse.gemoc.executionframework.engine.core.EngineStoppedException;
64+
import org.eclipse.gemoc.executionframework.mep.engine.IMEPEngine;
65+
import org.eclipse.gemoc.executionframework.mep.engine.IMEPEventListener;
66+
import org.eclipse.gemoc.executionframework.mep.events.StoppedReason;
67+
import org.eclipse.gemoc.executionframework.mep.types.Variable;
68+
import org.eclipse.gemoc.xdsmlframework.api.core.ExecutionMode;
6369
import org.eclipse.gemoc.xdsmlframework.api.extensions.languages.LanguageDefinitionExtension;
6470
import org.eclipse.jdt.core.IPackageFragmentRoot;
6571
import org.eclipse.jdt.core.IType;
@@ -70,6 +76,9 @@
7076
import org.eclipse.jdt.core.search.SearchParticipant;
7177
import org.eclipse.jdt.core.search.SearchPattern;
7278
import org.eclipse.jdt.core.search.SearchRequestor;
79+
import org.eclipse.jdt.internal.compiler.ast.Clinit;
80+
import org.eclipse.lsp4j.debug.StoppedEventArguments;
81+
import org.eclipse.lsp4j.debug.TerminatedEventArguments;
7382
import org.eclipse.xtext.nodemodel.ICompositeNode;
7483
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
7584
import org.osgi.framework.Bundle;
@@ -90,7 +99,7 @@
9099
* @author Didier Vojtisek<[email protected]>
91100
*
92101
*/
93-
public class HeadlessPlainK3ExecutionEngine< L extends LanguageDefinitionExtension> extends AbstractCommandBasedSequentialExecutionEngine<AbstractHeadlessExecutionContext<ISequentialRunConfiguration, L >, ISequentialRunConfiguration> implements IStepManager {
102+
public class HeadlessPlainK3ExecutionEngine<L extends LanguageDefinitionExtension> extends AbstractCommandBasedSequentialExecutionEngine<AbstractHeadlessExecutionContext<ISequentialRunConfiguration, L >, ISequentialRunConfiguration> implements IStepManager {
94103
//public class HeadlessPlainK3ExecutionEngine< L extends LanguageDefinitionExtension> extends AbstractSequentialExecutionEngine<AbstractHeadlessExecutionContext<ISequentialRunConfiguration, L >, ISequentialRunConfiguration> implements IStepManager {
95104

96105

@@ -108,7 +117,7 @@ public class HeadlessPlainK3ExecutionEngine< L extends LanguageDefinitionExtensi
108117
private Map<Integer, Boolean> breakpoints;
109118

110119
private ByteArrayOutputStream outputStream;
111-
120+
112121
@Override
113122
public String engineKindName() {
114123
return "GEMOC Kermeta HEADLESS Sequential Engine";
@@ -470,7 +479,7 @@ public void executeStep(Object caller, final StepCommand command, String classNa
470479
if (node != null && breakpoints.containsKey(node.getStartLine())) {
471480
continueSimulation = false;
472481
updateVariables();
473-
sendStopEvent(StopReason.REACHED_BREAKPOINT);
482+
sendStopEvent(StoppedReason.REACHED_BREAKPOINT);
474483
increment(finishDoStepSemaphore);
475484
decrement(startDoStepSemaphore);
476485
stepCaller = eObj;
@@ -663,11 +672,6 @@ public static Resource loadModel(URI modelURI) {
663672
}
664673
return resource;
665674
}
666-
667-
//
668-
// Simulation Server
669-
670-
671675

672676
// semaphore for locking doStep
673677
Semaphore startDoStepSemaphore;
@@ -755,19 +759,15 @@ protected void simulate() throws Exception {
755759
increment(startDoStepSemaphore);
756760
decrement(finishDoStepSemaphore);
757761
}
758-
/*
759-
if(clientCommand instanceof SetVariableCommand) {
760-
String varQN = ((SetVariableCommand) clientCommand).variableQualifiedName;
761-
Object newValue = ((SetVariableCommand) clientCommand).newValue;
762-
Boolean res = this.setVariable(varQN, newValue);
763-
cout.writeObject(res);
764-
}*/
765762
System.out.println("wait for a new command.");
766763
} while(!simulationEnded);
764+
767765
solverThread.join();
766+
768767
if (stopReceived) {
769768
cout.writeObject(Boolean.TRUE);
770769
}
770+
clientSocket.close();
771771
serverSocket.close();
772772

773773
if (exceptionQueue.isEmpty()) {
@@ -800,7 +800,7 @@ public Thread launchEntryPointInThread(BlockingQueue<Exception> exceptionQueue)
800800
}
801801
}
802802
if (continueSimulation) {
803-
sendStopEvent(StopReason.REACHED_SIMULATION_END);
803+
sendStopEvent(StoppedReason.REACHED_SIMULATION_END);
804804
}
805805
updateVariables();
806806
simulationEnded = true;
@@ -814,7 +814,7 @@ public Thread launchEntryPointInThread(BlockingQueue<Exception> exceptionQueue)
814814
return simulationThread;
815815
}
816816

817-
public void sendStopEvent(StopReason stopReason) {
817+
public void sendStopEvent(StoppedReason stopReason) {
818818
StopEvent stopEvent = new StopEvent();
819819
stopEvent.stopReason = stopReason;
820820
try {
@@ -832,9 +832,9 @@ public StopCondition doStep() {
832832
updateVariables();
833833

834834
if (simulationEnded) {
835-
lastStopcondition = new StopCondition(StopReason.REACHED_SIMULATION_END);
835+
lastStopcondition = new StopCondition(StoppedReason.REACHED_SIMULATION_END);
836836
} else {
837-
lastStopcondition = new StopCondition(StopReason.REACHED_NEXT_LOGICAL_STEP);
837+
lastStopcondition = new StopCondition(StoppedReason.REACHED_NEXT_LOGICAL_STEP);
838838
}
839839
return lastStopcondition;
840840
}

0 commit comments

Comments
 (0)