Przeglądaj źródła

Refactoring of timer interfaces of java generator.

markus.muehlbrandt@gmail.com 12 lat temu
rodzic
commit
11a3c8503f
68 zmienionych plików z 3663 dodań i 2620 usunięć
  1. 37 27
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/IStatemachine.java
  2. 48 0
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/ITimer.java
  3. 25 0
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/ITimerCallback.java
  4. 217 207
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService.java
  5. 101 60
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService.java
  6. 52 42
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine.java
  7. 1449 1750
      examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine.java
  8. 5 2
      examples/org.yakindu.sct.examples.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoCycleBased.java
  9. 11 1
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ExpressionCode.xtend
  10. 19 5
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/FlowCode.xtend
  11. 1 1
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/IStatemachine.xtend
  12. 72 0
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimer.xtend
  13. 9 24
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimedStatemachine.xtend
  14. 0 80
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimerService.xtend
  15. 4 6
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaGenerator.xtend
  16. 5 5
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Naming.xtend
  17. 32 39
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Statemachine.xtend
  18. 5 5
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/StatemachineInterface.xtend
  19. 0 92
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/TimeEventTemplate.xtend
  20. 67 36
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/TimerService.xtend
  21. 44 31
      plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/extensions/SExecExtensions.xtend
  22. 0 30
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimedStatemachine.java
  23. 38 0
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimer.java
  24. 15 0
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimerCallback.java
  25. 0 46
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimerService.java
  26. 0 58
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/TimeEvent.java
  27. 66 35
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/TimerService.java
  28. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/alwaysoncycle/AlwaysOncycleStatemachine.java
  29. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/assignmentasexpression/AssignmentAsExpressionStatemachine.java
  30. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/bitexpressions/BitExpressionsStatemachine.java
  31. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/booleanexpressions/BooleanExpressionsStatemachine.java
  32. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/choice/ChoiceStatemachine.java
  33. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ckeywords/CKeywordsStatemachine.java
  34. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/declarations/DeclarationsStatemachine.java
  35. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/deephistory/DeepHistoryStatemachine.java
  36. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/enterstate/EnterStateStatemachine.java
  37. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/exitonselftransition/ExitOnSelfTransitionStatemachine.java
  38. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/exitstate/ExitStateStatemachine.java
  39. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/featurecalls/FeatureCallsStatemachine.java
  40. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guard/GuardStatemachine.java
  41. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guardedentry/GuardedEntryStatemachine.java
  42. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guardedexit/GuardedExitStatemachine.java
  43. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/historywithoutinitialstep/HistoryWithoutInitialStepStatemachine.java
  44. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ineventlifecycle/InEventLifeCycleStatemachine.java
  45. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/integerexpressions/IntegerExpressionsStatemachine.java
  46. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/internaleventlifecycle/InternalEventLifeCycleStatemachine.java
  47. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/javakeywords/JavaKeywordsStatemachine.java
  48. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/namedinterfaceaccess/NamedInterfaceAccessStatemachine.java
  49. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/operations/OperationsStatemachine.java
  50. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/outeventlifecycle/OutEventLifeCycleStatemachine.java
  51. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/parenthesis/ParenthesisStatemachine.java
  52. 25 0
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/performancetest/IPerformanceTestStatemachine.java
  53. 1221 0
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/performancetest/PerformanceTestStatemachine.java
  54. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/priorityvalues/PriorityValuesStatemachine.java
  55. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/raiseevent/RaiseEventStatemachine.java
  56. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/realexpressions/RealExpressionsStatemachine.java
  57. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/samenamedifferentregion/SameNameDifferentRegionStatemachine.java
  58. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/shallowhistory/ShallowHistoryStatemachine.java
  59. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/simpleevent/SimpleEventStatemachine.java
  60. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/simplehierachy/SimpleHierachyStatemachine.java
  61. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/statechartlocalreactions/StatechartLocalReactionsStatemachine.java
  62. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stateisactive/StateIsActiveStatemachine.java
  63. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stextkeywordsinstatesandregions/STextKeywordsInStatesAndRegionsStatemachine.java
  64. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stringexpressions/StringExpressionsStatemachine.java
  65. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/syncfork/SyncForkStatemachine.java
  66. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/syncjoin/SyncJoinStatemachine.java
  67. 0 1
      test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/valuedevents/ValuedEventsStatemachine.java
  68. 95 0
      test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/PerformanceTestsTest.java

+ 37 - 27
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/IStatemachine.java

@@ -1,27 +1,37 @@
-package org.yakindu.sct.examples.trafficlight.cyclebased;
-
-/**
- * Basic interface for statemachines.
- */
-public interface IStatemachine {
-
-	/**
-	* Initializes the statemachine. Use to init internal variables etc.
-	*/
-	public void init();
-
-	/**
-	* Enters the statemachine. Sets the statemachine in a defined state.
-	*/
-	public void enter();
-
-	/**
-	* Exits the statemachine. Leaves the statemachine with a defined state.
-	*/
-	public void exit();
-
-	/**
-	* Start a run-to-completion cycle.
-	*/
-	public void runCycle();
-}
+/**
+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.examples.trafficlight.cyclebased;
+
+/**
+ * Basic interface for statemachines.
+ */
+public interface IStatemachine {
+
+	/**
+	* Initializes the statemachine. Use to init internal variables etc.
+	*/
+	public void init();
+
+	/**
+	* Enters the statemachine. Sets the statemachine in a defined state.
+	*/
+	public void enter();
+
+	/**
+	* Exits the statemachine. Leaves the statemachine with a defined state.
+	*/
+	public void exit();
+
+	/**
+	* Start a run-to-completion cycle.
+	*/
+	public void runCycle();
+}

+ 48 - 0
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/ITimer.java

@@ -0,0 +1,48 @@
+/**
+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.examples.trafficlight.cyclebased;
+
+/**
+ * Interface a timer has to implement. Use to implement your own timer
+ * service.
+ * 
+ */
+public interface ITimer {
+
+	/**
+	 * Starts the timing for a given time event id.
+	 * 
+	 * @param callback
+	 * 			  : The target callback where the time event has to be raised.
+	 * 
+	 * @param eventID
+	 *            : The eventID the timer should use if timed out.
+	 *            
+	 * @param time
+	 *            : Time in milliseconds after the given time event should be
+	 *            triggered
+	 *            
+	 * @param isPeriodic
+	 * 			  : Set to true if the time event should be triggered periodically
+	 */
+	public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
+
+	/**
+	 * Unset a time event.
+	 * 
+	 * @param callback
+	 * 			: The target callback for which the time event has to be unset.
+	 * 
+	 * @param eventID
+	 * 			: The time event id.
+	 */
+	public void unsetTimer(ITimerCallback callback, int eventID);
+}

+ 25 - 0
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/ITimerCallback.java

@@ -0,0 +1,25 @@
+/**
+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.examples.trafficlight.cyclebased;
+
+/**
+* Interface for state machines which use timed event triggers.
+*/
+public interface ITimerCallback {
+	
+	/**
+	* Callback method if a time event occurred.
+	* 
+	* @param eventID
+	* 			:The id of the occurred event.
+	*/
+	public void timeElapsed(int eventID);
+}

+ 217 - 207
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService.java

@@ -1,207 +1,217 @@
-package org.yakindu.sct.examples.trafficlight.cyclebased;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-/**
- * Runtime service for state machines to execute a run to completion step
- * periodically.
- * 
- */
-public class RuntimeService {
-
-	private static RuntimeService runtimeService;
-
-	private Timer timer = null;
-
-	private Map<Long, StatemachineTimerTask> timerTasks = new HashMap<Long, StatemachineTimerTask>();
-
-	private class StatemachineTimerTask extends TimerTask {
-
-		private List<IStatemachine> statemachineList = new LinkedList<IStatemachine>();
-
-		private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
-
-		private boolean isPaused = false;
-
-		@Override
-		public void run() {
-			lock.readLock().lock();
-			if (!isPaused) {
-				for (IStatemachine statemachine : statemachineList) {
-					statemachine.runCycle();
-				}
-			}
-			lock.readLock().unlock();
-		}
-
-		/**
-		 * Adds the given state machine to the TimerTask.
-		 * 
-		 * @param statemachine
-		 * @return {@code true} if state machine is added properly.
-		 */
-		public boolean addStatemachine(IStatemachine statemachine) {
-			lock.writeLock().lock();
-			boolean ret = statemachineList.add(statemachine);
-			lock.writeLock().unlock();
-			return ret;
-		}
-
-		/**
-		 * Removes the given state machine from the TimerTask.
-		 * 
-		 * @param statemachine
-		 * @return {@code true} if state machine is removed properly.
-		 */
-		public boolean removeStatemachine(IStatemachine statemachine) {
-			lock.writeLock().lock();
-			boolean ret = statemachineList.remove(statemachine);
-			lock.writeLock().unlock();
-			return ret;
-		}
-
-		public void pause() {
-			isPaused = true;
-		}
-
-		public void resume() {
-			isPaused = false;
-		}
-	}
-
-	private RuntimeService() {
-		// Not intended to be instantiated.
-	}
-
-	/**
-	 * Returns the {@code RuntimeService} instance as singleton.
-	 * 
-	 * @return The singleton {@code RuntimeService} instance
-	 */
-	public static RuntimeService getInstance() {
-		if (runtimeService == null) {
-			runtimeService = new RuntimeService();
-		}
-		return runtimeService;
-	}
-
-	/**
-	 * Registers an {@link IStatemachine} for scheduled fixed rate execution
-	 * 
-	 * @param statemachine
-	 *            - The statemachine to execute
-	 * @param cyclePeriod
-	 *            - the fixed rate cycle period for scheduling
-	 * @return {@code true} if state machine is added properly.
-	 */
-	public boolean registerStatemachine(IStatemachine statemachine,
-			long cyclePeriod) {
-
-		if (timerTasks.containsKey(cyclePeriod)) {
-			// TimerTask for cycle time already existing -> add statemachine
-			return timerTasks.get(cyclePeriod).addStatemachine(statemachine);
-		} else {
-			// Create new TimerTask for cycle period and add statemachine
-			StatemachineTimerTask timerTask = new StatemachineTimerTask();
-			timerTasks.put(cyclePeriod, timerTask);
-			boolean ret = timerTask.addStatemachine(statemachine);
-			// Create a new Timer instance if runtime service was cancelled
-			// before
-			if (timer == null) {
-				timer = new Timer();
-			}
-			timer.scheduleAtFixedRate(timerTask, 0, cyclePeriod);
-			return ret;
-		}
-	}
-
-	/**
-	 * Removes the given state machine from runtime service.
-	 * 
-	 * @param statemachine
-	 *            - the statemachine which should be removed
-	 * @param cyclePeriod
-	 *            - the scheduling cycle period of the statemachine
-	 * @return {@code true} if state machine is removed properly.
-	 */
-	public boolean unregisterStatemachine(IStatemachine statemachine,
-			long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			boolean ret = timerTasks.get(cyclePeriod).removeStatemachine(
-					statemachine);
-
-			return ret;
-		}
-		return false;
-	}
-
-	/**
-	 * Cancels the execution of statemachines for the given cycle period. This
-	 * stops the execution of statemachines which are registered for the given
-	 * cycle period and cancels the executing {@link TimerTask}.
-	 * 
-	 * @return {@code true} if poperly cancelled
-	 */
-	public boolean cancelAll(long cyclePeriod) {
-		if (timer != null && timerTasks.containsKey(cyclePeriod)) {
-			TimerTask task = timerTasks.get(cyclePeriod);
-			task.cancel();
-			timer.purge();
-			timerTasks.remove(cyclePeriod);
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Pauses the execution of all statemachines which are registered for the
-	 * given cyclePeriod.
-	 * 
-	 * @param cyclePeriod
-	 * @return {@code true} if properly paused
-	 * 
-	 */
-	public boolean pauseAll(long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			timerTasks.get(cyclePeriod).pause();
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Resumes the execution of all statemachines which are registered for the
-	 * given cyclePeriod.
-	 * 
-	 * @param cyclePeriod
-	 * @return {@code true} if properly resumed
-	 * 
-	 */
-	public boolean resumeAll(long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			timerTasks.get(cyclePeriod).resume();
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Cancels the execution of all registered statemachines. This cancels the
-	 * executing {@link Timer} freeing all allocated resources and terminates
-	 * all existing execution threads.
-	 */
-	public void cancelTimer() {
-		if (timer != null) {
-			timer.cancel();
-			timer.purge();
-			timerTasks.clear();
-			timer = null;
-		}
-	}
-}
+/**
+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.examples.trafficlight.cyclebased;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Runtime service for state machines to execute a run to completion step
+ * periodically.
+ * 
+ */
+public class RuntimeService {
+
+	private static RuntimeService runtimeService;
+
+	private Timer timer = null;
+
+	private Map<Long, StatemachineTimerTask> timerTasks = new HashMap<Long, StatemachineTimerTask>();
+
+	private class StatemachineTimerTask extends TimerTask {
+
+		private List<IStatemachine> statemachineList = new LinkedList<IStatemachine>();
+
+		private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+		private boolean isPaused = false;
+
+		@Override
+		public void run() {
+			lock.readLock().lock();
+			if (!isPaused) {
+				for (IStatemachine statemachine : statemachineList) {
+					statemachine.runCycle();
+				}
+			}
+			lock.readLock().unlock();
+		}
+
+		/**
+		 * Adds the given state machine to the TimerTask.
+		 * 
+		 * @param statemachine
+		 * @return {@code true} if state machine is added properly.
+		 */
+		public boolean addStatemachine(IStatemachine statemachine) {
+			lock.writeLock().lock();
+			boolean ret = statemachineList.add(statemachine);
+			lock.writeLock().unlock();
+			return ret;
+		}
+
+		/**
+		 * Removes the given state machine from the TimerTask.
+		 * 
+		 * @param statemachine
+		 * @return {@code true} if state machine is removed properly.
+		 */
+		public boolean removeStatemachine(IStatemachine statemachine) {
+			lock.writeLock().lock();
+			boolean ret = statemachineList.remove(statemachine);
+			lock.writeLock().unlock();
+			return ret;
+		}
+
+		public void pause() {
+			isPaused = true;
+		}
+
+		public void resume() {
+			isPaused = false;
+		}
+	}
+
+	private RuntimeService() {
+		// Not intended to be instantiated.
+	}
+
+	/**
+	 * Returns the {@code RuntimeService} instance as singleton.
+	 * 
+	 * @return The singleton {@code RuntimeService} instance
+	 */
+	public static RuntimeService getInstance() {
+		if (runtimeService == null) {
+			runtimeService = new RuntimeService();
+		}
+		return runtimeService;
+	}
+
+	/**
+	 * Registers an {@link IStatemachine} for scheduled fixed rate execution
+	 * 
+	 * @param statemachine
+	 *            - The statemachine to execute
+	 * @param cyclePeriod
+	 *            - the fixed rate cycle period for scheduling
+	 * @return {@code true} if state machine is added properly.
+	 */
+	public boolean registerStatemachine(IStatemachine statemachine,
+			long cyclePeriod) {
+
+		if (timerTasks.containsKey(cyclePeriod)) {
+			// TimerTask for cycle time already existing -> add statemachine
+			return timerTasks.get(cyclePeriod).addStatemachine(statemachine);
+		} else {
+			// Create new TimerTask for cycle period and add statemachine
+			StatemachineTimerTask timerTask = new StatemachineTimerTask();
+			timerTasks.put(cyclePeriod, timerTask);
+			boolean ret = timerTask.addStatemachine(statemachine);
+			// Create a new Timer instance if runtime service was cancelled
+			// before
+			if (timer == null) {
+				timer = new Timer();
+			}
+			timer.scheduleAtFixedRate(timerTask, 0, cyclePeriod);
+			return ret;
+		}
+	}
+
+	/**
+	 * Removes the given state machine from runtime service.
+	 * 
+	 * @param statemachine
+	 *            - the statemachine which should be removed
+	 * @param cyclePeriod
+	 *            - the scheduling cycle period of the statemachine
+	 * @return {@code true} if state machine is removed properly.
+	 */
+	public boolean unregisterStatemachine(IStatemachine statemachine,
+			long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			boolean ret = timerTasks.get(cyclePeriod).removeStatemachine(
+					statemachine);
+
+			return ret;
+		}
+		return false;
+	}
+
+	/**
+	 * Cancels the execution of statemachines for the given cycle period. This
+	 * stops the execution of statemachines which are registered for the given
+	 * cycle period and cancels the executing {@link TimerTask}.
+	 * 
+	 * @return {@code true} if poperly cancelled
+	 */
+	public boolean cancelAll(long cyclePeriod) {
+		if (timer != null && timerTasks.containsKey(cyclePeriod)) {
+			TimerTask task = timerTasks.get(cyclePeriod);
+			task.cancel();
+			timer.purge();
+			timerTasks.remove(cyclePeriod);
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Pauses the execution of all statemachines which are registered for the
+	 * given cyclePeriod.
+	 * 
+	 * @param cyclePeriod
+	 * @return {@code true} if properly paused
+	 * 
+	 */
+	public boolean pauseAll(long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			timerTasks.get(cyclePeriod).pause();
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Resumes the execution of all statemachines which are registered for the
+	 * given cyclePeriod.
+	 * 
+	 * @param cyclePeriod
+	 * @return {@code true} if properly resumed
+	 * 
+	 */
+	public boolean resumeAll(long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			timerTasks.get(cyclePeriod).resume();
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Cancels the execution of all registered statemachines. This cancels the
+	 * executing {@link Timer} freeing all allocated resources and terminates
+	 * all existing execution threads.
+	 */
+	public void cancelTimer() {
+		if (timer != null) {
+			timer.cancel();
+			timer.purge();
+			timerTasks.clear();
+			timer = null;
+		}
+	}
+}

+ 101 - 60
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService.java

@@ -1,60 +1,101 @@
-package org.yakindu.sct.examples.trafficlight.cyclebased;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * Default timer service implementation.
- * 
- */
-public class TimerService implements ITimerService {
-
-	private final Timer timer = new Timer();
-
-	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
-		// timer tasks are properly reset by sexec model.
-		if (timerTaskMap.containsKey(event)) {
-			resetTimer(event);
-		}
-
-		// Create a new TimerTask for given event.
-		timerTaskMap.put(event, new TimerTask() {
-			@Override
-			public void run() {
-				event.getStatemachine().onTimeEventRaised(event);
-			}
-		});
-
-		// start scheduling the timer
-		if (event.isPeriodic()) {
-			timer.scheduleAtFixedRate(timerTaskMap.get(event),
-					time - (System.currentTimeMillis() - cycleStartTime), time);
-		} else {
-			timer.schedule(timerTaskMap.get(event),
-					time - (System.currentTimeMillis() - cycleStartTime));
-		}
-	}
-
-	public void resetTimer(TimeEvent event) {
-		if (timerTaskMap.containsKey(event) && timerTaskMap.get(event) != null) {
-			timerTaskMap.get(event).cancel();
-			timer.purge();
-		}
-		timerTaskMap.remove(event);
-	}
-
-	public void cancel() {
-		timer.cancel();
-		timer.purge();
-	}
-
-	public long getSystemTimeMillis() {
-		return System.currentTimeMillis();
-	}
-}
+/**
+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.examples.trafficlight.cyclebased;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Default timer service implementation.
+ * 
+ */
+public class TimerService implements ITimer {
+
+	private final Timer timer = new Timer();
+	
+	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
+	
+	/**
+	 * Timer task that reflects a time event. It's internally used by
+	 * {@link TimerService}.
+	 * 
+	 */
+	private class TimeEventTask extends TimerTask {
+	
+		private ITimerCallback callback;
+	
+		int eventID;
+	
+		/**
+		 * Constructor for a time event.
+		 * 
+		 * @param callback
+		 *            : Set to {@code true} if event should be repeated
+		 *            periodically.
+		 * 
+		 * @param eventID
+		 *            : Index position within the state machine's timeEvent
+		 *            array.
+		 */
+		public TimeEventTask(ITimerCallback callback, int eventID) {
+			this.callback = callback;
+			this.eventID = eventID;
+		}
+	
+		public void run() {
+			callback.timeElapsed(eventID);
+		}
+	
+		public boolean equals(Object obj) {
+			if (obj instanceof TimeEventTask) {
+				return ((TimeEventTask) obj).callback.equals(callback)
+						&& ((TimeEventTask) obj).eventID == eventID;
+			}
+			return super.equals(obj);
+		}
+	}
+	
+	public void setTimer(final ITimerCallback callback, final int eventID,
+			long time, boolean isPeriodic) {
+	
+		// Create a new TimerTask for given event and store it.
+		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+		timerTaskList.add(timerTask);
+	
+		// start scheduling the timer
+		if (isPeriodic) {
+			timer.scheduleAtFixedRate(timerTask, time, time);
+		} else {
+			timer.schedule(timerTask, time);
+		}
+	}
+	
+	public void unsetTimer(ITimerCallback callback, int eventID) {
+		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
+		if (index != -1) {
+			timerTaskList.get(index).cancel();
+			timer.purge();
+			timerTaskList.remove(index);
+		}
+	}
+	
+	/**
+	 * Cancel timer service. Use this to end possible timing threads and free
+	 * memory resources.
+	 */
+	public void cancel() {
+		timer.cancel();
+		timer.purge();
+	}
+}
+

+ 52 - 42
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine.java

@@ -1,42 +1,52 @@
-package org.yakindu.sct.examples.trafficlight.cyclebased.trafficlightwaiting;
-import org.yakindu.sct.examples.trafficlight.cyclebased.IStatemachine;
-import org.yakindu.sct.examples.trafficlight.cyclebased.ITimedStatemachine;
-
-public interface ITrafficLightWaitingStatemachine
-		extends
-			ITimedStatemachine,
-			IStatemachine {
-
-	public interface SCITrafficLight {
-		public boolean getRed();
-		public void setRed(boolean value);
-		public boolean getYellow();
-		public void setYellow(boolean value);
-		public boolean getGreen();
-		public void setGreen(boolean value);
-
-	}
-
-	public SCITrafficLight getSCITrafficLight();
-
-	public interface SCIPedestrian {
-		public boolean getRequest();
-		public void setRequest(boolean value);
-		public boolean getRed();
-		public void setRed(boolean value);
-		public boolean getGreen();
-		public void setGreen(boolean value);
-
-	}
-
-	public SCIPedestrian getSCIPedestrian();
-
-	public interface SCInterface {
-		public void raisePedestrianRequest();
-		public void raiseOnOff();
-
-	}
-
-	public SCInterface getSCInterface();
-
-}
+/**
+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.examples.trafficlight.cyclebased.trafficlightwaiting;
+import org.yakindu.sct.examples.trafficlight.cyclebased.IStatemachine;
+import org.yakindu.sct.examples.trafficlight.cyclebased.ITimerCallback;
+
+public interface ITrafficLightWaitingStatemachine
+		extends
+			ITimerCallback,
+			IStatemachine {
+
+	public interface SCITrafficLight {
+		public boolean getRed();
+		public void setRed(boolean value);
+		public boolean getYellow();
+		public void setYellow(boolean value);
+		public boolean getGreen();
+		public void setGreen(boolean value);
+
+	}
+
+	public SCITrafficLight getSCITrafficLight();
+
+	public interface SCIPedestrian {
+		public boolean getRequest();
+		public void setRequest(boolean value);
+		public boolean getRed();
+		public void setRed(boolean value);
+		public boolean getGreen();
+		public void setGreen(boolean value);
+
+	}
+
+	public SCIPedestrian getSCIPedestrian();
+
+	public interface SCInterface {
+		public void raisePedestrianRequest();
+		public void raiseOnOff();
+
+	}
+
+	public SCInterface getSCInterface();
+
+}

Plik diff jest za duży
+ 1449 - 1750
examples/org.yakindu.sct.examples.trafficlight/src-gen/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine.java


+ 5 - 2
examples/org.yakindu.sct.examples.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoCycleBased.java

@@ -26,6 +26,8 @@ import org.yakindu.sct.examples.trafficlight.cyclebased.trafficlightwaiting.Traf
 public class CrossingDemoCycleBased extends CrossingDemoBase {
 
 	private TrafficLightWaitingStatemachine statemachine;
+	
+	private TimerService timer;
 
 	public static void main(String[] args) {
 
@@ -36,7 +38,8 @@ public class CrossingDemoCycleBased extends CrossingDemoBase {
 	protected void setUpAndRunStatemachine() {
 
 		statemachine = new TrafficLightWaitingStatemachine();
-		statemachine.setTimerService(new TimerService());
+		timer = new TimerService();
+		statemachine.setTimer(timer);
 		statemachine.init();
 		statemachine.enter();
 		
@@ -46,7 +49,7 @@ public class CrossingDemoCycleBased extends CrossingDemoBase {
 	@Override
 	protected void tearDownStatemachine() {
 		// End TimerHandler and RuntimeService.
-		statemachine.getTimerService().cancel();
+		timer.cancel();
 		RuntimeService.getInstance().cancelTimer();
 	}
 

+ 11 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ExpressionCode.xtend

@@ -40,6 +40,7 @@ import org.yakindu.sct.model.stext.stext.StringLiteral
 import org.yakindu.sct.model.stext.stext.UnaryOperator
 import org.yakindu.sct.model.stext.types.ISTextTypeSystem
 import org.yakindu.sct.model.stext.types.ISTextTypeInferrer
+import java.util.List
 
 class ExpressionCode {
 	
@@ -48,6 +49,15 @@ class ExpressionCode {
 	@Inject extension ISTextTypeSystem
 	@Inject extension ISTextTypeInferrer
 	
+	private var List<TimeEvent> timeEvents;
+	
+	def private getTimeEvents(TimeEvent it) {
+		if (timeEvents == null) {
+			timeEvents = flow.timeEvents
+		}
+		return timeEvents
+	}
+	
 	def dispatch String code(EObject it) '''
 		//ERROR: Template in ExpressionCode.xtend for class '«getClass().name»' not define.
 		//Container: «eContainer?.getClass().name»
@@ -217,7 +227,7 @@ class ExpressionCode {
 	}
 	
 	def dispatch String code(TimeEvent it) {
-		"timeEvents[" + name.asEscapedIdentifier + ".getIndex()]"
+		"timeEvents[" + getTimeEvents.indexOf(it) + "]"
 	}
 	
 	def dispatch String getContext(Variable it) {

+ 19 - 5
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/FlowCode.xtend

@@ -16,11 +16,17 @@ import org.yakindu.sct.model.sexec.Sequence
 import org.yakindu.sct.model.sexec.StateSwitch
 import org.yakindu.sct.model.sexec.Step
 import org.yakindu.sct.model.sexec.UnscheduleTimeEvent
+import org.yakindu.sct.model.sexec.extensions.SExecExtensions
+import java.util.List
+import org.yakindu.sct.model.sexec.TimeEvent
 
 class FlowCode {
 	
 	@Inject extension Naming
-	@Inject extension ExpressionCode
+	@Inject extension ExpressionCode
+	@Inject extension SExecExtensions
+	
+	private var List<TimeEvent> timeEvents;
 	
 	def stepComment(Step it) '''
 		«IF comment != null && ! comment.empty»
@@ -50,13 +56,14 @@ class FlowCode {
 	'''
 	
 	def dispatch code(ScheduleTimeEvent it) '''
-		«stepComment»
-		getTimerService().setTimer(«timeEvent.name.asEscapedIdentifier», «timeValue.code», cycleStartTime);
+		«stepComment»
+		
+		timer.setTimer(this, «getTimeEvents.indexOf(timeEvent)», «timeValue.code», «IF timeEvent.periodic»true«ELSE»false«ENDIF»);
 	'''
 	
 	def dispatch code(UnscheduleTimeEvent it) '''
 		«stepComment»
-		getTimerService().resetTimer(«timeEvent.name.asEscapedIdentifier»);
+		timer.unsetTimer(this, «getTimeEvents.indexOf(timeEvent)»);
 	'''
 	
 	def dispatch code(Execution it) {
@@ -130,5 +137,12 @@ class FlowCode {
 	def dispatch code(SaveHistory it) '''
 		«stepComment»
 		historyVector[«region.historyVector.offset»] = stateVector[«region.stateVector.offset»];
-	'''
+	'''
+	
+	def private getTimeEvents(Step it) {
+		if (timeEvents==null) {
+			timeEvents = flow.timeEvents
+		}
+		return timeEvents
+	}
 }

+ 1 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/IStatemachine.xtend

@@ -23,7 +23,7 @@ class IStatemachine {
 	extension GenmodelEntries
 	
 	def generateIStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(entry.basePackagePath + '/' + iStatemachineClass.java, content(entry))
+		fsa.generateFile(entry.basePackagePath + '/' + iStatemachine.java, content(entry))
 	}
 	
 	def private content(GeneratorEntry entry) {

+ 72 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimer.xtend

@@ -0,0 +1,72 @@
+/**
+  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:
+  	Markus Muehlbrandt - Initial contribution and API
+ */
+package org.yakindu.sct.generator.java
+
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sgen.GeneratorEntry
+import org.eclipse.xtext.generator.IFileSystemAccess
+import com.google.inject.Inject
+
+class ITimer {
+	
+	@Inject
+	extension Naming 
+	
+	@Inject
+	extension GenmodelEntries
+	
+	def generateITimer(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
+		fsa.generateFile(entry.basePackagePath + '/' + iTimer.java, content(entry))
+	}
+	
+	def private content(GeneratorEntry entry) {
+		'''
+		«entry.licenseText»
+		package «entry.getBasePackageName()»;
+
+		/**
+		 * Interface a timer has to implement. Use to implement your own timer
+		 * service.
+		 * 
+		 */
+		public interface ITimer {
+		
+			/**
+			 * Starts the timing for a given time event id.
+			 * 
+			 * @param callback
+			 * 			  : The target callback where the time event has to be raised.
+			 * 
+			 * @param eventID
+			 *            : The eventID the timer should use if timed out.
+			 *            
+			 * @param time
+			 *            : Time in milliseconds after the given time event should be
+			 *            triggered
+			 *            
+			 * @param isPeriodic
+			 * 			  : Set to true if the time event should be triggered periodically
+			 */
+			public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
+		
+			/**
+			 * Unset a time event.
+			 * 
+			 * @param callback
+			 * 			: The target callback for which the time event has to be unset.
+			 * 
+			 * @param eventID
+			 * 			: The time event id.
+			 */
+			public void unsetTimer(ITimerCallback callback, int eventID);
+		}
+		'''
+	}
+}

+ 9 - 24
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimedStatemachine.xtend

@@ -14,7 +14,7 @@ import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
 
-class ITimedStatemachine {
+class ITimerCallback {
 	
 	@Inject
 	extension Naming 
@@ -22,8 +22,8 @@ class ITimedStatemachine {
 	@Inject
 	extension GenmodelEntries
 	
-	def generateITimedStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(entry.basePackagePath + '/' + iTimedStatemachineClass.java, content(entry))
+	def generateITimerCallback(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
+		fsa.generateFile(entry.basePackagePath + '/' + iTimerCallback.java, content(entry))
 	}
 	
 	def private content(GeneratorEntry entry) {
@@ -34,30 +34,15 @@ class ITimedStatemachine {
 		/**
 		* Interface for state machines which use timed event triggers.
 		*/
-		public interface ITimedStatemachine {
-		
+		public interface ITimerCallback {
+			
 			/**
-			* Set the {@link ITimerService} for the state machine. It must be set
-			* externally on a timed state machine before a run cycle can be correct
-			* executed.
+			* Callback method if a time event occurred.
 			* 
-			* @param timerService
+			* @param eventID
+			* 			:The id of the occurred event.
 			*/
-			public void setTimerService(ITimerService timerService);
-		
-			/**
-			* Returns the currently used timer service.
-			* 
-			* @return {@link ITimerService}
-			*/
-			public ITimerService getTimerService();
-		
-			/**
-			* Callback method if a {@link TimeEvent} occurred.
-			* 
-			* @param timeEvent
-			*/
-			public void onTimeEventRaised(TimeEvent timeEvent);
+			public void timeElapsed(int eventID);
 		}
 		'''
 	}

+ 0 - 80
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/ITimerService.xtend

@@ -1,80 +0,0 @@
-/**
-  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:
-  	Markus Muehlbrandt - Initial contribution and API
- */
-package org.yakindu.sct.generator.java
-
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.eclipse.xtext.generator.IFileSystemAccess
-import com.google.inject.Inject
-
-class ITimerService {
-	
-	@Inject
-	extension Naming 
-	
-	@Inject
-	extension GenmodelEntries
-	
-	def generateITimerService(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(entry.basePackagePath + '/' + iTimerServiceClass.java, content(entry))
-	}
-	
-	def private content(GeneratorEntry entry) {
-		'''
-		«entry.licenseText»
-		package «entry.getBasePackageName()»;
-
-		/**
-		 * Interface a timer service has to implement. Use to implement your own timer
-		 * service. A timer service has to be added to a timed state machine.
-		 * 
-		 */
-		public interface ITimerService {
-		
-			/**
-			 * Starts the timing for a given {@link TimeEvent}.
-			 * 
-			 * @param event
-			 *            : The TimeEvent the timer service should throw if timed out.
-			 * @param time
-			 *            : Time in milliseconds after the given time event should be
-			 *            triggered
-			 * @param cycleStartTime
-			 *            : The absolute start time in milliseconds at which the last
-			 *            run cycle was called. Can be used to produce a more accurate
-			 *            timing behavior.
-			 */
-			public void setTimer(TimeEvent event, long time, long cycleStartTime);
-		
-			/**
-			 * Unset the given {@link TimeEvent}. Use to unset cyclic repeated time
-			 * events.
-			 * 
-			 * @param event
-			 */
-			public void resetTimer(TimeEvent event);
-		
-			/**
-			 * Cancel timer service. Use this to end possible timing threads and free
-			 * memory resources.
-			 */
-			public void cancel();
-		
-			/**
-			 * Returns the system time in milliseconds.
-			 * 
-			 * @return the difference, measured in milliseconds, between the current
-			 *         time and a defined point of time in the past.
-			 */
-			public long getSystemTimeMillis();
-		}
-		'''
-	}
-}

+ 4 - 6
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaGenerator.xtend

@@ -24,9 +24,8 @@ class JavaGenerator implements IExecutionFlowGenerator {
 
 	@Inject extension Navigation
 	@Inject extension IStatemachine
-	@Inject extension ITimedStatemachine
-	@Inject extension ITimerService
-	@Inject extension TimeEventTemplate
+	@Inject extension ITimerCallback
+	@Inject extension ITimer
 	@Inject extension TimerService
 	@Inject extension GenmodelEntries
 	@Inject extension RuntimeService
@@ -38,9 +37,8 @@ class JavaGenerator implements IExecutionFlowGenerator {
 		flow.generateIStatemachine(entry, fsa)
 		
 		if (flow.timed) {
-			flow.generateITimedStatemachine(entry, fsa)
-			flow.generateITimerService(entry, fsa)
-			flow.generateTimeEvent(entry, fsa)
+			flow.generateITimerCallback(entry, fsa)
+			flow.generateITimer(entry, fsa)
 			if (entry.createTimerService) {
 				flow.generateTimerService(entry, fsa);
 			}

+ 5 - 5
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Naming.xtend

@@ -25,16 +25,16 @@ class Naming implements JavaKeywords {
 	
 	@Inject StextNameProvider provider;
 	
-	def iStatemachineClass() {
+	def iStatemachine() {
 		"IStatemachine"
 	}
 	
-	def iTimedStatemachineClass() {
-		"ITimedStatemachine"
+	def iTimerCallback() {
+		"ITimerCallback"
 	}
 	
-	def iTimerServiceClass() {
-		"I" + timerServiceClass
+	def iTimer() {
+		"ITimer"
 	}
 	
 	def timerServiceClass() {

+ 32 - 39
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Statemachine.xtend

@@ -10,18 +10,17 @@
 package org.yakindu.sct.generator.java
 
 import com.google.inject.Inject
+import java.util.List
 import org.eclipse.xtext.generator.IFileSystemAccess
+import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
+import org.yakindu.sct.model.sexec.Check
 import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import java.util.List
 import org.yakindu.sct.model.sexec.Step
-import org.yakindu.sct.model.sexec.Check
-import org.yakindu.sct.model.stext.types.ISTextTypeSystem
-import org.yakindu.sct.model.stext.stext.InterfaceScope
+import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.model.stext.stext.Direction
-import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
 import org.yakindu.sct.model.stext.stext.EventDefinition
-import org.yakindu.sct.model.sexec.extensions.SExecExtensions
+import org.yakindu.sct.model.stext.stext.InterfaceScope
+import org.yakindu.sct.model.stext.types.ISTextTypeSystem
 
 class Statemachine {
 	
@@ -31,7 +30,6 @@ class Statemachine {
 	@Inject extension ICodegenTypeSystemAccess
 	@Inject extension ISTextTypeSystem
 	@Inject extension FlowCode
-	@Inject extension SExecExtensions
 	
 	
 	@Inject Beautifier beautifier
@@ -85,8 +83,7 @@ class Statemachine {
 		import java.util.List;
 		«ENDIF»
 		«IF flow.timed»
-			import «entry.getBasePackageName()».TimeEvent;
-			import «entry.getBasePackageName()».ITimerService;
+			import «entry.getBasePackageName()».ITimer;
 		«ENDIF»
 	'''
 	
@@ -98,13 +95,8 @@ class Statemachine {
 			private «event.type.targetLanguageName» «event.valueIdentifier»;
 		«ENDIF»
 		«ENDFOR»
-		«var timeEvents = flow.timeEvents»
-		«FOR timeEvent: timeEvents»
-			private final TimeEvent «timeEvent.name.asEscapedIdentifier» = new TimeEvent(«timeEvent.periodic», «timeEvents.indexOf(timeEvent)»); 
-		«ENDFOR»
-	
 		«IF flow.timed»
-			private final boolean[] timeEvents = new boolean[«timeEvents.size»];
+			private final boolean[] timeEvents = new boolean[«flow.timeEvents.size»];
 		«ENDIF»
 	
 		«FOR scope : flow.interfaceScopes»
@@ -132,9 +124,7 @@ class Statemachine {
 		private int nextStateIndex;
 		
 		«IF flow.timed»
-		private ITimerService timerService;
-		
-		private long cycleStartTime;
+		private ITimer timer;
 		«ENDIF»
 		
 		«FOR internal : flow.internalScopes»
@@ -150,18 +140,14 @@ class Statemachine {
 			«FOR scope : flow.interfaceScopes»
 			«scope.interfaceName.asEscapedIdentifier» = new «scope.getInterfaceImplName()»();
 			«ENDFOR»
-			
-			«FOR timeEvent : flow.timeEvents»
-				«timeEvent.name.asEscapedIdentifier».setStatemachine(this);
-			«ENDFOR»
-			}
+		}
 	'''
 	
 	def private initFunction(ExecutionFlow flow) '''
 		public void init() {
 			«IF flow.timed»
-			if (timerService == null) {
-				throw new IllegalStateException("TimerService not set.");
+			if (timer == null) {
+				throw new IllegalStateException("timer not set.");
 			}
 			«ENDIF»
 			for (int i = 0; i < «flow.stateVector.size»; i++) {
@@ -227,16 +213,28 @@ class Statemachine {
 	
 	def private timingFunctions(ExecutionFlow flow) '''
 		«IF flow.timed»
-			public void setTimerService(ITimerService timerService) {
-				this.timerService = timerService;
+			/**
+			* Set the {@link ITimer} for the state machine. It must be set
+			* externally on a timed state machine before a run cycle can be correct
+			* executed.
+			* 
+			* @param timer
+			*/
+			public void setTimer(ITimer timer) {
+				this.timer = timer;
 			}
 			
-			public ITimerService getTimerService() {
-				return timerService;
+			/**
+			* Returns the currently used timer.
+			* 
+			* @return {@link ITimer}
+			*/
+			public ITimer getTimer() {
+				return timer;
 			}
 			
-			public void onTimeEventRaised(TimeEvent timeEvent) {
-				timeEvents[timeEvent.getIndex()] = true;
+			public void timeElapsed(int eventID) {
+				timeEvents[eventID] = true;
 			}
 		«ENDIF»
 	'''
@@ -457,10 +455,6 @@ class Statemachine {
 	def private runCycleFunction(ExecutionFlow flow) '''
 		public void runCycle() {
 			
-			«IF flow.timed»
-			cycleStartTime = timerService.getSystemTimeMillis();
-			
-			«ENDIF»
 			clearOutEvents();
 			
 			for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
@@ -485,10 +479,9 @@ class Statemachine {
 	def private enterFunction(ExecutionFlow it) '''
 		public void enter() {
 			«IF timed»
-			if (timerService == null) {
-				throw new IllegalStateException("TimerService not set.");
+			if (timer == null) {
+				throw new IllegalStateException("timer not set.");
 			}
-			cycleStartTime = timerService.getSystemTimeMillis();
 			«ENDIF»
 			«enterSequences.defaultSequence.code»
 		}

+ 5 - 5
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/StatemachineInterface.xtend

@@ -44,9 +44,9 @@ class StatemachineInterface {
 		«IF entry.createInterfaceObserver && flow.hasOutgoingEvents»
 		import java.util.List;
 		«ENDIF»
-		import «entry.basePackageName».IStatemachine;
+		import «entry.basePackageName».«iStatemachine»;
 		«IF flow.timed»
-		import «entry.basePackageName».ITimedStatemachine;
+		import «entry.basePackageName».«iTimerCallback»;
 		«ENDIF»
 		
 		public interface «flow.statemachineInterfaceName» extends «flow.statemachineInterfaceExtensions» {
@@ -142,7 +142,7 @@ class StatemachineInterface {
 		'''
 		«FOR event : scope.eventDefinitions»
 			«IF  event.direction ==  Direction::IN»
-				««« IMPORTANT: An event not specifying a type is regarded to have a void type		
+				««« IMPORTANT: An event not specifying a type is regarded to have a void type
 				«IF event.type != null && !event.type.voidType»
 					public void raise«event.name.asName»(«event.type.targetLanguageName» value);
 				«ELSE»
@@ -173,10 +173,10 @@ class StatemachineInterface {
 		var String interfaces = "";
 
 		if (flow.timed) {
-			interfaces = interfaces + "ITimedStatemachine,"
+			interfaces = interfaces + iTimerCallback + ","
 		}
 
-		interfaces = interfaces + "IStatemachine"
+		interfaces = interfaces + iStatemachine
 		
 		return interfaces;
 	}

+ 0 - 92
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/TimeEventTemplate.xtend

@@ -1,92 +0,0 @@
-/**
-  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:
-  	Markus Muehlbrandt - Initial contribution and API
- */
-package org.yakindu.sct.generator.java
-
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.eclipse.xtext.generator.IFileSystemAccess
-import com.google.inject.Inject
-
-class TimeEventTemplate {
-	
-	@Inject
-	extension Naming 
-	
-	@Inject
-	extension GenmodelEntries
-	
-	def generateTimeEvent(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(entry.basePackagePath + '/' + timeEventClass.java, content(entry))
-	}
-	
-	def private content(GeneratorEntry entry) {
-		'''
-		«entry.licenseText»
-		package «entry.getBasePackageName()»;
-
-		/**
-		 * Event that reflects a time event. It's internally used by
-		 * {@link ITimedStatemachine}.
-		 * 
-		 * @author muehlbrandt
-		 * 
-		 * @param <T>
-		 */
-		public class TimeEvent {
-		
-			private boolean periodic;
-		
-			private ITimedStatemachine statemachine;
-			
-			int index;
-		
-			/**
-			 * Constructor for a time event.
-			 * 
-			 * @param periodic
-			 *            : Set to {@code true} if event should be repeated
-			 *            periodically.
-			 * 
-			 * @param index
-			 *            : Index position within the state machine's timeEvent array.
-			 */
-			public TimeEvent(boolean periodic, int index) {
-				this.periodic = periodic;
-				this.index = index;
-			}
-		
-			/**
-			 * Returns the state machine reference of the event.
-			 * 
-			 */
-			public ITimedStatemachine getStatemachine() {
-				return statemachine;
-			}
-		
-			/**
-			 * Sets the state machine reference of the event.
-			 * 
-			 * @param statemachine
-			 */
-			public void setStatemachine(ITimedStatemachine statemachine) {
-				this.statemachine = statemachine;
-			}
-		
-			public boolean isPeriodic() {
-				return periodic;
-			}
-		
-			public int getIndex() {
-				return index;
-			}
-		}
-		'''
-	}
-}

+ 67 - 36
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/TimerService.xtend

@@ -30,8 +30,8 @@ class TimerService {
 		«entry.licenseText»
 		package «entry.getBasePackageName()»;
 		
-		import java.util.HashMap;
-		import java.util.Map;
+		import java.util.ArrayList;
+		import java.util.List;
 		import java.util.Timer;
 		import java.util.TimerTask;
 		
@@ -39,54 +39,85 @@ class TimerService {
 		 * Default timer service implementation.
 		 * 
 		 */
-		public class TimerService implements ITimerService {
-		
+		public class TimerService implements ITimer {
+
 			private final Timer timer = new Timer();
-		
-			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
-				// timer tasks are properly reset by sexec model.
-				if (timerTaskMap.containsKey(event)) {
-					resetTimer(event);
+			
+			private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
+			
+			/**
+			 * Timer task that reflects a time event. It's internally used by
+			 * {@link TimerService}.
+			 * 
+			 */
+			private class TimeEventTask extends TimerTask {
+			
+				private ITimerCallback callback;
+			
+				int eventID;
+			
+				/**
+				 * Constructor for a time event.
+				 * 
+				 * @param callback
+				 *            : Set to {@code true} if event should be repeated
+				 *            periodically.
+				 * 
+				 * @param eventID
+				 *            : Index position within the state machine's timeEvent
+				 *            array.
+				 */
+				public TimeEventTask(ITimerCallback callback, int eventID) {
+					this.callback = callback;
+					this.eventID = eventID;
 				}
-		
-				// Create a new TimerTask for given event.
-				timerTaskMap.put(event, new TimerTask() {
-					@Override
-					public void run() {
-						event.getStatemachine().onTimeEventRaised(event);
+			
+				public void run() {
+					callback.timeElapsed(eventID);
+				}
+			
+				public boolean equals(Object obj) {
+					if (obj instanceof TimeEventTask) {
+						return ((TimeEventTask) obj).callback.equals(callback)
+								&& ((TimeEventTask) obj).eventID == eventID;
 					}
-				});
-		
+					return super.equals(obj);
+				}
+			}
+			
+			public void setTimer(final ITimerCallback callback, final int eventID,
+					long time, boolean isPeriodic) {
+			
+				// Create a new TimerTask for given event and store it.
+				TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+				timerTaskList.add(timerTask);
+			
 				// start scheduling the timer
-				if (event.isPeriodic()) {
-					timer.scheduleAtFixedRate(timerTaskMap.get(event),
-							time - (System.currentTimeMillis() - cycleStartTime), time);
+				if (isPeriodic) {
+					timer.scheduleAtFixedRate(timerTask, time, time);
 				} else {
-					timer.schedule(timerTaskMap.get(event),
-							time - (System.currentTimeMillis() - cycleStartTime));
+					timer.schedule(timerTask, time);
 				}
 			}
-		
-			public void resetTimer(TimeEvent event) {
-				if (timerTaskMap.containsKey(event) && timerTaskMap.get(event) != null) {
-					timerTaskMap.get(event).cancel();
+			
+			public void unsetTimer(ITimerCallback callback, int eventID) {
+				int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
+				if (index != -1) {
+					timerTaskList.get(index).cancel();
 					timer.purge();
+					timerTaskList.remove(index);
 				}
-				timerTaskMap.remove(event);
 			}
-		
+			
+			/**
+			 * Cancel timer service. Use this to end possible timing threads and free
+			 * memory resources.
+			 */
 			public void cancel() {
 				timer.cancel();
 				timer.purge();
 			}
-		
-			public long getSystemTimeMillis() {
-				return System.currentTimeMillis();
-			}
 		}
+
 	'''
 }

+ 44 - 31
plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/extensions/SExecExtensions.xtend

@@ -8,33 +8,33 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.model.sexec.extensions
-
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sexec.TimeEvent
-import org.yakindu.sct.model.stext.stext.EventDefinition
-import java.util.List
-import java.util.ArrayList
-import org.yakindu.sct.model.sgraph.Scope
-import org.yakindu.sct.model.stext.stext.Direction
-import org.yakindu.sct.model.stext.stext.VariableDefinition
-import org.yakindu.sct.model.stext.stext.InternalScope
-import org.yakindu.sct.model.sgraph.Declaration
-import org.yakindu.sct.model.stext.stext.ElementReferenceExpression
-import org.yakindu.sct.model.stext.stext.FeatureCall
-import org.yakindu.sct.model.stext.stext.Expression
-import org.yakindu.sct.model.sgraph.Event
-import org.yakindu.sct.model.sexec.ExecutionState
-import org.yakindu.sct.model.sexec.ExecutionRegion
-import org.yakindu.sct.model.sexec.ExecutionScope
-import org.yakindu.sct.model.sexec.Step
-import org.yakindu.sct.model.sexec.ExecutionNode
-import org.yakindu.sct.model.sexec.Reaction
-import org.eclipse.emf.ecore.EObject
-import org.yakindu.sct.model.sexec.Check
-import org.yakindu.sct.model.stext.stext.InterfaceScope
-import org.yakindu.sct.model.sexec.Sequence
-import java.util.LinkedList
import org.yakindu.sct.model.stext.stext.StatechartScope
+package org.yakindu.sct.model.sexec.extensions
+
+import java.util.ArrayList
+import java.util.List
+import org.eclipse.emf.ecore.EObject
+import org.yakindu.sct.model.sexec.Check
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sexec.ExecutionNode
+import org.yakindu.sct.model.sexec.ExecutionRegion
+import org.yakindu.sct.model.sexec.ExecutionScope
+import org.yakindu.sct.model.sexec.ExecutionState
+import org.yakindu.sct.model.sexec.Reaction
+import org.yakindu.sct.model.sexec.Sequence
+import org.yakindu.sct.model.sexec.Step
+import org.yakindu.sct.model.sexec.TimeEvent
+import org.yakindu.sct.model.sgraph.Declaration
+import org.yakindu.sct.model.sgraph.Event
+import org.yakindu.sct.model.sgraph.Scope
+import org.yakindu.sct.model.stext.stext.Direction
+import org.yakindu.sct.model.stext.stext.ElementReferenceExpression
+import org.yakindu.sct.model.stext.stext.EventDefinition
+import org.yakindu.sct.model.stext.stext.Expression
+import org.yakindu.sct.model.stext.stext.FeatureCall
+import org.yakindu.sct.model.stext.stext.InterfaceScope
+import org.yakindu.sct.model.stext.stext.InternalScope
+import org.yakindu.sct.model.stext.stext.StatechartScope
+import org.yakindu.sct.model.stext.stext.VariableDefinition
 
 class SExecExtensions {
 	
@@ -45,12 +45,25 @@ class SExecExtensions {
 		}
 	}
 	
+	def ExecutionFlow flow(EObject element){
+		var ExecutionFlow ret = null;
+		if (element != null) {
+			if (element instanceof ExecutionFlow) {
+				return element as ExecutionFlow
+			}
+			else {
+				ret = flow(element.eContainer)
+			}
+		}
+		return ret;
+	}
+	
 	def isTimed (ExecutionFlow it) {
 		scopes.filter[declarations.filter( typeof(TimeEvent) ).size > 0].size > 0
 	}
 	
 	def getTimeEvents(ExecutionFlow it) {
-		scopes.fold(new LinkedList<TimeEvent>, [l, s | l += s.declarations.filter(typeof(TimeEvent)) l])
+		scopes.fold(new ArrayList<TimeEvent>, [l, s | l += s.declarations.filter(typeof(TimeEvent)) l])
 	}
 	
 	def hasHistory(ExecutionFlow it) {
@@ -62,7 +75,7 @@ class SExecExtensions {
 	}
 	
 	def getOutgoingEvents(Scope it) {
-		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::OUT].fold(new LinkedList<EventDefinition>, [l, ev | l += ev l])
+		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::OUT].fold(new ArrayList<EventDefinition>, [l, ev | l += ev l])
 	}
 	
 	def hasIncomingEvents(Scope it) {
@@ -70,11 +83,11 @@ class SExecExtensions {
 	}
 		
 	def List<EventDefinition> getIncomingEvents(Scope it) {
-		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::IN].fold(new LinkedList<EventDefinition>, [l, ev | l += ev l])
+		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::IN].fold(new ArrayList<EventDefinition>, [l, ev | l += ev l])
 	}
 	
 	def List<EventDefinition> getLocalEvents(Scope it) {
-		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::LOCAL].fold(new LinkedList<EventDefinition>, [l, ev | l += ev l])
+		declarations.filter(typeof(EventDefinition)).filter[direction == Direction::LOCAL].fold(new ArrayList<EventDefinition>, [l, ev | l += ev l])
 	}
 	
 	def getInterfaceScopes(ExecutionFlow it) {

+ 0 - 30
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimedStatemachine.java

@@ -1,30 +0,0 @@
-package org.yakindu.scr;
-
-/**
-* Interface for state machines which use timed event triggers.
-*/
-public interface ITimedStatemachine {
-
-	/**
-	* Set the {@link ITimerService} for the state machine. It must be set
-	* externally on a timed state machine before a run cycle can be correct
-	* executed.
-	* 
-	* @param timerService
-	*/
-	public void setTimerService(ITimerService timerService);
-
-	/**
-	* Returns the currently used timer service.
-	* 
-	* @return {@link ITimerService}
-	*/
-	public ITimerService getTimerService();
-
-	/**
-	* Callback method if a {@link TimeEvent} occurred.
-	* 
-	* @param timeEvent
-	*/
-	public void onTimeEventRaised(TimeEvent timeEvent);
-}

+ 38 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimer.java

@@ -0,0 +1,38 @@
+package org.yakindu.scr;
+
+/**
+ * Interface a timer has to implement. Use to implement your own timer
+ * service.
+ * 
+ */
+public interface ITimer {
+
+	/**
+	 * Starts the timing for a given time event id.
+	 * 
+	 * @param callback
+	 * 			  : The target callback where the time event has to be raised.
+	 * 
+	 * @param eventID
+	 *            : The eventID the timer should use if timed out.
+	 *            
+	 * @param time
+	 *            : Time in milliseconds after the given time event should be
+	 *            triggered
+	 *            
+	 * @param isPeriodic
+	 * 			  : Set to true if the time event should be triggered periodically
+	 */
+	public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
+
+	/**
+	 * Unset a time event.
+	 * 
+	 * @param callback
+	 * 			: The target callback for which the time event has to be unset.
+	 * 
+	 * @param eventID
+	 * 			: The time event id.
+	 */
+	public void unsetTimer(ITimerCallback callback, int eventID);
+}

+ 15 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimerCallback.java

@@ -0,0 +1,15 @@
+package org.yakindu.scr;
+
+/**
+* Interface for state machines which use timed event triggers.
+*/
+public interface ITimerCallback {
+	
+	/**
+	* Callback method if a time event occurred.
+	* 
+	* @param eventID
+	* 			:The id of the occurred event.
+	*/
+	public void timeElapsed(int eventID);
+}

+ 0 - 46
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ITimerService.java

@@ -1,46 +0,0 @@
-package org.yakindu.scr;
-
-/**
- * Interface a timer service has to implement. Use to implement your own timer
- * service. A timer service has to be added to a timed state machine.
- * 
- */
-public interface ITimerService {
-
-	/**
-	 * Starts the timing for a given {@link TimeEvent}.
-	 * 
-	 * @param event
-	 *            : The TimeEvent the timer service should throw if timed out.
-	 * @param time
-	 *            : Time in milliseconds after the given time event should be
-	 *            triggered
-	 * @param cycleStartTime
-	 *            : The absolute start time in milliseconds at which the last
-	 *            run cycle was called. Can be used to produce a more accurate
-	 *            timing behavior.
-	 */
-	public void setTimer(TimeEvent event, long time, long cycleStartTime);
-
-	/**
-	 * Unset the given {@link TimeEvent}. Use to unset cyclic repeated time
-	 * events.
-	 * 
-	 * @param event
-	 */
-	public void resetTimer(TimeEvent event);
-
-	/**
-	 * Cancel timer service. Use this to end possible timing threads and free
-	 * memory resources.
-	 */
-	public void cancel();
-
-	/**
-	 * Returns the system time in milliseconds.
-	 * 
-	 * @return the difference, measured in milliseconds, between the current
-	 *         time and a defined point of time in the past.
-	 */
-	public long getSystemTimeMillis();
-}

+ 0 - 58
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/TimeEvent.java

@@ -1,58 +0,0 @@
-package org.yakindu.scr;
-
-/**
- * Event that reflects a time event. It's internally used by
- * {@link ITimedStatemachine}.
- * 
- * @author muehlbrandt
- * 
- * @param <T>
- */
-public class TimeEvent {
-
-	private boolean periodic;
-
-	private ITimedStatemachine statemachine;
-	
-	int index;
-
-	/**
-	 * Constructor for a time event.
-	 * 
-	 * @param periodic
-	 *            : Set to {@code true} if event should be repeated
-	 *            periodically.
-	 * 
-	 * @param index
-	 *            : Index position within the state machine's timeEvent array.
-	 */
-	public TimeEvent(boolean periodic, int index) {
-		this.periodic = periodic;
-		this.index = index;
-	}
-
-	/**
-	 * Returns the state machine reference of the event.
-	 * 
-	 */
-	public ITimedStatemachine getStatemachine() {
-		return statemachine;
-	}
-
-	/**
-	 * Sets the state machine reference of the event.
-	 * 
-	 * @param statemachine
-	 */
-	public void setStatemachine(ITimedStatemachine statemachine) {
-		this.statemachine = statemachine;
-	}
-
-	public boolean isPeriodic() {
-		return periodic;
-	}
-
-	public int getIndex() {
-		return index;
-	}
-}

+ 66 - 35
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/TimerService.java

@@ -1,7 +1,7 @@
 package org.yakindu.scr;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -9,52 +9,83 @@ import java.util.TimerTask;
  * Default timer service implementation.
  * 
  */
-public class TimerService implements ITimerService {
+public class TimerService implements ITimer {
 
 	private final Timer timer = new Timer();
-
-	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
-		// timer tasks are properly reset by sexec model.
-		if (timerTaskMap.containsKey(event)) {
-			resetTimer(event);
+	
+	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
+	
+	/**
+	 * Timer task that reflects a time event. It's internally used by
+	 * {@link TimerService}.
+	 * 
+	 */
+	private class TimeEventTask extends TimerTask {
+	
+		private ITimerCallback callback;
+	
+		int eventID;
+	
+		/**
+		 * Constructor for a time event.
+		 * 
+		 * @param callback
+		 *            : Set to {@code true} if event should be repeated
+		 *            periodically.
+		 * 
+		 * @param eventID
+		 *            : Index position within the state machine's timeEvent
+		 *            array.
+		 */
+		public TimeEventTask(ITimerCallback callback, int eventID) {
+			this.callback = callback;
+			this.eventID = eventID;
 		}
-
-		// Create a new TimerTask for given event.
-		timerTaskMap.put(event, new TimerTask() {
-			@Override
-			public void run() {
-				event.getStatemachine().onTimeEventRaised(event);
+	
+		public void run() {
+			callback.timeElapsed(eventID);
+		}
+	
+		public boolean equals(Object obj) {
+			if (obj instanceof TimeEventTask) {
+				return ((TimeEventTask) obj).callback.equals(callback)
+						&& ((TimeEventTask) obj).eventID == eventID;
 			}
-		});
-
+			return super.equals(obj);
+		}
+	}
+	
+	public void setTimer(final ITimerCallback callback, final int eventID,
+			long time, boolean isPeriodic) {
+	
+		// Create a new TimerTask for given event and store it.
+		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+		timerTaskList.add(timerTask);
+	
 		// start scheduling the timer
-		if (event.isPeriodic()) {
-			timer.scheduleAtFixedRate(timerTaskMap.get(event),
-					time - (System.currentTimeMillis() - cycleStartTime), time);
+		if (isPeriodic) {
+			timer.scheduleAtFixedRate(timerTask, time, time);
 		} else {
-			timer.schedule(timerTaskMap.get(event),
-					time - (System.currentTimeMillis() - cycleStartTime));
+			timer.schedule(timerTask, time);
 		}
 	}
-
-	public void resetTimer(TimeEvent event) {
-		if (timerTaskMap.containsKey(event) && timerTaskMap.get(event) != null) {
-			timerTaskMap.get(event).cancel();
+	
+	public void unsetTimer(ITimerCallback callback, int eventID) {
+		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
+		if (index != -1) {
+			timerTaskList.get(index).cancel();
 			timer.purge();
+			timerTaskList.remove(index);
 		}
-		timerTaskMap.remove(event);
 	}
-
+	
+	/**
+	 * Cancel timer service. Use this to end possible timing threads and free
+	 * memory resources.
+	 */
 	public void cancel() {
 		timer.cancel();
 		timer.purge();
 	}
-
-	public long getSystemTimeMillis() {
-		return System.currentTimeMillis();
-	}
 }
+

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/alwaysoncycle/AlwaysOncycleStatemachine.java

@@ -39,7 +39,6 @@ public class AlwaysOncycleStatemachine implements IAlwaysOncycleStatemachine {
 	public AlwaysOncycleStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/assignmentasexpression/AssignmentAsExpressionStatemachine.java

@@ -251,7 +251,6 @@ public class AssignmentAsExpressionStatemachine
 	public AssignmentAsExpressionStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/bitexpressions/BitExpressionsStatemachine.java

@@ -109,7 +109,6 @@ public class BitExpressionsStatemachine implements IBitExpressionsStatemachine {
 	public BitExpressionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/booleanexpressions/BooleanExpressionsStatemachine.java

@@ -101,7 +101,6 @@ public class BooleanExpressionsStatemachine
 	public BooleanExpressionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/choice/ChoiceStatemachine.java

@@ -60,7 +60,6 @@ public class ChoiceStatemachine implements IChoiceStatemachine {
 	public ChoiceStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ckeywords/CKeywordsStatemachine.java

@@ -297,7 +297,6 @@ public class CKeywordsStatemachine implements ICKeywordsStatemachine {
 	public CKeywordsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/declarations/DeclarationsStatemachine.java

@@ -325,7 +325,6 @@ public class DeclarationsStatemachine implements IDeclarationsStatemachine {
 
 		sCInterface = new SCInterfaceImpl();
 		sCIIfA = new SCIIfAImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/deephistory/DeepHistoryStatemachine.java

@@ -86,7 +86,6 @@ public class DeepHistoryStatemachine implements IDeepHistoryStatemachine {
 	public DeepHistoryStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/enterstate/EnterStateStatemachine.java

@@ -43,7 +43,6 @@ public class EnterStateStatemachine implements IEnterStateStatemachine {
 	public EnterStateStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/exitonselftransition/ExitOnSelfTransitionStatemachine.java

@@ -58,7 +58,6 @@ public class ExitOnSelfTransitionStatemachine
 	public ExitOnSelfTransitionStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/exitstate/ExitStateStatemachine.java

@@ -43,7 +43,6 @@ public class ExitStateStatemachine implements IExitStateStatemachine {
 	public ExitStateStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/featurecalls/FeatureCallsStatemachine.java

@@ -39,7 +39,6 @@ public class FeatureCallsStatemachine implements IFeatureCallsStatemachine {
 	public FeatureCallsStatemachine() {
 
 		sCIMyInterface = new SCIMyInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guard/GuardStatemachine.java

@@ -53,7 +53,6 @@ public class GuardStatemachine implements IGuardStatemachine {
 	public GuardStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guardedentry/GuardedEntryStatemachine.java

@@ -49,7 +49,6 @@ public class GuardedEntryStatemachine implements IGuardedEntryStatemachine {
 	public GuardedEntryStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/guardedexit/GuardedExitStatemachine.java

@@ -49,7 +49,6 @@ public class GuardedExitStatemachine implements IGuardedExitStatemachine {
 	public GuardedExitStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/historywithoutinitialstep/HistoryWithoutInitialStepStatemachine.java

@@ -39,7 +39,6 @@ public class HistoryWithoutInitialStepStatemachine
 	public HistoryWithoutInitialStepStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/ineventlifecycle/InEventLifeCycleStatemachine.java

@@ -41,7 +41,6 @@ public class InEventLifeCycleStatemachine
 	public InEventLifeCycleStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/integerexpressions/IntegerExpressionsStatemachine.java

@@ -231,7 +231,6 @@ public class IntegerExpressionsStatemachine
 	public IntegerExpressionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/internaleventlifecycle/InternalEventLifeCycleStatemachine.java

@@ -42,7 +42,6 @@ public class InternalEventLifeCycleStatemachine
 	public InternalEventLifeCycleStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/javakeywords/JavaKeywordsStatemachine.java

@@ -507,7 +507,6 @@ public class JavaKeywordsStatemachine implements IJavaKeywordsStatemachine {
 	public JavaKeywordsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/namedinterfaceaccess/NamedInterfaceAccessStatemachine.java

@@ -85,7 +85,6 @@ public class NamedInterfaceAccessStatemachine
 
 		sCISafe = new SCISafeImpl();
 		sCIUser = new SCIUserImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/operations/OperationsStatemachine.java

@@ -53,7 +53,6 @@ public class OperationsStatemachine implements IOperationsStatemachine {
 
 		sCIInterface1 = new SCIInterface1Impl();
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/outeventlifecycle/OutEventLifeCycleStatemachine.java

@@ -64,7 +64,6 @@ public class OutEventLifeCycleStatemachine
 	public OutEventLifeCycleStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/parenthesis/ParenthesisStatemachine.java

@@ -29,7 +29,6 @@ public class ParenthesisStatemachine implements IParenthesisStatemachine {
 	public ParenthesisStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 25 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/performancetest/IPerformanceTestStatemachine.java

@@ -0,0 +1,25 @@
+package org.yakindu.scr.performancetest;
+import org.yakindu.scr.IStatemachine;
+import org.yakindu.scr.ITimerCallback;
+
+public interface IPerformanceTestStatemachine
+		extends
+			ITimerCallback,
+			IStatemachine {
+
+	public interface SCInterface {
+		public void raiseE1();
+		public void raiseE2();
+		public void raiseE3();
+		public int getX();
+		public void setX(int value);
+		public int getA();
+		public void setA(int value);
+		public int getC();
+		public void setC(int value);
+
+	}
+
+	public SCInterface getSCInterface();
+
+}

Plik diff jest za duży
+ 1221 - 0
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/performancetest/PerformanceTestStatemachine.java


+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/priorityvalues/PriorityValuesStatemachine.java

@@ -36,7 +36,6 @@ public class PriorityValuesStatemachine implements IPriorityValuesStatemachine {
 	public PriorityValuesStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/raiseevent/RaiseEventStatemachine.java

@@ -42,7 +42,6 @@ public class RaiseEventStatemachine implements IRaiseEventStatemachine {
 	public RaiseEventStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/realexpressions/RealExpressionsStatemachine.java

@@ -231,7 +231,6 @@ public class RealExpressionsStatemachine
 	public RealExpressionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/samenamedifferentregion/SameNameDifferentRegionStatemachine.java

@@ -31,7 +31,6 @@ public class SameNameDifferentRegionStatemachine
 	public SameNameDifferentRegionStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/shallowhistory/ShallowHistoryStatemachine.java

@@ -79,7 +79,6 @@ public class ShallowHistoryStatemachine implements IShallowHistoryStatemachine {
 	public ShallowHistoryStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/simpleevent/SimpleEventStatemachine.java

@@ -29,7 +29,6 @@ public class SimpleEventStatemachine implements ISimpleEventStatemachine {
 	public SimpleEventStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/simplehierachy/SimpleHierachyStatemachine.java

@@ -29,7 +29,6 @@ public class SimpleHierachyStatemachine implements ISimpleHierachyStatemachine {
 	public SimpleHierachyStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/statechartlocalreactions/StatechartLocalReactionsStatemachine.java

@@ -31,7 +31,6 @@ public class StatechartLocalReactionsStatemachine
 	public StatechartLocalReactionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stateisactive/StateIsActiveStatemachine.java

@@ -29,7 +29,6 @@ public class StateIsActiveStatemachine implements IStateIsActiveStatemachine {
 	public StateIsActiveStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stextkeywordsinstatesandregions/STextKeywordsInStatesAndRegionsStatemachine.java

@@ -38,7 +38,6 @@ public class STextKeywordsInStatesAndRegionsStatemachine
 	public STextKeywordsInStatesAndRegionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/stringexpressions/StringExpressionsStatemachine.java

@@ -81,7 +81,6 @@ public class StringExpressionsStatemachine
 	public StringExpressionsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/syncfork/SyncForkStatemachine.java

@@ -36,7 +36,6 @@ public class SyncForkStatemachine implements ISyncForkStatemachine {
 	public SyncForkStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/syncjoin/SyncJoinStatemachine.java

@@ -60,7 +60,6 @@ public class SyncJoinStatemachine implements ISyncJoinStatemachine {
 	public SyncJoinStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 0 - 1
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/scr/valuedevents/ValuedEventsStatemachine.java

@@ -49,7 +49,6 @@ public class ValuedEventsStatemachine implements IValuedEventsStatemachine {
 	public ValuedEventsStatemachine() {
 
 		sCInterface = new SCInterfaceImpl();
-
 	}
 
 	public void init() {

+ 95 - 0
test-plugins/org.yakindu.sct.generator.java.test/test-gen/org/yakindu/sct/generator/java/test/PerformanceTestsTest.java

@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2013 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.generator.java.test;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.yakindu.scr.performancetest.PerformanceTestStatemachine;
+import org.yakindu.scr.performancetest.PerformanceTestStatemachine.State;
+import org.yakindu.scr.TimerService;
+/**
+ *  Unit TestCase for PerformanceTest
+ */
+@SuppressWarnings("all")
+public class PerformanceTestsTest {
+
+	private PerformanceTestStatemachine statemachine;
+
+	@Before
+	public void setUp() {
+		statemachine = new PerformanceTestStatemachine();
+		statemachine.setTimer(new TimerService());
+		statemachine.init();
+	}
+
+	@After
+	public void tearDown() {
+		statemachine = null;
+	}
+
+	@Test
+	public void testtest_100_000() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.mr_A));
+		while (statemachine.getC() < 100000) {
+			if (statemachine.isStateActive(State.mr_A)) {
+				statemachine.raiseE1();;
+			} else {
+				if (statemachine.getC() % 2 == 0) {
+					statemachine.raiseE2();;
+				} else {
+					statemachine.raiseE3();;
+				};
+			}
+			statemachine.runCycle();
+		}
+		assertTrue(statemachine.getA() > 2);
+	}
+	@Test
+	public void testtest_1_000_000() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.mr_A));
+		while (statemachine.getC() < 1000000) {
+			if (statemachine.isStateActive(State.mr_A)) {
+				statemachine.raiseE1();;
+			} else {
+				if (statemachine.getC() % 2 == 0) {
+					statemachine.raiseE2();;
+				} else {
+					statemachine.raiseE3();;
+				};
+			}
+			statemachine.runCycle();
+		}
+		assertTrue(statemachine.getA() > 2);
+	}
+	@Test
+	public void testtest_10_000_000() {
+		statemachine.enter();
+		assertTrue(statemachine.isStateActive(State.mr_A));
+		while (statemachine.getC() < 10000000) {
+			if (statemachine.isStateActive(State.mr_A)) {
+				statemachine.raiseE1();;
+			} else {
+				if (statemachine.getC() % 2 == 0) {
+					statemachine.raiseE2();;
+				} else {
+					statemachine.raiseE3();;
+				};
+			}
+			statemachine.runCycle();
+		}
+		assertTrue(statemachine.getA() > 2);
+	}
+}