1. /*
  2. * @(#)StateEngine.java 1.9 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.spi.orbutil.fsm;
  8. /**
  9. * A StateEngine defines the state transition function for a
  10. * finite state machine (FSM). A FSM always has a current state.
  11. * In response to an Input, the FSM performs an Action and
  12. * makes a transition to a new state. Note that any object can
  13. * be used as an input if it supports the Input interface.
  14. * For example, a protocol message may be an input. The FSM
  15. * uses only the result of calling getLabel on the Input to
  16. * drive the transition.
  17. * <p>
  18. * The function can be non-deterministic
  19. * in that the same input may cause transitions to different new
  20. * states from the current state. In this case, the action that
  21. * is executed for the transition must set the correct new state.
  22. *
  23. * @version @(#)StateEngine.java 1.9 03/12/19
  24. * @author Ken Cavanaugh
  25. */
  26. public interface StateEngine
  27. {
  28. /** Add a new transition (old,in,guard,act,new) to the state engine.
  29. * Multiple calls to add with the same old and in are permitted,
  30. * in which case only a transition in which the guard evaluates to
  31. * true will be taken. If no such transition is enabled, a default
  32. * will be taken. If more than one transition is enabled, one will
  33. * be chosen arbitrarily.
  34. * This method can only be called before done(). An attempt to
  35. * call it after done() results in an IllegalStateException.
  36. */
  37. public StateEngine add( State oldState, Input input, Guard guard,
  38. Action action, State newState ) throws IllegalStateException ;
  39. /** Add a transition with a guard that always evaluates to true.
  40. */
  41. public StateEngine add( State oldState, Input input,
  42. Action action, State newState ) throws IllegalStateException ;
  43. /** Set the default transition and action for a state.
  44. * This transition will be used if no more specific transition was
  45. * defined for the actual input. Repeated calls to this method
  46. * simply change the default.
  47. * This method can only be called before done(). An attempt to
  48. * call it after done() results in an IllegalStateException.
  49. */
  50. public StateEngine setDefault( State oldState, Action action, State newState )
  51. throws IllegalStateException ;
  52. /** Equivalent to setDefault( oldState, act, newState ) where act is an
  53. * action that does nothing.
  54. */
  55. public StateEngine setDefault( State oldState, State newState )
  56. throws IllegalStateException ;
  57. /** Euaivalent to setDefault( oldState, oldState )
  58. */
  59. public StateEngine setDefault( State oldState )
  60. throws IllegalStateException ;
  61. /** Set the default action used in this state engine. This is the
  62. * action that is called whenever there is no applicable transition.
  63. * Normally this would simply flag an error. This method can only
  64. * be called before done(). An attempt to
  65. * call it after done() results in an IllegalStateException.
  66. */
  67. public void setDefaultAction( Action act ) throws IllegalStateException ;
  68. /** Called after all transitions have been added to the state engine.
  69. * This provides an opportunity for the implementation to optimize
  70. * its representation before the state engine is used. This method
  71. * may only be called once. An attempt to call it more than once
  72. * results in an IllegalStateException.
  73. */
  74. public void done() throws IllegalStateException ;
  75. /** Create an instance of a FSM that uses this state engine.
  76. * The initial state of the FSM will be the stateState specified
  77. * here. This method can only be called after done(). An attempt
  78. * to call it before done results in an IllegalStateException.
  79. */
  80. public FSM makeFSM( State startState ) throws IllegalStateException ;
  81. }
  82. // end of StateEngine.java