瀏覽代碼

Added exceptionhandling for exceptions raised from referenced code in statechart simulation for eventdriven and cyclebased simulations. Updated snippets in manual testcases. (#1686)

Robert Rudi 7 年之前
父節點
當前提交
166efd577b

文件差異過大導致無法顯示
+ 1 - 1
manual-tests/org.yakindu.sct.test.manual/testcases/sct_testcase_03_simulation.textile


文件差異過大導致無法顯示
+ 3 - 6
manual-tests/org.yakindu.sct.test.manual/testcases/sct_testcase_06_expression_language_proposals.textile


文件差異過大導致無法顯示
+ 5 - 5
manual-tests/org.yakindu.sct.test.manual/testcases/sct_testcase_09_template_proposals.textile


+ 12 - 4
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/AbstractExecutionFlowSimulationEngine.java

@@ -96,8 +96,12 @@ public class AbstractExecutionFlowSimulationEngine extends AbstractSimulationEng
 	}
 
 	public void suspend() {
-		suspended = true;
-		timeTaskScheduler.suspend();
+		try {
+			suspended = true;
+			timeTaskScheduler.suspend();
+		} catch (Exception ex) {
+			handleException(ex);
+		}
 	}
 
 	public void resume() {
@@ -111,8 +115,12 @@ public class AbstractExecutionFlowSimulationEngine extends AbstractSimulationEng
 	}
 
 	public void terminate() {
-		terminated = true;
-		timeTaskScheduler.terminate();
+		try {
+			terminated = true;
+			timeTaskScheduler.terminate();
+		} catch (Exception ex) {
+			handleException(ex);
+		}
 	}
 
 	public void stepForward() {

+ 7 - 1
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/CycleBasedSimulationEngine.java

@@ -54,7 +54,13 @@ public class CycleBasedSimulationEngine extends AbstractExecutionFlowSimulationE
 					SRuntimeFactory.eINSTANCE.createExecutionContext());
 		}
 
-		TimeTask cycleTask = new TimeTask("$cycle", () -> interpreter.runCycle(), Priority.LOW);
+		TimeTask cycleTask = new TimeTask("$cycle", () -> {
+			try {
+				interpreter.runCycle();
+			} catch (Exception e) {
+				handleException(e);
+			}
+		}, Priority.LOW);
 		timeTaskScheduler.scheduleTimeTask(cycleTask, true, cyclePeriod);
 	}
 }

+ 120 - 116
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/EventDrivenSimulationEngine.java

@@ -1,116 +1,120 @@
-/**
- * Copyright (c) 2012 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * Contributors:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-
-package org.yakindu.sct.simulation.core.sexec.container;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.util.EContentAdapter;
-import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.model.sruntime.ExecutionEvent;
-import org.yakindu.sct.model.sruntime.SRuntimePackage;
-import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
-import org.yakindu.sct.simulation.core.sexec.interpreter.IExecutionFlowInterpreter;
-
-/**
- * Event Driven implementation of the {@link ISimulationEngine}.
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class EventDrivenSimulationEngine extends AbstractExecutionFlowSimulationEngine {
-
-	private EventDrivenCycleAdapter cycleAdapter;
-
-	public EventDrivenSimulationEngine(Statechart statechart) {
-		super(statechart);
-	}
-
-	@Override
-	public void init() {
-		super.init();
-		cycleAdapter = new EventDrivenCycleAdapter(interpreter);
-		context.eAdapters().add(cycleAdapter);
-	}
-
-	@Override
-	public void terminate() {
-		context.eAdapters().remove(cycleAdapter);
-		super.terminate();
-	}
-
-	@Override
-	public void suspend() {
-		cycleAdapter.suspend();
-		super.suspend();
-	}
-
-	@Override
-	public void resume() {
-		cycleAdapter.resume();
-		super.resume();
-	}
-
-	@Override
-	public void stepForward() {
-		interpreter.runCycle();
-		super.stepForward();
-	}
-
-	@Override
-	protected boolean useInternalEventQueue() {
-		return true;
-	}
-
-	public static class EventDrivenCycleAdapter extends EContentAdapter {
-
-		private IExecutionFlowInterpreter interpreter;
-
-		private boolean suspended = false;
-		private boolean cycleAfterResume = false;
-
-		public EventDrivenCycleAdapter(IExecutionFlowInterpreter interpreter) {
-			this.interpreter = interpreter;
-
-		}
-
-		public void notifyChanged(Notification notification) {
-			super.notifyChanged(notification);
-			if (notification.getNotifier() instanceof ExecutionEvent
-					&& notification.getFeature() == SRuntimePackage.Literals.EXECUTION_EVENT__RAISED) {
-				if (notification.getNewBooleanValue() != notification.getOldBooleanValue()) {
-					if (notification.getNewBooleanValue()) {
-						if (!suspended)
-							interpreter.runCycle();
-						else {
-							cycleAfterResume = true;
-						}
-					}
-				}
-			}
-
-		}
-
-		public boolean isAdapterForType(Object type) {
-			return type == EventDrivenCycleAdapter.class;
-		}
-
-		public void suspend() {
-			suspended = true;
-		}
-
-		public void resume() {
-			suspended = false;
-			if (cycleAfterResume)
-				interpreter.runCycle();
-			cycleAfterResume = false;
-		}
-	}
-}
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+
+package org.yakindu.sct.simulation.core.sexec.container;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sruntime.ExecutionEvent;
+import org.yakindu.sct.model.sruntime.SRuntimePackage;
+import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
+import org.yakindu.sct.simulation.core.sexec.interpreter.IExecutionFlowInterpreter;
+
+/**
+ * Event Driven implementation of the {@link ISimulationEngine}.
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class EventDrivenSimulationEngine extends AbstractExecutionFlowSimulationEngine {
+
+	private EventDrivenCycleAdapter cycleAdapter;
+
+	public EventDrivenSimulationEngine(Statechart statechart) {
+		super(statechart);
+	}
+
+	@Override
+	public void init() {
+		super.init();
+		cycleAdapter = new EventDrivenCycleAdapter(interpreter);
+		context.eAdapters().add(cycleAdapter);
+	}
+
+	@Override
+	public void terminate() {
+		context.eAdapters().remove(cycleAdapter);
+		super.terminate();
+	}
+
+	@Override
+	public void suspend() {
+		cycleAdapter.suspend();
+		super.suspend();
+	}
+
+	@Override
+	public void resume() {
+		cycleAdapter.resume();
+		super.resume();
+	}
+
+	@Override
+	public void stepForward() {
+		try {
+			interpreter.runCycle();
+		} catch (Exception ex) {
+			handleException(ex);
+		}
+		super.stepForward();
+	}
+
+	@Override
+	protected boolean useInternalEventQueue() {
+		return true;
+	}
+
+	public static class EventDrivenCycleAdapter extends EContentAdapter {
+
+		
+		private IExecutionFlowInterpreter interpreter;
+
+		private boolean suspended = false;
+		private boolean cycleAfterResume = false;
+
+		public EventDrivenCycleAdapter(IExecutionFlowInterpreter interpreter) {
+			this.interpreter = interpreter;
+		}
+
+		public void notifyChanged(Notification notification) {
+			super.notifyChanged(notification);
+			if (notification.getNotifier() instanceof ExecutionEvent
+					&& notification.getFeature() == SRuntimePackage.Literals.EXECUTION_EVENT__RAISED) {
+				if (notification.getNewBooleanValue() != notification.getOldBooleanValue()) {
+					if (notification.getNewBooleanValue()) {
+						if (!suspended) 
+							interpreter.runCycle();
+						else {
+							cycleAfterResume = true;
+						}
+					}
+				}
+			}
+
+		}
+		
+		public boolean isAdapterForType(Object type) {
+			return type == EventDrivenCycleAdapter.class;
+		}
+
+		public void suspend() {
+			suspended = true;
+		}
+
+		public void resume() {
+			suspended = false;
+			if (cycleAfterResume)
+				interpreter.runCycle();
+			cycleAfterResume = false;
+		}
+	}
+}