View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.statemachine.transition;
21  
22  import org.apache.mina.statemachine.State;
23  import org.apache.mina.statemachine.StateMachine;
24  import org.apache.mina.statemachine.event.Event;
25  
26  /**
27   * The interface implemented by classes which need to react on transitions
28   * between states.
29   * 
30   * A Transition must implement two methods 
31   * <ul>
32   *   <li>execute : a method called when we process the transition</li>
33   *   <li>getNextState : a method that gives the next state for this transition</li>
34   * </ul>
35   * 
36   * Each Transition accepts two parameters :
37   * <ul>
38   *   <li>An event ID : this defines the event this transition will accept</li>
39   *   <li>A next state</li>
40   * </ul>
41   * 
42   * The event ID might be '*', which means the transition will accept any event.
43   * The next state can be null, which means teh next state is the current state.
44   *
45   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
46   */
47  public interface Transition {
48      /**
49       * Executes this {@link Transition}. It is the responsibility of this
50       * {@link Transition} to determine whether it actually applies for the
51       * specified {@link Event}. If this {@link Transition} doesn't apply
52       * nothing should be executed and <tt>false</tt> must be returned.
53       * The method will accept any {@link Event} if it is registered with the 
54       * wild card event ID ('*'), and the event ID it is declared for (ie,
55       * the event ID that has been passed as a parameter to this transition 
56       * constructor.)
57       * 
58       * @param event the current {@link Event}.
59       * @return <tt>true</tt> if the {@link Transition} was executed, 
60       *         <tt>false</tt> otherwise.
61       */
62      boolean execute(Event event);
63  
64      /**
65       * @return the {@link State} which the {@link StateMachine} should move to 
66       * if this {@link Transition} is taken and {@link #execute(Event)} returns
67       * <tt>true</tt>. <code>null</code> if this {@link Transition} is a loopback 
68       * {@link Transition}.
69       */
70      State getNextState();
71  }