KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > orbutil > fsm > StateEngine


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
8 package com.sun.corba.se.spi.orbutil.fsm;
9
10 /**
11  * A StateEngine defines the state transition function for a
12  * finite state machine (FSM). A FSM always has a current state.
13  * In response to an Input, the FSM performs an Action and
14  * makes a transition to a new state. Note that any object can
15  * be used as an input if it supports the Input interface.
16  * For example, a protocol message may be an input. The FSM
17  * uses only the result of calling getLabel on the Input to
18  * drive the transition.
19  * <p>
20  * The function can be non-deterministic
21  * in that the same input may cause transitions to different new
22  * states from the current state. In this case, the action that
23  * is executed for the transition must set the correct new state.
24  *
25  * @version @(#)StateEngine.java 1.9 03/12/19
26  * @author Ken Cavanaugh
27  */

28 public interface StateEngine
29 {
30     /** Add a new transition (old,in,guard,act,new) to the state engine.
31     * Multiple calls to add with the same old and in are permitted,
32     * in which case only a transition in which the guard evaluates to
33     * true will be taken. If no such transition is enabled, a default
34     * will be taken. If more than one transition is enabled, one will
35     * be chosen arbitrarily.
36     * This method can only be called before done(). An attempt to
37     * call it after done() results in an IllegalStateException.
38     */

39     public StateEngine add( State oldState, Input input, Guard guard,
40         Action action, State newState ) throws IllegalStateException JavaDoc ;
41
42     /** Add a transition with a guard that always evaluates to true.
43     */

44     public StateEngine add( State oldState, Input input,
45         Action action, State newState ) throws IllegalStateException JavaDoc ;
46
47     /** Set the default transition and action for a state.
48     * This transition will be used if no more specific transition was
49     * defined for the actual input. Repeated calls to this method
50     * simply change the default.
51     * This method can only be called before done(). An attempt to
52     * call it after done() results in an IllegalStateException.
53     */

54     public StateEngine setDefault( State oldState, Action action, State newState )
55         throws IllegalStateException JavaDoc ;
56
57     /** Equivalent to setDefault( oldState, act, newState ) where act is an
58      * action that does nothing.
59      */

60     public StateEngine setDefault( State oldState, State newState )
61         throws IllegalStateException JavaDoc ;
62
63     /** Euaivalent to setDefault( oldState, oldState )
64      */

65     public StateEngine setDefault( State oldState )
66         throws IllegalStateException JavaDoc ;
67
68     /** Set the default action used in this state engine. This is the
69     * action that is called whenever there is no applicable transition.
70     * Normally this would simply flag an error. This method can only
71     * be called before done(). An attempt to
72     * call it after done() results in an IllegalStateException.
73     */

74     public void setDefaultAction( Action act ) throws IllegalStateException JavaDoc ;
75
76     /** Called after all transitions have been added to the state engine.
77     * This provides an opportunity for the implementation to optimize
78     * its representation before the state engine is used. This method
79     * may only be called once. An attempt to call it more than once
80     * results in an IllegalStateException.
81     */

82     public void done() throws IllegalStateException JavaDoc ;
83
84     /** Create an instance of a FSM that uses this state engine.
85     * The initial state of the FSM will be the stateState specified
86     * here. This method can only be called after done(). An attempt
87     * to call it before done results in an IllegalStateException.
88     */

89     public FSM makeFSM( State startState ) throws IllegalStateException JavaDoc ;
90 }
91
92 // end of StateEngine.java
93

94
95
Popular Tags