private void createStateMachine() { // State Machine Components // Define and initialize in the order: // 1) Events // 2) Regions and states, from outer to inner // 3) Transitions, ordered internal, local, external // 4) Group states and transitions within a region together. // Maintain the same order of declaration and initialization. // Events // Event constructors take the form (name, parent) cycleEvent = new NSFEvent("CycleEvent", this); aReadyEvent = new NSFEvent("AReadyEvent", this); bReadyEvent = new NSFEvent("BReadyEvent", this); aCompleteEvent = new NSFEvent("ACompleteEvent", this); bCompleteEvent = new NSFEvent("BCompleteEvent", this); // Regions and states, from outer to inner systemRegion = new NSFRegion("SystemRegion", this); subsystemARegion = new NSFRegion("SubsystemARegion", this); subsystemBRegion = new NSFRegion("SubsystemBRegion", this); initializeForkJoin = new NSFForkJoin("InitializeForkJoin", this); cycleForkJoin = new NSFForkJoin("CycleForkJoin", this); completeForkJoin = new NSFForkJoin("CompleteForkJoin", this); // System Region // Regions and states, from outer to inner // Initial state construtors take the form (name, parent) systemInitialState = new NSFInitialState("SystemInitial", systemRegion); // Composite state construtors take the form (name, parent, entry actions, exit actions) waitForCycleEventState = new NSFCompositeState("WaitForCycleEvent", systemRegion, null, null); // Transitions, ordered internal, local, external // External transition construtors take the form (name, source, target, trigger, guard, action) systemInitialToInitializeForkJoinTransition = new NSFExternalTransition("SystemInitialToInitializeForkJoin", systemInitialState, initializeForkJoin, null, null, null); initializeForkJoinToWaitForCycleEventTransition = new NSFExternalTransition("InitializeForkJoinToWaitForCycleEvent", initializeForkJoin, waitForCycleEventState, null, null, null); waitForCycleEventToCycleForkJoinTransition = new NSFExternalTransition("WaitForCycleEventToCycleForkJoin", waitForCycleEventState, cycleForkJoin, cycleEvent, null, null); cycleForkJoinToCompleteForkJoinTransiiton = new NSFForkJoinTransition("CycleForkJoinToCompleteForkJoin", cycleForkJoin, completeForkJoin, systemRegion, null); completeForkJoinToWaitForCycleEventTransition = new NSFExternalTransition("CompleteForkJoinToWaitForCycleEvent", completeForkJoin, waitForCycleEventState, null, null, null); // Subystem A Region // Regions and states, from outer to inner // Initial state construtors take the form (name, parent) subsystemAInitialState = new NSFInitialState("SubsystemAInitial", subsystemARegion); // Composite state construtors take the form (name, parent, entry actions, exit actions) initializeAState = new NSFCompositeState("InitializeA", subsystemARegion, initializeAEntryActions, null); cycleAState = new NSFCompositeState("CycleA", subsystemARegion, cycleAEntryActions, null); // Transitions, ordered internal, local, external // External transition construtors take the form (name, source, target, trigger, guard, action) subsystemAInitialToInitializeATransition = new NSFExternalTransition("SubsystemAInitialToInitializeA", subsystemAInitialState, initializeAState, null, null, null); initializeAToInitializeForkJoinTransition = new NSFExternalTransition("InitializeAToInitializeForkJoin", initializeAState, initializeForkJoin, aReadyEvent, null, null); initializeForkJoinToCycleForkJoinARegionTransition = new NSFForkJoinTransition("InitializeForkJoinToCycleForkJoinARegion", initializeForkJoin, cycleForkJoin, subsystemARegion, null); cycleForkJoinToCycleATransition = new NSFExternalTransition("CycleForkJoinToCycleA", cycleForkJoin, cycleAState, null, null, null); cycleAToCompleteForkJoinTransition = new NSFExternalTransition("CycleAToCompleteForkJoin", cycleAState, completeForkJoin, aCompleteEvent, null, null); // Subystem B Region // Regions and states, from outer to inner // Initial state construtors take the form (name, parent) subsystemBInitialState = new NSFInitialState("SubsystemBInitial", subsystemBRegion); // Composite state construtors take the form (name, parent, entry actions, exit actions) initializeBState = new NSFCompositeState("InitializeB", subsystemBRegion, initializeBEntryActions, null); cycleBState = new NSFCompositeState("CycleB", subsystemBRegion, cycleBEntryActions, null); // Transitions, ordered internal, local, external // External transition construtors take the form (name, source, target, trigger, guard, action) subsystemBInitialToInitializeBTransition = new NSFExternalTransition("SubsystemBInitialToInitializeB", subsystemBInitialState, initializeBState, null, null, null); initializeBToInitializeForkJoinTransition = new NSFExternalTransition("InitializeBToInitializeForkJoin", initializeBState, initializeForkJoin, bReadyEvent, null, null); initializeForkJoinToCycleForkJoinBRegionTransition = new NSFForkJoinTransition("InitializeForkJoinToCycleForkJoinBRegion", initializeForkJoin, cycleForkJoin, subsystemBRegion, null); cycleForkJoinToCycleBTransition = new NSFExternalTransition("CycleForkJoinToCycleB", cycleForkJoin, cycleBState, null, null, null); cycleBToCompleteForkJoinTransition = new NSFExternalTransition("CycleBToCompleteForkJoin", cycleBState, completeForkJoin, bCompleteEvent, null, null); }