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.builder.StateMachineBuilder.externalParallelTransition 2.测试方法:com.alibaba.cola.test.StateMachineTest.testParallel
- Loading branch information
huangweilong
committed
Apr 18, 2024
1 parent
22f6367
commit e0b79c0
Showing
12 changed files
with
206 additions
and
0 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
27 changes: 27 additions & 0 deletions
27
...rc/main/java/com/alibaba/cola/statemachine/builder/AbstractParallelTransitionBuilder.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,27 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
import com.alibaba.cola.statemachine.State; | ||
import com.alibaba.cola.statemachine.impl.StateHelper; | ||
import com.alibaba.cola.statemachine.impl.TransitionType; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
abstract class AbstractParallelTransitionBuilder<S,E,C> implements ParallelFrom<S,E,C>,On<S,E,C>,To<S,E,C>{ | ||
|
||
final Map<S, State<S, E, C>> stateMap; | ||
|
||
protected List<State<S, E, C>> targets; | ||
|
||
final TransitionType transitionType; | ||
|
||
public AbstractParallelTransitionBuilder(Map<S, State<S, E, C>> stateMap, TransitionType transitionType) { | ||
this.stateMap = stateMap; | ||
this.transitionType = transitionType; | ||
} | ||
@Override | ||
public To<S, E, C> toAmong(S ... stateIds) { | ||
targets = StateHelper.getStates(stateMap, stateIds); | ||
return this; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...rc/main/java/com/alibaba/cola/statemachine/builder/ExternalParallelTransitionBuilder.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.builder; | ||
|
||
|
||
public interface ExternalParallelTransitionBuilder<S, E, C> { | ||
/** | ||
* Build transition source state. | ||
* @param stateId id of state | ||
* @return from clause builder | ||
*/ | ||
ParallelFrom<S, E, C> from(S stateId); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ponent-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/ParallelFrom.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.builder; | ||
|
||
|
||
public interface ParallelFrom<S, E, C> { | ||
/** | ||
* Build transition target state and return to clause builder | ||
* @param stateIds id of state | ||
* @return To clause builder | ||
*/ | ||
To<S, E, C> toAmong(S ... stateIds); | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...ne/src/main/java/com/alibaba/cola/statemachine/builder/ParallelTransitionBuilderImpl.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,51 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
import com.alibaba.cola.statemachine.Action; | ||
import com.alibaba.cola.statemachine.Condition; | ||
import com.alibaba.cola.statemachine.State; | ||
import com.alibaba.cola.statemachine.Transition; | ||
import com.alibaba.cola.statemachine.impl.StateHelper; | ||
import com.alibaba.cola.statemachine.impl.TransitionType; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
class ParallelTransitionBuilderImpl<S,E,C> extends AbstractParallelTransitionBuilder<S,E,C> implements ExternalParallelTransitionBuilder<S,E,C> { | ||
|
||
|
||
private State<S, E, C> source; | ||
private List<Transition<S, E, C>> transitions; | ||
|
||
public ParallelTransitionBuilderImpl(Map<S, State<S, E, C>> stateMap, TransitionType transitionType) { | ||
super(stateMap, transitionType); | ||
} | ||
|
||
@Override | ||
public ParallelFrom<S, E, C> from(S stateId) { | ||
source = StateHelper.getState(stateMap, stateId); | ||
return this; | ||
} | ||
|
||
@Override | ||
public When<S, E, C> when(Condition<C> condition) { | ||
for (Transition<S, E, C> transition : transitions) { | ||
transition.setCondition(condition); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public On<S, E, C> on(E event) { | ||
transitions = source.addTransitions(event, targets, transitionType); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void perform(Action<S, E, C> action) { | ||
for (Transition<S, E, C> transition : transitions) { | ||
transition.setAction(action); | ||
} | ||
} | ||
|
||
|
||
} |
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
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
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