uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

State Machine Actions and Do Activities

When an transition is taken, an action can occur. This is indicated using a slash "/" followed by arbitrary code in braces.

Similarly, when entering or exiting a state, an action can occur. This is indicated using the keywords entry or exit, followed by a slash, followed by code.

The actions described above should take negligible time to execute.

If a longer-running computation or activity should run while in a state, encode this using the keyword do, followed by code. In languages such as Java that support it, a thread will be started to invoke the thread. This allows the state machine to 'stay live' and be able to respond to other events, even while the do activity is running. Note that at the current time, the do activity thread must terminate itself; as an enhancement, the do activity thread should be interrupted and cancelled when a transition is taken out of the state.

Example


namespace example;

class LightFixture
{
  bulb
  {
    On {
      entry / { doEntry(); }
      exit / { doExit(); }
      push -> /{ doTransition(); } Off;
      do { doThisContinuouslyWhileOn(); }
    }
    Off {}
  }

  void doEntry() {System.out.println("Entry");}
  void doExit() {System.out.println("Exit");}
  void doTransition() {System.out.println("Transition");}
  void doThisContinuouslyWhileOn() {
    while (true) {
      System.out.println("Still on");
      try {
        Thread.sleep(1000);
      }
      catch (InterruptedException e) {}
    }
  }
}


      

Load the above code into UmpleOnline

 

Another Example

// This demonstrates that actions can be different in different target languages
class DemoSM
{
  Integer id;
  sm {
    s1 {
      e1 / Java {id=5;} Php {$id=5;} -> s2;
    }
    s2 {
    }
  }
}


      

Load the above code into UmpleOnline

 

Syntax


// An action can be executed on a transition, or on entry or exit
action : / [[moreCode]]+

entryOrExitAction : [=type:entry|exit] / [[moreCode]]+

// A do activity is long-lasting and can be interrupted
activity : do [[moreCode]]+