Browse Source

Fixed bugs regarding event driven execution model

terfloth@itemis.de 13 years ago
parent
commit
d9e5f3e224

+ 32 - 24
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/impl/BufferingExecutionContext.java

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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
@@ -21,17 +21,24 @@ import org.yakindu.sct.model.sgraph.RegularState;
 import org.yakindu.sct.simulation.core.runtime.ExecutionException;
 import org.yakindu.sct.simulation.core.runtime.IExecutionContext;
 import org.yakindu.sct.simulation.core.runtime.IExecutionContextListener;
+import org.yakindu.sct.simulation.core.runtime.impl.ExecutionContextImpl;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable;
 import org.yakindu.sct.simulation.core.runtime.timer.VirtualClock;
 
-public class BufferingExecutionContext implements IExecutionContext {
+public class BufferingExecutionContext extends ExecutionContextImpl implements IExecutionContextListener {
 
 	protected IExecutionContext delegate;
+	protected boolean delegateNotify = true;
 
-	private HashMap<String, Object> raisedEvents = new HashMap<String, Object>();
 	private HashMap<String, Object> setVariables = new HashMap<String, Object>();
 
+	
+	public BufferingExecutionContext(IExecutionContext delegate) {
+		this.delegate = delegate;
+		delegate.addExecutionContextListener(this);
+	}
+
 	public List<ExecutionEvent> getDeclaredEvents() {
 		return delegate.getDeclaredEvents();
 	}
@@ -40,18 +47,14 @@ public class BufferingExecutionContext implements IExecutionContext {
 		delegate.declareEvent(event);
 	}
 
-	public List<ExecutionEvent> getRaisedEvents() {
-		return delegate.getRaisedEvents();
-	}
 
 	public void resetRaisedEvents() {
 		delegate.resetRaisedEvents();
 	}
 
-	public void raiseEvent(String name, Object value) throws ExecutionException {
-		synchronized (raisedEvents) {
-			raisedEvents.put(name, value);
-		}
+	
+	public ExecutionEvent getDeclaredEvent(String eventName) {
+		return delegate.getDeclaredEvent(eventName);
 	}
 
 	public boolean isEventRaised(String eventName) {
@@ -79,11 +82,12 @@ public class BufferingExecutionContext implements IExecutionContext {
 
 	public void flush() {
 		synchronized (raisedEvents) {
-			Set<Entry<String, Object>> entrySet = raisedEvents.entrySet();
-			for (Entry<String, Object> entry : entrySet) {
-				delegate.raiseEvent(entry.getKey(), entry.getValue());
+			delegateNotify = false;
+			for (ExecutionEvent event : raisedEvents) {
+				delegate.raiseEvent(event.getName(), event.getValue());
 			}
 			raisedEvents.clear();
+			delegateNotify = true;
 		}
 		synchronized (setVariables) {
 			Set<Entry<String, Object>> entrySet = setVariables.entrySet();
@@ -114,15 +118,6 @@ public class BufferingExecutionContext implements IExecutionContext {
 		delegate.call(procedureId);
 	}
 
-	public void addExecutionContextListener(IExecutionContextListener listener) {
-		delegate.addExecutionContextListener(listener);
-	}
-
-	public void removeExecutionContextListener(
-			IExecutionContextListener listener) {
-		delegate.removeExecutionContextListener(listener);
-	}
-
 	public double getTimeScaleFactor() {
 		return delegate.getTimeScaleFactor();
 	}
@@ -143,8 +138,21 @@ public class BufferingExecutionContext implements IExecutionContext {
 		delegate.saveHistoryStateConfiguration(region);
 	}
 
-	public BufferingExecutionContext(IExecutionContext delegate) {
-		this.delegate = delegate;
+
+	public void eventRaised(ExecutionEvent event) {
+		if ( delegateNotify ) {
+			notifyEventRaised(event);
+		}
+	}
+
+	public void variableValueChanged(ExecutionVariable variable) {
+		notifyVariableValueChanged(variable);
+		
+	}
+
+	public void timeScaleFactorChanged(double oldFactor, double newFactor) {
+		notifyTimeScaleFactorChanged(oldFactor, newFactor);
 	}
 
+	
 }

+ 2 - 2
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/impl/ExecutionFlowInterpreter.xtend

@@ -305,7 +305,7 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 	def dispatch execute(SaveHistory action){
 		executionContext.saveHistoryStateConfiguration(action.region);
 		null
-	}
+	} 
 	
 	def dispatch execute(StateSwitch stateSwitch){
 		val historyRegion = stateSwitch.historyRegion
@@ -329,7 +329,7 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 	def dispatch execute(ScheduleTimeEvent scheduleTimeEvent){
 		var timeEvent = scheduleTimeEvent.timeEvent
 		var duration = interpreter.evaluateStatement(scheduleTimeEvent.timeValue, executionContext)
-		timingService.scheduleTimeEvent(executionContext,timeEvent.name,timeEvent.periodic, duration as Integer)
+		timingService.scheduleTimeEvent(externalExecutionContext,timeEvent.name,timeEvent.periodic, duration as Integer)
 		null
 	}
 	

+ 1 - 1
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/stext/StextStatementInterpreter.xtend

@@ -9,7 +9,7 @@
  * 
  */
 package org.yakindu.sct.model.sexec.interpreter.stext
-
+ 
 import org.yakindu.sct.model.sexec.interpreter.IStatementInterpreter
 import org.yakindu.sct.simulation.core.IExecutionContext
 import org.yakindu.sct.model.sgraph.Statement

+ 1 - 1
plugins/org.yakindu.sct.model.sexec.interpreter/xtend-gen/org/yakindu/sct/model/sexec/interpreter/impl/ExecutionFlowInterpreter.java

@@ -534,7 +534,7 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
       Object duration = _evaluateStatement;
       String _name = timeEvent.getName();
       boolean _isPeriodic = timeEvent.isPeriodic();
-      this.timingService.scheduleTimeEvent(this.executionContext, _name, _isPeriodic, ((Integer) duration));
+      this.timingService.scheduleTimeEvent(this.externalExecutionContext, _name, _isPeriodic, ((Integer) duration));
       _xblockexpression = (null);
     }
     return _xblockexpression;

+ 2 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/IExecutionContext.java

@@ -130,4 +130,6 @@ public interface IExecutionContext {
 
 	public void saveHistoryStateConfiguration(ExecutionRegion region);
 
+	public abstract ExecutionEvent getDeclaredEvent(String eventName);
+
 }

+ 4 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/impl/AbstractExecutionContext.java

@@ -68,4 +68,8 @@ public abstract class AbstractExecutionContext implements IExecutionContext {
 		}
 	}
 
+	public ExecutionEvent getDeclaredEvent(String eventName) {
+		return null;
+	}
+
 }

+ 3 - 2
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/impl/ExecutionContextImpl.java

@@ -40,7 +40,7 @@ public class ExecutionContextImpl extends AbstractExecutionContext implements
 
 	private List<ExecutionVariable> variables;
 	private List<ExecutionEvent> declaredEvents;
-	private List<ExecutionEvent> raisedEvents;
+	protected List<ExecutionEvent> raisedEvents;
 	private ExecutionState[] activeStateConfig;
 	private Map<Integer, ExecutionState> historyStateConfig;
 	private double timeScaleFactor;
@@ -93,7 +93,8 @@ public class ExecutionContextImpl extends AbstractExecutionContext implements
 		}
 	}
 
-	private ExecutionEvent getDeclaredEvent(String eventName) {
+	@Override
+	public ExecutionEvent getDeclaredEvent(String eventName) {
 		synchronized (declaredEvents) {
 			for (ExecutionEvent event : declaredEvents) {
 				if (event.getName().equals(eventName))

+ 1 - 1
test-plugins/org.yakindu.sct.model.sexec.interpreter.test/src/org/yakindu/sct/model/sexec/interpreter/test/AbstractSTextTest.java

@@ -35,7 +35,7 @@ public class AbstractSTextTest {
 	@Inject
 	private XtextResource resource;
 	@Inject 
-	private ExecutionContextImpl context;
+	private IExecutionContext context;
 	@Inject
 	private StextStatementInterpreter interpreter;