@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.shell.Bootstrap;
|
||||
import org.springframework.statemachine.StateContext;
|
||||
@@ -37,6 +38,8 @@ import org.springframework.statemachine.config.builders.StateMachineTransitionCo
|
||||
import org.springframework.statemachine.guard.Guard;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Configuration
|
||||
public class Application {
|
||||
|
||||
@@ -155,9 +158,15 @@ public class Application {
|
||||
if (ObjectUtils.nullSafeEquals(variables.get("T1"), true)
|
||||
&& ObjectUtils.nullSafeEquals(variables.get("T2"), true)
|
||||
&& ObjectUtils.nullSafeEquals(variables.get("T3"), true)) {
|
||||
context.getStateMachine().sendEvent(Events.CONTINUE);
|
||||
context.getStateMachine()
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(Events.CONTINUE).build()))
|
||||
.subscribe();
|
||||
} else {
|
||||
context.getStateMachine().sendEvent(Events.FALLBACK);
|
||||
context.getStateMachine()
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(Events.FALLBACK).build()))
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -173,7 +182,10 @@ public class Application {
|
||||
variables.put("T1", true);
|
||||
variables.put("T2", true);
|
||||
variables.put("T3", true);
|
||||
context.getStateMachine().sendEvent(Events.CONTINUE);
|
||||
context.getStateMachine()
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(Events.CONTINUE).build()))
|
||||
.subscribe();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package demo.tasks;
|
||||
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.shell.core.annotation.CliCommand;
|
||||
import org.springframework.shell.core.annotation.CliOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -22,14 +23,17 @@ import org.springframework.stereotype.Component;
|
||||
import demo.AbstractStateMachineCommands;
|
||||
import demo.tasks.Application.Events;
|
||||
import demo.tasks.Application.States;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
public class StateMachineCommands extends AbstractStateMachineCommands<States, Events> {
|
||||
|
||||
@CliCommand(value = "sm event", help = "Sends an event to a state machine")
|
||||
public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) {
|
||||
getStateMachine().sendEvent(event);
|
||||
getStateMachine()
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(event).build()))
|
||||
.subscribe();
|
||||
return "Event " + event + " send";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.statemachine.ExtendedState;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.statemachine.annotation.WithStateMachine;
|
||||
@@ -28,6 +29,7 @@ import org.springframework.statemachine.annotation.WithStateMachine;
|
||||
import demo.tasks.Application.Events;
|
||||
import demo.tasks.Application.States;
|
||||
import demo.tasks.Application.StatesOnTransition;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@WithStateMachine
|
||||
public class Tasks {
|
||||
@@ -46,14 +48,20 @@ public class Tasks {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
stateMachine.sendEvent(Events.RUN);
|
||||
stateMachine
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(Events.RUN).build()))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public void fix() {
|
||||
tasks.put("T1", true);
|
||||
tasks.put("T2", true);
|
||||
tasks.put("T3", true);
|
||||
stateMachine.sendEvent(Events.FIX);
|
||||
stateMachine
|
||||
.sendEvent(Mono.just(MessageBuilder
|
||||
.withPayload(Events.FIX).build()))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public void fail(String task) {
|
||||
|
||||
Reference in New Issue
Block a user