Class StateControl


  • public class StateControl
    extends java.lang.Object
    Allows for programmatic control of a state machines execution.

    The *Now() family of methods move to a new State immediately and let the new State handle the current Event. The *Next() family on the other hand let the new State handle the next Event which is generated which make these method the programmatic equivalent of using the Transition annotation.

    Using the breakAndCall*() and breakAndReturn* methods one can create sub state machines which behave very much like sub routines. When calling a state the current state (or the specified returnTo state) will be pushed on a stack. When returning from a state the last pushed state will be popped from the stack and used as the new state.

    • Constructor Detail

      • StateControl

        public StateControl()
    • Method Detail

      • breakAndContinue

        public static void breakAndContinue()
        Breaks the execution of the current Transition and tries to find another Transition with higher weight or a Transition of a parent State which can handle the current Event.
      • breakAndGotoNow

        public static void breakAndGotoNow​(java.lang.String state)
        Breaks the execution of the current Transition and lets the State with the specified id handle the current Event.
        Parameters:
        state - the id of the State to go to.
      • breakAndGotoNext

        public static void breakAndGotoNext​(java.lang.String state)
        Breaks the execution of the current Transition and lets the State with the specified id handle the next Event. Using this method is the programmatic equivalent of using the Transition annotation.
        Parameters:
        state - the id of the State to go to.
      • breakAndCallNow

        public static void breakAndCallNow​(java.lang.String state)
        Breaks the execution of the current Transition and lets the State with the specified id handle the current Event. Before moving to the new state the current state will be recorded. The next call to breakAndReturnNow() or breakAndReturnNext() will return to the current state.
        Parameters:
        state - the id of the State to call.
      • breakAndCallNext

        public static void breakAndCallNext​(java.lang.String state)
        Breaks the execution of the current Transition and lets the State with the specified id handle the next Event. Before moving to the new state the current state will be recorded. The next call to breakAndReturnNow() or breakAndReturnNext() will return to the current state.
        Parameters:
        state - the id of the State to call.
      • breakAndCallNow

        public static void breakAndCallNow​(java.lang.String state,
                                           java.lang.String returnTo)
        Breaks the execution of the current Transition and lets the State with the specified id handle the current Event. Before moving to the new state the current state will be recorded. The next call to breakAndReturnNow() or breakAndReturnNext() will return to the specified returnTo state.
        Parameters:
        state - the id of the State to call.
        returnTo - the id of the State to return to.
      • breakAndCallNext

        public static void breakAndCallNext​(java.lang.String state,
                                            java.lang.String returnTo)
        Breaks the execution of the current Transition and lets the State with the specified id handle the next Event. Before moving to the new state the current state will be recorded. The next call to breakAndReturnNow() or breakAndReturnNext() will return to the specified returnTo state.
        Parameters:
        state - the id of the State to call.
        returnTo - the id of the State to return to.
      • breakAndReturnNow

        public static void breakAndReturnNow()
        Breaks the execution of the current Transition and lets the last recorded State handle the current Event.
      • breakAndReturnNext

        public static void breakAndReturnNext()
        Breaks the execution of the current Transition and lets the last recorded State handle the next Event.