Browse Source

Updated TimerHandler to support many statemachines.
Updated examples and test cases.

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
2da7014ef4
18 changed files with 75 additions and 39 deletions
  1. 10 0
      Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java
  2. 3 9
      Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimerHandler.java
  3. 10 0
      Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java
  4. 1 1
      Examples/org.yakindu.sct.generator.java.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemo.java
  5. 3 0
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomCycleBasedStatemachine.xpt
  6. 16 7
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/TimeEvent.xpt
  7. 6 12
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/TimerHandler.xpt
  8. 10 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java
  9. 3 9
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/TimerHandler.java
  10. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/interfacetest/InterfaceTestCycleBasedStatemachine.java
  11. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_deephistory/Test_DeepHistoryCycleBasedStatemachine.java
  12. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_expression/Test_ExpressionCycleBasedStatemachine.java
  13. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_hierarchy/Test_HierarchyCycleBasedStatemachine.java
  14. 3 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/Test_LocalActionsCycleBasedStatemachine.java
  15. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java
  16. 1 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_shallowhistory/Test_ShallowHistoryCycleBasedStatemachine.java
  17. 3 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/Test_TransitionCycleBasedStatemachine.java
  18. 1 1
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestLocalActionsCycleBasedStatemachine.java

+ 10 - 0
Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java

@@ -14,6 +14,8 @@ public class TimeEvent extends ValuedEvent<Boolean> {
 
 	private long time = -1;
 
+	private ITimedStatemachine statemachine;
+
 	public TimeEvent(String name, boolean periodic) {
 		super(name, periodic);
 	}
@@ -25,4 +27,12 @@ public class TimeEvent extends ValuedEvent<Boolean> {
 	public long getTime() {
 		return time;
 	}
+
+	public ITimedStatemachine getStatemachine() {
+		return statemachine;
+	}
+
+	public void setStatemachine(ITimedStatemachine statemachine) {
+		this.statemachine = statemachine;
+	}
 }

+ 3 - 9
Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimerHandler.java

@@ -19,15 +19,9 @@ import org.yakindu.sct.runtime.java.EventNotification;
 
 public class TimerHandler implements ITimerHandler {
 
-	private final ITimedStatemachine statemachine;
-
 	private final Timer timer = new Timer();
 
-	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();;
-
-	public TimerHandler(ITimedStatemachine statemachine) {
-		this.statemachine = statemachine;
-	}
+	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();
 
 	public void setTimer(final TimeEvent event, long time, long cycleStartTime) {
 		// Reset existing TimerTask for event. This step isn't necessary if
@@ -40,11 +34,11 @@ public class TimerHandler implements ITimerHandler {
 		timerTaskMap.put(event, new TimerTask() {
 			@Override
 			public void run() {
-				statemachine.notify(new EventNotification(event));
+				event.getStatemachine().notify(new EventNotification(event));
 			}
 		});
 
-		//set time field of event
+		// set time field of event
 		event.setTime(time);
 
 		// start scheduling the timer

+ 10 - 0
Examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java

@@ -69,6 +69,16 @@ public class TrafficLightWaitingCycleBasedStatemachine
 		interfaceTrafficLight = new InterfaceTrafficLightImpl(this);
 		interfacePedestrian = new InterfacePedestrianImpl(this);
 		defaultInterface = new DefaultInterfaceImpl(this);
+		PedWaiting_time_event_0.setStatemachine(this);
+		WaitOn_time_event_0.setStatemachine(this);
+		WaitOff_time_event_0.setStatemachine(this);
+		StreetAttention_time_event_0.setStatemachine(this);
+		StreetRed_time_event_0.setStatemachine(this);
+		PedestrianGreen_time_event_0.setStatemachine(this);
+		PedestrianRed_time_event_0.setStatemachine(this);
+		StreetPrepare_time_event_0.setStatemachine(this);
+		BlinkYellow_time_event_0.setStatemachine(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 1
Examples/org.yakindu.sct.generator.java.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemo.java

@@ -71,7 +71,7 @@ public class CrossingDemo {
 				// Generator is used in this case. You can add your own
 				// implementation of a TimerHandler. It has to implement the
 				// ITimerHandler interface.
-				statemachine.setTimerHandler(new TimerHandler(statemachine));
+				statemachine.setTimerHandler(new TimerHandler());
 				statemachine.enter();
 				while (!isInterrupted()) {
 					statemachine.runCycle();

+ 3 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomCycleBasedStatemachine.xpt

@@ -221,6 +221,9 @@ public class 
 		«FOREACH getInterfaceScope() AS interface-»
 		«interface.getInterfaceName().toFirstLower()» = new «interface.getInterfaceImplName()»(this);
 		«ENDFOREACH-»
+		«FOREACH getTimeEvents() AS timeEvent-»
+			«timeEvent.getName()».setStatemachine(this);
+		«ENDFOREACH»
 	}
 	
 	protected Collection<Event> getOccuredEvents() {

+ 16 - 7
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/TimeEvent.xpt

@@ -22,22 +22,31 @@ Contributors:
 package «entry.getBasePackageName()»;
 
 public class TimeEvent extends ValuedEvent<Boolean> {
-	
+
 	private long time = -1;
-	
+
+	private ITimedStatemachine statemachine;
+
 	public TimeEvent(String name, boolean periodic) {
 		super(name, periodic);
 	}
-	
-	public void setTime(long time){
+
+	public void setTime(long time) {
 		this.time = time;
 	}
-	
-	public long getTime(){
+
+	public long getTime() {
 		return time;
 	}
-}
 
+	public ITimedStatemachine getStatemachine() {
+		return statemachine;
+	}
+
+	public void setStatemachine(ITimedStatemachine statemachine) {
+		this.statemachine = statemachine;
+	}
+}
 «ENDFILE-»
 «ENDIF-»
 «ENDDEFINE»

+ 6 - 12
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/TimerHandler.xpt

@@ -29,15 +29,9 @@ import 
 
 public class TimerHandler implements ITimerHandler {
 
-	private final ITimedStatemachine statemachine;
-
 	private final Timer timer = new Timer();
 
-	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();;
-
-	public TimerHandler(ITimedStatemachine statemachine) {
-		this.statemachine = statemachine;
-	}
+	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();
 
 	public void setTimer(final TimeEvent event, long time, long cycleStartTime) {
 		// Reset existing TimerTask for event. This step isn't necessary if
@@ -50,13 +44,13 @@ public class TimerHandler implements ITimerHandler {
 		timerTaskMap.put(event, new TimerTask() {
 			@Override
 			public void run() {
-				statemachine.notify(new EventNotification(event));
+				event.getStatemachine().notify(new EventNotification(event));
 			}
 		});
-		
-		//set time field of event
+
+		// set time field of event
 		event.setTime(time);
-		
+
 		// start scheduling the timer
 		if (event.getValue()) {
 			timer.scheduleAtFixedRate(timerTaskMap.get(event),
@@ -74,7 +68,7 @@ public class TimerHandler implements ITimerHandler {
 		}
 		timerTaskMap.remove(event);
 	}
-	
+
 	/**
 	 * Cancels all running TimersTasks
 	 */

+ 10 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java

@@ -14,6 +14,8 @@ public class TimeEvent extends ValuedEvent<Boolean> {
 
 	private long time = -1;
 
+	private ITimedStatemachine statemachine;
+
 	public TimeEvent(String name, boolean periodic) {
 		super(name, periodic);
 	}
@@ -25,4 +27,12 @@ public class TimeEvent extends ValuedEvent<Boolean> {
 	public long getTime() {
 		return time;
 	}
+
+	public ITimedStatemachine getStatemachine() {
+		return statemachine;
+	}
+
+	public void setStatemachine(ITimedStatemachine statemachine) {
+		this.statemachine = statemachine;
+	}
 }

+ 3 - 9
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/TimerHandler.java

@@ -19,15 +19,9 @@ import org.yakindu.sct.runtime.java.EventNotification;
 
 public class TimerHandler implements ITimerHandler {
 
-	private final ITimedStatemachine statemachine;
-
 	private final Timer timer = new Timer();
 
-	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();;
-
-	public TimerHandler(ITimedStatemachine statemachine) {
-		this.statemachine = statemachine;
-	}
+	private final Map<TimeEvent, TimerTask> timerTaskMap = new HashMap<TimeEvent, TimerTask>();
 
 	public void setTimer(final TimeEvent event, long time, long cycleStartTime) {
 		// Reset existing TimerTask for event. This step isn't necessary if
@@ -40,11 +34,11 @@ public class TimerHandler implements ITimerHandler {
 		timerTaskMap.put(event, new TimerTask() {
 			@Override
 			public void run() {
-				statemachine.notify(new EventNotification(event));
+				event.getStatemachine().notify(new EventNotification(event));
 			}
 		});
 
-		//set time field of event
+		// set time field of event
 		event.setTime(time);
 
 		// start scheduling the timer

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/interfacetest/InterfaceTestCycleBasedStatemachine.java

@@ -40,6 +40,7 @@ public class InterfaceTestCycleBasedStatemachine implements IStatemachine {
 		defaultInterface = new DefaultInterfaceImpl(this);
 		interfaceOther = new InterfaceOtherImpl(this);
 		interfaceThird = new InterfaceThirdImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_deephistory/Test_DeepHistoryCycleBasedStatemachine.java

@@ -36,6 +36,7 @@ public class Test_DeepHistoryCycleBasedStatemachine implements IStatemachine {
 		occuredEvents = new ArrayList<Event>();
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_expression/Test_ExpressionCycleBasedStatemachine.java

@@ -38,6 +38,7 @@ public class Test_ExpressionCycleBasedStatemachine implements IStatemachine {
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
 		interfaceOther = new InterfaceOtherImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_hierarchy/Test_HierarchyCycleBasedStatemachine.java

@@ -36,6 +36,7 @@ public class Test_HierarchyCycleBasedStatemachine implements IStatemachine {
 		occuredEvents = new ArrayList<Event>();
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 3 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/Test_LocalActionsCycleBasedStatemachine.java

@@ -51,6 +51,9 @@ public class Test_LocalActionsCycleBasedStatemachine
 		occuredEvents = new ArrayList<Event>();
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
+		State1_time_event_0.setStatemachine(this);
+		State2_time_event_0.setStatemachine(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java

@@ -38,6 +38,7 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 		occuredEvents = new ArrayList<Event>();
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_shallowhistory/Test_ShallowHistoryCycleBasedStatemachine.java

@@ -36,6 +36,7 @@ public class Test_ShallowHistoryCycleBasedStatemachine implements IStatemachine
 		occuredEvents = new ArrayList<Event>();
 		outEvents = new HashSet<Event>();
 		defaultInterface = new DefaultInterfaceImpl(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 3 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/Test_TransitionCycleBasedStatemachine.java

@@ -57,6 +57,9 @@ public class Test_TransitionCycleBasedStatemachine
 		outEvents = new HashSet<Event>();
 		interfaceA = new InterfaceAImpl(this);
 		defaultInterface = new DefaultInterfaceImpl(this);
+		State1_time_event_0.setStatemachine(this);
+		State1_time_event_1.setStatemachine(this);
+
 	}
 
 	protected Collection<Event> getOccuredEvents() {

+ 1 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestLocalActionsCycleBasedStatemachine.java

@@ -43,7 +43,7 @@ public class TestLocalActionsCycleBasedStatemachine {
 	@Before
 	public void setUp() {
 		statemachine = new Test_LocalActionsCycleBasedStatemachine();
-		statemachine.setTimerHandler(new TimerHandler(statemachine));
+		statemachine.setTimerHandler(new TimerHandler());
 		statemachine.enter();
 	}