All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.squirrelframework.foundation.fsm.ActionExecutionService Maven / Gradle / Ivy

Go to download

foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation.

There is a newer version: 0.3.10
Show newest version
package org.squirrelframework.foundation.fsm;

import java.lang.reflect.Method;

import org.squirrelframework.foundation.component.Observable;
import org.squirrelframework.foundation.event.SquirrelEvent;
import org.squirrelframework.foundation.exception.TransitionException;
import org.squirrelframework.foundation.util.ReflectUtils;

/**
 * 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 stack.
	 */
	void begin();
	
	/**
	 * Execute all the actions collected on the top of stack.
	 */
	void execute();
	
	/**
	 * 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 action execution listener which can be used for monitoring execution
	 * @param listener action execution listener
	 */
	void addExecActionListener(ExecActionListener listener);
	
	/**
	 * Remove action execution listener
	 * @param listener action execution listener
	 */
	void removeExecActionListener(ExecActionListener 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 ExecActionEvent, S, E, C> extends ActionEvent {}
	
	/**
	 * Action execution listener
	 */
	public interface ExecActionListener, S, E, C> {
	    public static final String METHOD_NAME = "beforeExecute";
	    public static final Method METHOD = ReflectUtils.getMethod(
	            ExecActionListener.class, METHOD_NAME, new Class[]{ExecActionEvent.class});
		void beforeExecute(ExecActionEvent 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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy