src/share/classes/com/sun/corba/se/spi/orbutil/fsm/StateEngine.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.corba.se.spi.orbutil.fsm;
aoqi@0 27
aoqi@0 28 /**
aoqi@0 29 * A StateEngine defines the state transition function for a
aoqi@0 30 * finite state machine (FSM). A FSM always has a current state.
aoqi@0 31 * In response to an Input, the FSM performs an Action and
aoqi@0 32 * makes a transition to a new state. Note that any object can
aoqi@0 33 * be used as an input if it supports the Input interface.
aoqi@0 34 * For example, a protocol message may be an input. The FSM
aoqi@0 35 * uses only the result of calling getLabel on the Input to
aoqi@0 36 * drive the transition.
aoqi@0 37 * <p>
aoqi@0 38 * The function can be non-deterministic
aoqi@0 39 * in that the same input may cause transitions to different new
aoqi@0 40 * states from the current state. In this case, the action that
aoqi@0 41 * is executed for the transition must set the correct new state.
aoqi@0 42 *
aoqi@0 43 * @author Ken Cavanaugh
aoqi@0 44 */
aoqi@0 45 public interface StateEngine
aoqi@0 46 {
aoqi@0 47 /** Add a new transition (old,in,guard,act,new) to the state engine.
aoqi@0 48 * Multiple calls to add with the same old and in are permitted,
aoqi@0 49 * in which case only a transition in which the guard evaluates to
aoqi@0 50 * true will be taken. If no such transition is enabled, a default
aoqi@0 51 * will be taken. If more than one transition is enabled, one will
aoqi@0 52 * be chosen arbitrarily.
aoqi@0 53 * This method can only be called before done(). An attempt to
aoqi@0 54 * call it after done() results in an IllegalStateException.
aoqi@0 55 */
aoqi@0 56 public StateEngine add( State oldState, Input input, Guard guard,
aoqi@0 57 Action action, State newState ) throws IllegalStateException ;
aoqi@0 58
aoqi@0 59 /** Add a transition with a guard that always evaluates to true.
aoqi@0 60 */
aoqi@0 61 public StateEngine add( State oldState, Input input,
aoqi@0 62 Action action, State newState ) throws IllegalStateException ;
aoqi@0 63
aoqi@0 64 /** Set the default transition and action for a state.
aoqi@0 65 * This transition will be used if no more specific transition was
aoqi@0 66 * defined for the actual input. Repeated calls to this method
aoqi@0 67 * simply change the default.
aoqi@0 68 * This method can only be called before done(). An attempt to
aoqi@0 69 * call it after done() results in an IllegalStateException.
aoqi@0 70 */
aoqi@0 71 public StateEngine setDefault( State oldState, Action action, State newState )
aoqi@0 72 throws IllegalStateException ;
aoqi@0 73
aoqi@0 74 /** Equivalent to setDefault( oldState, act, newState ) where act is an
aoqi@0 75 * action that does nothing.
aoqi@0 76 */
aoqi@0 77 public StateEngine setDefault( State oldState, State newState )
aoqi@0 78 throws IllegalStateException ;
aoqi@0 79
aoqi@0 80 /** Euaivalent to setDefault( oldState, oldState )
aoqi@0 81 */
aoqi@0 82 public StateEngine setDefault( State oldState )
aoqi@0 83 throws IllegalStateException ;
aoqi@0 84
aoqi@0 85 /** Set the default action used in this state engine. This is the
aoqi@0 86 * action that is called whenever there is no applicable transition.
aoqi@0 87 * Normally this would simply flag an error. This method can only
aoqi@0 88 * be called before done(). An attempt to
aoqi@0 89 * call it after done() results in an IllegalStateException.
aoqi@0 90 */
aoqi@0 91 public void setDefaultAction( Action act ) throws IllegalStateException ;
aoqi@0 92
aoqi@0 93 /** Called after all transitions have been added to the state engine.
aoqi@0 94 * This provides an opportunity for the implementation to optimize
aoqi@0 95 * its representation before the state engine is used. This method
aoqi@0 96 * may only be called once. An attempt to call it more than once
aoqi@0 97 * results in an IllegalStateException.
aoqi@0 98 */
aoqi@0 99 public void done() throws IllegalStateException ;
aoqi@0 100
aoqi@0 101 /** Create an instance of a FSM that uses this state engine.
aoqi@0 102 * The initial state of the FSM will be the stateState specified
aoqi@0 103 * here. This method can only be called after done(). An attempt
aoqi@0 104 * to call it before done results in an IllegalStateException.
aoqi@0 105 */
aoqi@0 106 public FSM makeFSM( State startState ) throws IllegalStateException ;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 // end of StateEngine.java

mercurial