0
ステートマシンは、choiceステート内の評価が次のステートに移動するのではなくfalseを返すとき、選択ステートで一時停止します。ステートマシンが一時停止する選択項目での誤った評価
以下のコード:
国定義:
@Override
public void configure(StateMachineStateConfigurer<String, String>
states) throws Exception {
states
.withStates()
.initial("init")
.choice("S1Choice")
.state("S1")
.choice("S2Choice")
.state("S2")
.choice("S3Choice")
.state("S3")
.state("end");
}
トランジション/選択/アクション:
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("init")
.target("S1Choice")
.event("start")
.and()
.withChoice()
.source("S1Choice")
.first("S1", new Guard<String, String>() {
public boolean evaluate(StateContext<String, String> context) {
System.out.println("In s1 choice");
/*Map<Object, Object> map = context.getExtendedState().getVariables();
return !map.containsKey("S1done");*/
return false;
}
})
.last("S2Choice")
.and()
.withLocal()
.source("S1")
.target("S2Choice")
.action(new Action<String, String>() {
public void execute(StateContext<String, String> context) {
Map<Object, Object> map = context.getExtendedState().getVariables();
System.out.println("Executing s1");
map.put("S1done", Boolean.TRUE);
}
})
.and()
.withChoice()
.source("S2Choice")
.first("S2", new Guard<String, String>() {
public boolean evaluate(StateContext<String, String> context) {
System.out.println("In s2 choice");
Map<Object, Object> map = context.getExtendedState().getVariables();
return !map.containsKey("S2done");
}
})
.last("S3Choice")
.and()
.withLocal()
.source("S2")
.target("S3Choice")
.action(new Action<String, String>() {
public void execute(StateContext<String, String> context) {
Map<Object, Object> map = context.getExtendedState().getVariables();
System.out.println("Executing s2");
map.put("S2done", Boolean.TRUE);
}
})
.and()
.withChoice()
.source("S3Choice")
.first("S3", new Guard<String, String>() {
public boolean evaluate(StateContext<String, String> context) {
System.out.println("In s3 choice");
Map<Object, Object> map = context.getExtendedState().getVariables();
return !map.containsKey("S3done");
}
})
.last("end")
.and()
.withLocal()
.source("S3")
.target("end")
.and()
.withLocal()
.source("end")
.target("init");
}
メインクラス:
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(TasksConfig.class);
StateMachine<String, String> stateMachine = context.getBean(StateMachine.class);
stateMachine.start();
stateMachine.getExtendedState().getVariables().put("S1done", Boolean.TRUE);
stateMachine.sendEvent("start");
//stateMachine.stop();
}
次はサンプルですouからTPUTキャプチャ:
作業項目の状態
INFOを初期化するために変更は:あなたが見ることができるようにS1の選択肢でのinit S3 S1Choice S3Choice S2Choice/initを/
をS2 S1の終了を開始しました新しい状態に移行するのではなく、 "s1 choice"という状態で停止します。 "s2 choice"。
はい。バージョンをアップグレードした後、正常に動作しています!ありがとう!! – ShankaraNarayanan