init: 仓库初始化.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.serliunx.statemanagement.machine.handler;
|
||||
|
||||
/**
|
||||
* 状态处理器
|
||||
* <p>
|
||||
* 定义状态进入、离开及切换时执行的逻辑
|
||||
*
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface StateHandler<S> {
|
||||
|
||||
/**
|
||||
* 处理
|
||||
*
|
||||
* @param params 参数
|
||||
*/
|
||||
void handle(StateHandlerProcessParams<S> params);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.serliunx.statemanagement.machine.handler;
|
||||
|
||||
import com.serliunx.statemanagement.manager.BidirectionalStateManager;
|
||||
|
||||
/**
|
||||
* 状态处理器入参
|
||||
* <p>
|
||||
* 用于状态机处理事件
|
||||
*
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public final class StateHandlerProcessParams<S> {
|
||||
|
||||
/**
|
||||
* 源状态
|
||||
*/
|
||||
private final S from;
|
||||
/**
|
||||
* 目标状态
|
||||
*/
|
||||
private final S to;
|
||||
/**
|
||||
* 附加参数
|
||||
*/
|
||||
private final Object attach;
|
||||
|
||||
/**
|
||||
* @param from 原状态
|
||||
* @param to 目标状态
|
||||
* @param attach 附加参数
|
||||
* @param bidirectionalStateManager 状态机内置的状态管理器
|
||||
*/
|
||||
public StateHandlerProcessParams(S from, S to, Object attach) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
public S getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public S getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public Object getAttach() {
|
||||
return attach;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.serliunx.statemanagement.machine.handler;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
public class StateHandlerRegistry {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.serliunx.statemanagement.machine.handler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* 处理器封装
|
||||
* <p>
|
||||
* 用于添加处理器时设置处理器的行为
|
||||
*
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public final class StateHandlerWrapper<S> {
|
||||
|
||||
/**
|
||||
* 状态处理器
|
||||
*/
|
||||
private final StateHandler<S> stateHandler;
|
||||
/**
|
||||
* 执行器
|
||||
* <li> 用于异步执行处理逻辑
|
||||
*/
|
||||
private final Executor executor;
|
||||
/**
|
||||
* 是否异步执行
|
||||
*/
|
||||
private final Boolean async;
|
||||
|
||||
/**
|
||||
* @param stateHandler 状态处理器
|
||||
* @param executor 执行器
|
||||
* @param async 是否异步执行
|
||||
*/
|
||||
public StateHandlerWrapper(StateHandler<S> stateHandler, Executor executor, Boolean async) {
|
||||
this.stateHandler = stateHandler;
|
||||
this.executor = executor;
|
||||
this.async = async;
|
||||
}
|
||||
|
||||
public StateHandler<S> getStateHandler() {
|
||||
return stateHandler;
|
||||
}
|
||||
|
||||
public Executor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public Boolean getAsync() {
|
||||
return async;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user