forked from alibaba/COLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 增加com.alibaba.cola.statemachine.StateMachine#verify方法 用来判断当前状态能否响应某个事件 2. 增加com.alibaba.cola.statemachine.builder.StateMachineBuilder#setFailoverCallback 用来增加在状态流转没有命中当前配置的规则时执行的回调 接口定义 com.alibaba.cola.statemachine.builder.FailoverCallback 默认为NumbFailoverCallbackImpl,与当前行为一样,什么都不做。 另外内置AlertFailoverCallbackImpl,用于抛出异常TransitionFailoverException
- Loading branch information
Showing
10 changed files
with
215 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...achine/src/main/java/com/alibaba/cola/statemachine/builder/AlertFailoverCallbackImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
import com.alibaba.cola.statemachine.exception.TransitionFailoverException; | ||
|
||
/** | ||
* Default failover callback, do nothing. | ||
* | ||
* @author 龙也 | ||
* @date 2022/9/15 12:02 PM | ||
*/ | ||
public class AlertFailoverCallbackImpl<S, E, C> implements FailoverCallback<S, E, C> { | ||
|
||
@Override | ||
public void onFailover(S sourceState, E event, C context) { | ||
throw new TransitionFailoverException( | ||
"Cannot fire event [" + event + "] on current state [" + sourceState + "] with context [" + context + "]"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...nt-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/FailoverCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
/** | ||
* @author 龙也 | ||
* @date 2022/9/15 12:02 PM | ||
*/ | ||
@FunctionalInterface | ||
public interface FailoverCallback<S, E, C> { | ||
|
||
/** | ||
* Callback function to execute on failover | ||
* | ||
* @param sourceState | ||
* @param event | ||
* @param context | ||
*/ | ||
void onFailover(S sourceState, E event, C context); | ||
} |
15 changes: 15 additions & 0 deletions
15
...machine/src/main/java/com/alibaba/cola/statemachine/builder/NumbFailoverCallbackImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
/** | ||
* Default failover callback, do nothing. | ||
* | ||
* @author 龙也 | ||
* @date 2022/9/15 12:02 PM | ||
*/ | ||
public class NumbFailoverCallbackImpl<S, E, C> implements FailoverCallback<S, E, C> { | ||
|
||
@Override | ||
public void onFailover(S sourceState, E event, C context) { | ||
//do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ne/src/main/java/com/alibaba/cola/statemachine/exception/TransitionFailoverException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.alibaba.cola.statemachine.exception; | ||
|
||
/** | ||
* @author 龙也 | ||
* @date 2022/9/15 12:08 PM | ||
*/ | ||
public class TransitionFailoverException extends RuntimeException { | ||
|
||
public TransitionFailoverException(String errMsg) { | ||
super(errMsg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.