fix: 断路状态管理器逻辑异常.
This commit is contained in:
@@ -269,31 +269,24 @@ public abstract class AbstractStateMachine<S> extends AbstractStateManager<S> im
|
|||||||
* 触发
|
* 触发
|
||||||
*/
|
*/
|
||||||
private void doInvokeHandlers(List<StateHandlerWrapper<S>> handlerWrappers, S from, S to) {
|
private void doInvokeHandlers(List<StateHandlerWrapper<S>> handlerWrappers, S from, S to) {
|
||||||
if (handlerWrappers == null) {
|
if (handlerWrappers == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
// 全局的异步状态
|
|
||||||
final boolean isGlobalAsync = async != null && async;
|
|
||||||
|
|
||||||
handlerWrappers.forEach(hw -> {
|
handlerWrappers.forEach(hw -> {
|
||||||
final StateHandler<S> stateHandler;
|
final StateHandler<S> stateHandler;
|
||||||
if (hw == null ||
|
if (hw == null ||
|
||||||
(stateHandler = hw.getStateHandler()) == null) {
|
(stateHandler = hw.getStateHandler()) == null)
|
||||||
return;
|
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);
|
final StateHandlerProcessParams<S> params = new StateHandlerProcessParams<>(from, to, null);
|
||||||
|
if (hw.getAsync() == null ?
|
||||||
if (runInAsync) {
|
(this.async != null && this.async) :
|
||||||
if (executorToRun == null) {
|
hw.getAsync()) {
|
||||||
|
final Executor executor;
|
||||||
|
if ((executor = hw.getExecutor() == null ?
|
||||||
|
this.executor : hw.getExecutor()) == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
executor.execute(() -> stateHandler.handle(params));
|
||||||
executorToRun.execute(() -> stateHandler.handle(params));
|
} else
|
||||||
} else {
|
|
||||||
stateHandler.handle(params);
|
stateHandler.handle(params);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,11 @@ public final class BreakageUnidirectionalStateManager<S> extends DefaultUnidirec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean switchTo(S state) {
|
public boolean switchTo(S state) {
|
||||||
if (isLast()) {
|
/*
|
||||||
|
* 非最后一个状态且切换后的状态必须在当前状态的下位
|
||||||
|
*/
|
||||||
|
if (isLast() ||
|
||||||
|
indexOf(state) <= currentIndex()) {
|
||||||
if (allowThrow)
|
if (allowThrow)
|
||||||
throw new StateException("The last state has been reached and cannot be switched again!");
|
throw new StateException("The last state has been reached and cannot be switched again!");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user