org.eclipse.net4j.util.fsm

## Class FiniteStateMachine<STATE extends java.lang.Enum<?>,EVENT extends java.lang.Enum<?>,SUBJECT>

- java.lang.Object
- - org.eclipse.net4j.util.event.Notifier
  - - org.eclipse.net4j.util.lifecycle.Lifecycle
    - - org.eclipse.net4j.util.fsm.FiniteStateMachine<STATE,EVENT,SUBJECT>

- All Implemented Interfaces:
    INotifier, IDeactivateable, ILifecycle, ILifecycle.DeferrableActivation
  Direct Known Subclasses:
    Negotiator

      public abstract class FiniteStateMachine<STATE extends java.lang.Enum<?>,EVENT extends java.lang.Enum<?>,SUBJECT>
      extends Lifecycle

  A finite state machine that is based on a matrix of `transitions`.

  A finite state machine can fire the following events:

  - `FiniteStateMachine.StateChangedEvent` after state changes of a subject.
  Author:
    Eike Stepper
  Apiviz
  Apiviz
    `ITransition` oneway - - matrix
  Apiviz
    `FiniteStateMachine.StateChangedEvent` - - fires

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `FiniteStateMachine.ChangeStateTransition` A `transition` that changes the `state` of a subject.
    `static class` | `FiniteStateMachine.FailTransition` Deprecated. Use `FAIL`
    `static class` | `FiniteStateMachine.IgnoreTransition` Deprecated. Use `IGNORE`
    `class` | `FiniteStateMachine.StateChangedEvent`

    - ### Nested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle

      `ILifecycle.DeferrableActivation`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ITransition` | `FAIL`
    `static ITransition` | `IGNORE`

    - ### Fields inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle

      `USE_LABEL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FiniteStateMachine(java.lang.Class<STATE> stateEnum, java.lang.Class<EVENT> eventEnum)`
    `FiniteStateMachine(java.lang.Class<STATE> stateEnum, java.lang.Class<EVENT> eventEnum, ITransition<STATE,EVENT,SUBJECT,?> defaultTransition)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected STATE` | `changeState(SUBJECT subject, STATE state)`
    `protected ITransition<STATE,EVENT,SUBJECT,?>` | `createFailTransition(STATE state, EVENT event)`
    `protected ITransition<STATE,EVENT,SUBJECT,?>` | `createIgnoreTransition(STATE state, EVENT event)`
    `protected java.lang.String` | `formatFailMessage(SUBJECT subject, STATE state, EVENT event, java.lang.Object data)`
    `protected java.lang.String` | `formatIgnoreMessage(SUBJECT subject, STATE state, EVENT event, java.lang.Object data)`
    `protected java.lang.String` | `formatProcessMessage(SUBJECT subject, STATE state, EVENT event, java.lang.Object data)`
    `EVENT[]` | `getEvents()`
    `protected abstract STATE` | `getState(SUBJECT subject)`
    `STATE[]` | `getStates()`
    `ITransition<STATE,EVENT,SUBJECT,?>` | `getTransition(STATE state, EVENT event)`
    `void` | `init(STATE state, EVENT event, ITransition<STATE,EVENT,SUBJECT,?> transition)`
    `void` | `init(STATE state, EVENT event, STATE targetState)`
    `void` | `initAll(ITransition<STATE,EVENT,SUBJECT,?> transition)`
    `void` | `initAll(STATE targetState)`
    `void` | `initEvents(STATE state, ITransition<STATE,EVENT,SUBJECT,?> transition)`
    `void` | `initEvents(STATE state, STATE targetState)`
    `void` | `initStates(EVENT event, ITransition<STATE,EVENT,SUBJECT,?> transition)`
    `void` | `initStates(EVENT event, STATE targetState)`
    `<DATA> void` | `process(SUBJECT subject, EVENT event, DATA data)`
    `protected abstract void` | `setState(SUBJECT subject, STATE state)`

    - ### Methods inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle

      `activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doActivate, doAfterActivate, doBeforeActivate, doBeforeDeactivate, doDeactivate, dump, getLifecycleState, isActive, isDeferredActivation, toString`

    - ### Methods inherited from class org.eclipse.net4j.util.event.Notifier

      `addListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListeners, lastListenerRemoved, removeListener`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.net4j.util.event.INotifier

      `addListener, getListeners, hasListeners, removeListener`

- - ### Field Detail

    - #### IGNORE

          public static final ITransition IGNORE

    - #### FAIL

          public static final ITransition FAIL

  - ### Constructor Detail

    - #### FiniteStateMachine

          public FiniteStateMachine(java.lang.Class<STATE> stateEnum,
                                    java.lang.Class<EVENT> eventEnum,
                                    ITransition<STATE,EVENT,SUBJECT,?> defaultTransition)

    - #### FiniteStateMachine

          public FiniteStateMachine(java.lang.Class<STATE> stateEnum,
                                    java.lang.Class<EVENT> eventEnum)

  - ### Method Detail

    - #### getStates

          public final STATE[] getStates()

    - #### getEvents

          public final EVENT[] getEvents()

    - #### getTransition

          public final ITransition<STATE,EVENT,SUBJECT,?> getTransition(STATE state,
                                                                        EVENT event)

    - #### init

          public final void init(STATE state,
                                 EVENT event,
                                 STATE targetState)

    - #### init

          public final void init(STATE state,
                                 EVENT event,
                                 ITransition<STATE,EVENT,SUBJECT,?> transition)

    - #### initEvents

          public final void initEvents(STATE state,
                                       STATE targetState)

    - #### initEvents

          public final void initEvents(STATE state,
                                       ITransition<STATE,EVENT,SUBJECT,?> transition)

    - #### initStates

          public final void initStates(EVENT event,
                                       STATE targetState)

    - #### initStates

          public final void initStates(EVENT event,
                                       ITransition<STATE,EVENT,SUBJECT,?> transition)

    - #### initAll

          public final void initAll(STATE targetState)

    - #### initAll

          public final void initAll(ITransition<STATE,EVENT,SUBJECT,?> transition)

    - #### process

          public final <DATA> void process(SUBJECT subject,
                                           EVENT event,
                                           DATA data)

    - #### createIgnoreTransition

          protected ITransition<STATE,EVENT,SUBJECT,?> createIgnoreTransition(STATE state,
                                                                              EVENT event)

    - #### createFailTransition

          protected ITransition<STATE,EVENT,SUBJECT,?> createFailTransition(STATE state,
                                                                            EVENT event)

    - #### formatProcessMessage

          protected java.lang.String formatProcessMessage(SUBJECT subject,
                                                          STATE state,
                                                          EVENT event,
                                                          java.lang.Object data)

    - #### formatIgnoreMessage

          protected java.lang.String formatIgnoreMessage(SUBJECT subject,
                                                         STATE state,
                                                         EVENT event,
                                                         java.lang.Object data)

    - #### formatFailMessage

          protected java.lang.String formatFailMessage(SUBJECT subject,
                                                       STATE state,
                                                       EVENT event,
                                                       java.lang.Object data)

    - #### getState

          protected abstract STATE getState(SUBJECT subject)

    - #### setState

          protected abstract void setState(SUBJECT subject,
                                           STATE state)

    - #### changeState

          protected STATE changeState(SUBJECT subject,
                                      STATE state)

      Since:
        3.0

Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html