Package org.eclipse.net4j.util.fsm

# Class FiniteStateMachine<STATE extends Enum<?>,EVENT extends 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`, `INotifier.INotifier2`, `IDeactivateable`, `ILifecycle`, `ILifecycle.DeferrableActivation`

Direct Known Subclasses:
  `Negotiator`

public abstract class FiniteStateMachine<STATE extends Enum<?>,EVENT extends 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<STATE extends Enum<?>,EVENT extends Enum<?>,SUBJECT>.StateChangedEvent` after state changes of a subject.

Author:
  Eike Stepper

## Nested Class Summary

Nested Classes
Modifier and Type
Class
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`

## Nested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier

`INotifier.INotifier2`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final ITransition`
`FAIL`
`static final ITransition`
`IGNORE`

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

`USE_LABEL`

## Constructor Summary

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

## Method Summary

Modifier and Type
Method
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)`
`void`
`dump(PrintStream out)`
`protected String`
`formatFailMessage(SUBJECT subject, STATE state, EVENT event, Object data)`
`protected String`
`formatIgnoreMessage(SUBJECT subject, STATE state, EVENT event, Object data)`
`protected String`
`formatProcessMessage(SUBJECT subject, STATE state, EVENT event, Object data)`
`final EVENT[]`
`getEvents()`
`protected abstract STATE`
`getState(SUBJECT subject)`
`final STATE[]`
`getStates()`
`final ITransition<STATE,EVENT,SUBJECT,?>`
`getTransition(STATE state, EVENT event)`
`final void`
`init(STATE state, EVENT event, ITransition<STATE,EVENT,SUBJECT,?> transition)`
`final void`
`init(STATE state, EVENT event, STATE targetState)`
`final void`
`initAll(ITransition<STATE,EVENT,SUBJECT,?> transition)`
`final void`
`initAll(STATE targetState)`
`final void`
`initEvents(STATE state, ITransition<STATE,EVENT,SUBJECT,?> transition)`
`final void`
`initEvents(STATE state, STATE targetState)`
`final void`
`initStates(EVENT event, ITransition<STATE,EVENT,SUBJECT,?> transition)`
`final void`
`initStates(EVENT event, STATE targetState)`
`final <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, addUniqueListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, 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 Details

### IGNORE

public static final ITransition IGNORE

### FAIL

public static final ITransition FAIL

## Constructor Details

### FiniteStateMachine

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

### FiniteStateMachine

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

## Method Details

### 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)

### dump

public void dump(PrintStream out)

Since:
  3.25

### createIgnoreTransition

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

### createFailTransition

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

### formatProcessMessage

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

### formatIgnoreMessage

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

### formatFailMessage

protected String formatFailMessage(SUBJECT subject, STATE state, EVENT event, 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