org.squirrelframework.foundation.fsm.StateMachineBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squirrel-foundation Show documentation
Show all versions of squirrel-foundation Show documentation
foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation.
package org.squirrelframework.foundation.fsm;
import org.squirrelframework.foundation.fsm.builder.EntryExitActionBuilder;
import org.squirrelframework.foundation.fsm.builder.ExternalTransitionBuilder;
import org.squirrelframework.foundation.fsm.builder.InternalTransitionBuilder;
import org.squirrelframework.foundation.fsm.builder.LocalTransitionBuilder;
/**
* State machine builder API.
*
* @author Henry.He
*
* @param The type of implemented state machine
* @param The type of implemented state
* @param The type of implemented event
* @param The type of implemented context
*/
public interface StateMachineBuilder, S, E, C> {
/**
* Start to build external transition
* @return External transition builder
*/
ExternalTransitionBuilder externalTransition();
/**
* Start to build external transition, same as externalTransition
* @return External transition builder
*/
ExternalTransitionBuilder transition();
/**
* Start to build local transition
* @return Local transition builder
*/
LocalTransitionBuilder localTransition();
/**
* Start to build internal transition
* @return Internal transition builder
*/
InternalTransitionBuilder internalTransition();
ExternalTransitionBuilder externalTransition(int priority);
/**
* Same as externalTransition
* @param priority transition priority
* @return External transition builder
*/
ExternalTransitionBuilder transition(int priority);
LocalTransitionBuilder localTransition(int priority);
InternalTransitionBuilder internalTransition(int priority);
/**
* Define a new state in state machine model
* @param stateId id of new state
* @return defined new mutable state
*/
MutableState defineState(S stateId);
/**
* Define a final state in state machine model
* @param stateId id of final state
* @return defined final state
*/
MutableState defineFinalState(S stateId);
/**
* Define a linked state
* @param stateId id of linked state
* @param linkedStateMachineBuilder linked state machine builder
* @param initialLinkedState initial linked state
* @param extraParams additional parameters used to create linked state machine
* @return linked state
*/
MutableState defineLinkedState(S stateId,
StateMachineBuilder extends StateMachine, S, E, C>, S, E, C> linkedStateMachineBuilder,
S initialLinkedState, Object... extraParams);
/**
* Define a timed state
* @param stateId state id
* @param initialDelay initial delay ms
* @param timeInterval time period if null not repeat
* @param autoEvent
* @param autoContext
* @return timed state
*/
MutableState defineTimedState(S stateId, long initialDelay,
long timeInterval, E autoEvent, C autoContext);
/**
* Define sequential child states whose hierarchy type is default set to NONE on parent state
* @param parentStateId id of parent state
* @param childStateIds child states id of parent state. The first child state will be used as initial child state of parent state.
*/
void defineSequentialStatesOn(S parentStateId, S... childStateIds);
/**
* Define sequential child states on parent state
*
* @param parentStateId id of parent state
* @param historyType history type of parent state
* @param childStateIds child states id of parent state. The first child state will be used as initial child state of parent state.
*/
void defineSequentialStatesOn(S parentStateId, HistoryType historyType, S... childStateIds);
/**
* Define sequential child states on parent state. For parallel state the history type always be none.
*
* @param parentStateId id of parent state
* @param childStateIds child states id of parent state. The first child state will be used as initial child state of parent state.
*/
void defineParallelStatesOn(S parentStateId, S... childStateIds);
/**
* Define event for parallel transition finished
* @param finishEvent
*/
void defineFinishEvent(E finishEvent);
/**
* Define event for state machine started
* @param startEvent
*/
void defineStartEvent(E startEvent);
/**
* Define event for state machine terminated
* @param terminateEvent
*/
void defineTerminateEvent(E terminateEvent);
/**
* Define on entry actions for state
* @param stateId the id of state
* @return the builder to build state on entry actions
*/
EntryExitActionBuilder onEntry(S stateId);
/**
* Define on exit actions for state
* @param stateId the id of state
* @return the builder to build state on exit actions
*/
EntryExitActionBuilder onExit(S stateId);
/**
* Create a new state machine instance
* @param initialStateId initial state id
* @return new state machine instance
*/
T newStateMachine(S initialStateId);
/**
* Create new state machine instance according to state machine definition
* @param initialStateId the id of state machine initial state
* @param extraParams other parameters for instantiate state machine
* @return new state machine
*/
T newStateMachine(S initialStateId, Object... extraParams);
/**
* Create new state machine instance according to state machine definition
* @param initialStateId the id of state machine initial state
* @param configuration configuration for state machine
* @param extraParams other parameters for instantiate state machine
* @return new state machine
*/
T newStateMachine(S initialStateId, StateMachineConfiguration configuration, Object... extraParams);
/**
* Set default state machine configuration for state machine instance created by this builder
* @param configure state machine default configuration
*/
void setStateMachineConfiguration(StateMachineConfiguration configure);
}