fix: 断路状态管理器逻辑异常.

This commit is contained in:
2025-01-14 15:40:29 +08:00
parent 2f407e4cea
commit c546f855e1
2 changed files with 15 additions and 18 deletions

View File

@@ -269,31 +269,24 @@ public abstract class AbstractStateMachine<S> extends AbstractStateManager<S> im
* 触发
*/
private void doInvokeHandlers(List<StateHandlerWrapper<S>> handlerWrappers, S from, S to) {
if (handlerWrappers == null) {
if (handlerWrappers == null)
return;
}
// 全局的异步状态
final boolean isGlobalAsync = async != null && async;
handlerWrappers.forEach(hw -> {
final StateHandler<S> stateHandler;
if (hw == null ||
(stateHandler = hw.getStateHandler()) == null) {
(stateHandler = hw.getStateHandler()) == null)
return;
}
final Executor executorToRun = hw.getExecutor() == null ? executor : hw.getExecutor();
final boolean runInAsync = hw.getAsync() == null ? isGlobalAsync : hw.getAsync();
final StateHandlerProcessParams<S> params = new StateHandlerProcessParams<>(from, to, null);
if (runInAsync) {
if (executorToRun == null) {
if (hw.getAsync() == null ?
(this.async != null && this.async) :
hw.getAsync()) {
final Executor executor;
if ((executor = hw.getExecutor() == null ?
this.executor : hw.getExecutor()) == null)
throw new NullPointerException();
}
executorToRun.execute(() -> stateHandler.handle(params));
} else {
executor.execute(() -> stateHandler.handle(params));
} else
stateHandler.handle(params);
}
});
}
}

View File

@@ -70,7 +70,11 @@ public final class BreakageUnidirectionalStateManager<S> extends DefaultUnidirec
@Override
public boolean switchTo(S state) {
if (isLast()) {
/*
* 非最后一个状态且切换后的状态必须在当前状态的下位
*/
if (isLast() ||
indexOf(state) <= currentIndex()) {
if (allowThrow)
throw new StateException("The last state has been reached and cannot be switched again!");
return false;