org.squirrelframework.foundation.fsm.ActionExecutionService 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.component.Observable;
import org.squirrelframework.foundation.event.SquirrelEvent;
import org.squirrelframework.foundation.exception.TransitionException;
import org.squirrelframework.foundation.util.ReflectUtils;
import java.lang.reflect.Method;
/**
* State machine action executor. The action defined during state entry/exit and transition will be
* collected by action executor, and executed later together. The executor can execute actions in
* synchronize and synchronize manner.
*
* @author Henry.He
*
* @param type of State Machine
* @param type of State
* @param type of Event
* @param type of Context
*/
public interface ActionExecutionService, S, E, C> extends Observable {
/**
* Begin a action execution collection in the bucket.
*/
void begin(String bucketName);
/**
* Execute all the actions collected by front bucket.
*/
void execute();
/**
* Reset all deferred actions and its count
*/
void reset();
/**
* Set dummy execution true will cause no action being actually invoked when calling {@link ActionExecutionService#execute()}.
*
* @param dummyExecution
*/
void setDummyExecution(boolean dummyExecution);
/**
* Add action and all the execution parameters into execution context;
*
* @param action activity to be executed
* @param from source state
* @param to target state
* @param event activity cause
* @param context external environment context
* @param stateMachine state machine reference
*/
void defer(Action action, S from, S to, E event, C context, T stateMachine);
/**
* Add before action execution listener which can be used for monitoring execution
* @param listener action execution listener
*/
void addExecActionListener(BeforeExecActionListener listener);
/**
* Remove before action execution listener
* @param listener action execution listener
*/
void removeExecActionListener(BeforeExecActionListener listener);
/**
* Add after action execution listener which can be used for monitoring execution
* @param listener action execution listener
*/
void addExecActionListener(AfterExecActionListener listener);
/**
* Remove after action execution listener
* @param listener action execution listener
*/
void removeExecActionListener(AfterExecActionListener listener);
/**
* Add action execution exception listener which can be used for monitoring execution
* @param listener action execution exception listener
*/
void addExecActionExceptionListener(ExecActionExceptionListener listener);
/**
* Remove action execution exception listener
* @param listener action execution exception listener
*/
void removeExecActionExceptionListener(ExecActionExceptionListener listener);
/**
* Action execution event
*/
public interface ActionEvent, S, E, C> extends SquirrelEvent {
Action getExecutionTarget();
S getFrom();
S getTo();
E getEvent();
C getContext();
T getStateMachine();
int[] getMOfN();
}
public interface BeforeExecActionEvent, S, E, C> extends ActionEvent {}
/**
* Before Action execution listener
*/
public interface BeforeExecActionListener, S, E, C> {
public static final String METHOD_NAME = "beforeExecute";
public static final Method METHOD = ReflectUtils.getMethod(
BeforeExecActionListener.class, METHOD_NAME, new Class>[]{BeforeExecActionEvent.class});
void beforeExecute(BeforeExecActionEvent event);
}
public interface AfterExecActionEvent, S, E, C> extends ActionEvent {}
/**
* After Action execution listener
*/
public interface AfterExecActionListener, S, E, C> {
public static final String METHOD_NAME = "afterExecute";
public static final Method METHOD = ReflectUtils.getMethod(
AfterExecActionListener.class, METHOD_NAME, new Class>[]{AfterExecActionEvent.class});
void afterExecute(AfterExecActionEvent event);
}
public interface ExecActionExceptionEvent, S, E, C> extends ActionEvent {
TransitionException getException();
}
public interface ExecActionExceptionListener, S, E, C> {
public static final String METHOD_NAME = "executeException";
public static final Method METHOD = ReflectUtils.getMethod(
ExecActionExceptionListener.class, METHOD_NAME,
new Class>[]{ExecActionExceptionEvent.class});
void executeException(ExecActionExceptionEvent event);
}
}