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

cn.org.atool.fluentmachine.StateMachine Maven / Gradle / Ivy

There is a newer version: 0.3.3
Show newest version
package cn.org.atool.fluentmachine;

import cn.org.atool.fluentmachine.context.Context;

import java.util.function.Supplier;

/**
 * StateMachine: 状态机定义
 *
 * @param  状态
 * @param  事件
 * @param  上下文
 * @author darui.wu
 */
public interface StateMachine {

    /**
     * 返回状态机标识
     *
     * @return
     */
    String getMachineId();

    /**
     * 触发初始事件执行
     *
     * @param ctx
     */
    S start(Context ctx);

    /**
     * 在节点source上触发事件event执行
     *
     * @param source 源节点
     * @param ctx    上下文
     * @param event  事件
     * @return 目标节点
     */
    S fire(S source, Context ctx, E event);

    /**
     * 从上下文持久化实例中获取tradeNo的上下文, 并触发事件event
     *
     * @param tradeNo 业务单号
     * @param events  事件列表
     * @return 触发执行后的目标状态
     */
    S fire(String tradeNo, E... events);

    /**
     * 执行完动作event预处理动作列表后, 触发事件event
     * 

* 执行的动作列表不改变上下文保存的状态 * * @param tradeNo 状态机中唯一的业务id * @param event 要触发的事件 * @param supplier 外部提供的message * @return */ S fireByPretreatment(String tradeNo, E event, Supplier supplier); /** * 执行完动作event预处理动作列表后, 触发事件event *

* 执行的动作列表不改变上下文保存的状态 * * @param tradeNo 状态机中唯一的业务id * @param event 要触发的事件 * @param message 外部提供的message * @return */ default S fireByPretreatment(String tradeNo, E event, Object message) { return this.fireByPretreatment(tradeNo, event, () -> message); } /** * 触发上下文自动事件 * * @param tradeNo 业务单号 * @return */ S fireAutoEvents(String tradeNo); /** * 输出状态机plant uml流程图 * * @return */ String plantUml(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy