diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java index ef9ab233..ad3c76e8 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java @@ -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. @@ -35,6 +35,8 @@ import org.springframework.statemachine.config.builders.StateMachineStateConfigu import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; import org.springframework.statemachine.guard.Guard; +import reactor.core.publisher.Mono; + @Configuration public class Application { @@ -214,7 +216,10 @@ public class Application { && context.getEvent() == Events.PLAY && context.getTransition().getTarget().getId() == States.CLOSED && context.getExtendedState().getVariables().get(Variables.CD) != null) { - context.getStateMachine().sendEvent(Events.PLAY); + context.getStateMachine() + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.PLAY).build())) + .subscribe(); } } } @@ -265,9 +270,11 @@ public class Application { if (elapsed instanceof Long) { long e = ((Long)elapsed) + 1000l; if (e > ((Cd) cd).getTracks()[((Integer) track)].getLength()*1000) { - context.getStateMachine().sendEvent(MessageBuilder + context.getStateMachine() + .sendEvent(Mono.just(MessageBuilder .withPayload(Events.FORWARD) - .setHeader(Headers.TRACKSHIFT.toString(), 1).build()); + .setHeader(Headers.TRACKSHIFT.toString(), 1).build())) + .subscribe(); } else { variables.put(Variables.ELAPSEDTIME, e); } @@ -291,7 +298,10 @@ public class Application { variables.put(Variables.ELAPSEDTIME, 0l); variables.put(Variables.TRACK, next); } else if (((Cd)cd).getTracks().length <= next) { - context.getStateMachine().sendEvent(Events.STOP); + context.getStateMachine() + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.STOP).build())) + .subscribe(); } } } diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayer.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayer.java index 56e57db1..f1d13a38 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayer.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayer.java @@ -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. @@ -30,6 +30,7 @@ import demo.cdplayer.Application.Headers; import demo.cdplayer.Application.States; import demo.cdplayer.Application.StatesOnTransition; import demo.cdplayer.Application.Variables; +import reactor.core.publisher.Mono; @WithStateMachine public class CdPlayer { @@ -41,37 +42,54 @@ public class CdPlayer { private String trackStatus = ""; public void load(Cd cd) { - stateMachine.sendEvent(MessageBuilder.withPayload(Events.LOAD).setHeader(Variables.CD.toString(), cd).build()); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.LOAD).setHeader(Variables.CD.toString(), cd).build())) + .subscribe(); } public void play() { - stateMachine.sendEvent(Events.PLAY); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.PLAY).build())) + .subscribe(); } public void stop() { - stateMachine.sendEvent(Events.STOP); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.STOP).build())) + .subscribe(); } public void pause() { - stateMachine.sendEvent(Events.PAUSE); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.PAUSE).build())) + .subscribe(); } public void eject() { - stateMachine.sendEvent(Events.EJECT); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.EJECT).build())) + .subscribe(); } public void forward() { stateMachine - .sendEvent(MessageBuilder - .withPayload(Events.FORWARD) - .setHeader(Headers.TRACKSHIFT.toString(), 1).build()); + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.FORWARD) + .setHeader(Headers.TRACKSHIFT.toString(), 1).build())) + .subscribe(); } public void back() { stateMachine - .sendEvent(MessageBuilder - .withPayload(Events.BACK) - .setHeader(Headers.TRACKSHIFT.toString(), -1).build()); + .sendEvent(Mono.just(MessageBuilder + .withPayload(Events.BACK) + .setHeader(Headers.TRACKSHIFT.toString(), -1).build())) + .subscribe(); } public String getLdcStatus() { diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java index 34c3f1ee..22293054 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java @@ -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.cdplayer; +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.cdplayer.Application.Events; import demo.cdplayer.Application.States; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @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"; } - -} \ No newline at end of file +} diff --git a/spring-statemachine-samples/datajpa/src/main/java/demo/datajpa/StateMachineController.java b/spring-statemachine-samples/datajpa/src/main/java/demo/datajpa/StateMachineController.java index 55d67303..c31de6c9 100644 --- a/spring-statemachine-samples/datajpa/src/main/java/demo/datajpa/StateMachineController.java +++ b/spring-statemachine-samples/datajpa/src/main/java/demo/datajpa/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.config.StateMachineFactory; import org.springframework.statemachine.data.RepositoryTransition; @@ -28,6 +29,8 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import reactor.core.publisher.Mono; + @Controller public class StateMachineController { @@ -48,13 +51,16 @@ public class StateMachineController { StateMachine stateMachine = stateMachineFactory.getStateMachine(); StateMachineLogListener listener = new StateMachineLogListener(); stateMachine.addStateListener(listener); - stateMachine.start(); + stateMachine.startReactively().block(); if (events != null) { for (String event : events) { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } } - stateMachine.stop(); + stateMachine.stopReactively().block(); model.addAttribute("allEvents", getEvents()); model.addAttribute("messages", createMessages(listener.getMessages())); return "states"; diff --git a/spring-statemachine-samples/datajpamultipersist/src/main/java/demo/datajpamultipersist/StateMachineController.java b/spring-statemachine-samples/datajpamultipersist/src/main/java/demo/datajpamultipersist/StateMachineController.java index d480a012..06e8c142 100644 --- a/spring-statemachine-samples/datajpamultipersist/src/main/java/demo/datajpamultipersist/StateMachineController.java +++ b/spring-statemachine-samples/datajpamultipersist/src/main/java/demo/datajpamultipersist/StateMachineController.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.StateMachinePersist; @@ -31,6 +32,8 @@ import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import reactor.core.publisher.Mono; + @Controller public class StateMachineController { @@ -67,7 +70,10 @@ public class StateMachineController { StateMachine stateMachine = getStateMachine(machine); if (events != null) { for (String event : events) { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } } @@ -104,13 +110,13 @@ public class StateMachineController { if (currentStateMachine == null) { currentStateMachine = stateMachineService.acquireStateMachine(machineId, false); currentStateMachine.addStateListener(listener); - currentStateMachine.start(); + currentStateMachine.startReactively().block(); } else if (!ObjectUtils.nullSafeEquals(currentStateMachine.getId(), machineId)) { stateMachineService.releaseStateMachine(currentStateMachine.getId()); - currentStateMachine.stop(); + currentStateMachine.stopReactively().block(); currentStateMachine = stateMachineService.acquireStateMachine(machineId, false); currentStateMachine.addStateListener(listener); - currentStateMachine.start(); + currentStateMachine.startReactively().block(); } return currentStateMachine; } diff --git a/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineController.java b/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineController.java index 55c6fe94..999a88a1 100644 --- a/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineController.java +++ b/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-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. @@ -19,6 +19,7 @@ import java.util.EnumSet; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.StateMachinePersist; @@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestParam; import demo.datapersist.StateMachineConfig.Events; import demo.datapersist.StateMachineConfig.States; +import reactor.core.publisher.Mono; @Controller public class StateMachineController { @@ -61,7 +63,10 @@ public class StateMachineController { StateMachine stateMachine = getStateMachine(machine); if (events != null) { for (Events event : events) { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } } StateMachineContext stateMachineContext = stateMachinePersist.read(machine); @@ -79,13 +84,13 @@ public class StateMachineController { if (currentStateMachine == null) { currentStateMachine = stateMachineService.acquireStateMachine(machineId); currentStateMachine.addStateListener(listener); - currentStateMachine.start(); + currentStateMachine.startReactively().block(); } else if (!ObjectUtils.nullSafeEquals(currentStateMachine.getId(), machineId)) { stateMachineService.releaseStateMachine(currentStateMachine.getId()); - currentStateMachine.stop(); + currentStateMachine.stopReactively().block(); currentStateMachine = stateMachineService.acquireStateMachine(machineId); currentStateMachine.addStateListener(listener); - currentStateMachine.start(); + currentStateMachine.startReactively().block(); } return currentStateMachine; } diff --git a/spring-statemachine-samples/deploy/src/main/java/demo/deploy/StateMachineController.java b/spring-statemachine-samples/deploy/src/main/java/demo/deploy/StateMachineController.java index 375591c5..b6866e39 100644 --- a/spring-statemachine-samples/deploy/src/main/java/demo/deploy/StateMachineController.java +++ b/spring-statemachine-samples/deploy/src/main/java/demo/deploy/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -29,6 +29,8 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import reactor.core.publisher.Mono; + @Controller public class StateMachineController { @@ -59,7 +61,10 @@ public class StateMachineController { } } listener.resetMessages(); - stateMachine.sendEvent(MessageBuilder.createMessage(event, new MessageHeaders(headers))); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .createMessage(event, new MessageHeaders(headers)))) + .blockLast(); } model.addAttribute("states", stateMachine.getState().getIds()); model.addAttribute("messages", listener.getMessages()); diff --git a/spring-statemachine-samples/eventservice/src/main/java/demo/eventservice/StateMachineController.java b/spring-statemachine-samples/eventservice/src/main/java/demo/eventservice/StateMachineController.java index 13bf40e6..86041ce3 100644 --- a/spring-statemachine-samples/eventservice/src/main/java/demo/eventservice/StateMachineController.java +++ b/spring-statemachine-samples/eventservice/src/main/java/demo/eventservice/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -17,6 +17,7 @@ package demo.eventservice; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.persist.StateMachinePersister; import org.springframework.stereotype.Controller; @@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import demo.eventservice.StateMachineConfig.Events; import demo.eventservice.StateMachineConfig.States; +import reactor.core.publisher.Mono; @Controller public class StateMachineController { @@ -85,7 +87,10 @@ public class StateMachineController { //tag::snippetD[] private void feedMachine(String user, Events id) throws Exception { - stateMachine.sendEvent(id); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(id).build())) + .blockLast(); stateMachinePersister.persist(stateMachine, "testprefix:" + user); } //end::snippetD[] diff --git a/spring-statemachine-samples/monitoring/src/main/java/demo/monitoring/StateMachineController.java b/spring-statemachine-samples/monitoring/src/main/java/demo/monitoring/StateMachineController.java index 11aa7c35..d5854bac 100644 --- a/spring-statemachine-samples/monitoring/src/main/java/demo/monitoring/StateMachineController.java +++ b/spring-statemachine-samples/monitoring/src/main/java/demo/monitoring/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -18,12 +18,15 @@ package demo.monitoring; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import reactor.core.publisher.Mono; + @Controller public class StateMachineController { @@ -39,13 +42,16 @@ public class StateMachineController { public String feedAndGetStates(@RequestParam(value = "events", required = false) List events, Model model) throws Exception { StateMachineLogListener listener = new StateMachineLogListener(); stateMachine.addStateListener(listener); - stateMachine.start(); + stateMachine.startReactively().block(); if (events != null) { for (String event : events) { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } } - stateMachine.stop(); + stateMachine.stopReactively().block(); model.addAttribute("allEvents", new String[]{"E1", "E2"}); model.addAttribute("messages", createMessages(listener.getMessages())); return "states"; diff --git a/spring-statemachine-samples/ordershipping/src/main/java/demo/ordershipping/StateMachineController.java b/spring-statemachine-samples/ordershipping/src/main/java/demo/ordershipping/StateMachineController.java index 8cea063f..60cc7bac 100644 --- a/spring-statemachine-samples/ordershipping/src/main/java/demo/ordershipping/StateMachineController.java +++ b/spring-statemachine-samples/ordershipping/src/main/java/demo/ordershipping/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-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. @@ -31,6 +31,8 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import reactor.core.publisher.Mono; + @Controller public class StateMachineController { @@ -82,7 +84,10 @@ public class StateMachineController { headers.put("payment", true); } } - stateMachine.sendEvent(MessageBuilder.createMessage(event, new MessageHeaders(headers))); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .createMessage(event, new MessageHeaders(headers)))) + .blockLast(); } model.addAttribute("allIds", machines.keySet()); diff --git a/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java b/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java index afb75d2b..04416bcd 100644 --- a/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java +++ b/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java @@ -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,19 +15,23 @@ */ package demo.persist; +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; import demo.AbstractStateMachineCommands; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @CliCommand(value = "sm event", help = "Sends an event to a state machine") public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final String event) { - getStateMachine().sendEvent(event); + getStateMachine() + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .subscribe(); return "Event " + event + " send"; } - -} \ No newline at end of file +} diff --git a/spring-statemachine-samples/scope/src/main/java/demo/scope/StateMachineController.java b/spring-statemachine-samples/scope/src/main/java/demo/scope/StateMachineController.java index 04e38632..d1c81b5e 100644 --- a/spring-statemachine-samples/scope/src/main/java/demo/scope/StateMachineController.java +++ b/spring-statemachine-samples/scope/src/main/java/demo/scope/StateMachineController.java @@ -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. @@ -17,6 +17,7 @@ package demo.scope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam; import demo.scope.StateMachineConfig.Events; import demo.scope.StateMachineConfig.States; +import reactor.core.publisher.Mono; @Controller public class StateMachineController { @@ -44,7 +46,10 @@ public class StateMachineController { @RequestMapping("/states") public String getStates(@RequestParam(value = "event", required = false) Events event, Model model) { if (event != null) { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } model.addAttribute("states", stateMachine.getState().getIds()); model.addAttribute("stateChartModel", stateChartModel); diff --git a/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineController.java b/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineController.java index 25ff057b..9b275835 100644 --- a/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineController.java +++ b/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineController.java @@ -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. @@ -19,6 +19,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestParam; import demo.security.StateMachineConfig.Events; import demo.security.StateMachineConfig.States; +import reactor.core.publisher.Mono; @Controller public class StateMachineController { @@ -49,7 +51,10 @@ public class StateMachineController { public String getStates(@RequestParam(value = "event", required = false) Events event, Model model) { if (event != null) { try { - stateMachine.sendEvent(event); + stateMachine + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .blockLast(); } catch (Exception e) { log.error("Error sendEvent", e); } diff --git a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java index 391bd611..74121c0a 100644 --- a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java +++ b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java @@ -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.showcase; +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.showcase.Application.Events; import demo.showcase.Application.States; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @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"; } - -} \ No newline at end of file +} diff --git a/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java b/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java index 25bb29d1..fb2dd674 100644 --- a/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java +++ b/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java @@ -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. @@ -54,13 +54,13 @@ public class AbstractStateMachineCommands implements CommandMarker { @CliCommand(value = "sm start", help = "Start a state machine") public String start() { - stateMachine.start(); + stateMachine.startReactively().subscribe(); return "State machine started"; } @CliCommand(value = "sm stop", help = "Stop a state machine") public String stop() { - stateMachine.stop(); + stateMachine.stopReactively().subscribe(); return "State machine stopped"; } diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java index 5db1760e..842a9bec 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java @@ -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(); } }; } diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java index 037a5aa2..2333458c 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java @@ -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 { @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"; } - -} \ No newline at end of file +} diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Tasks.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Tasks.java index 9770b4bc..4f9bc202 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Tasks.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Tasks.java @@ -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) { diff --git a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java index ef642dcc..6779c3cd 100644 --- a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java +++ b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java @@ -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.turnstile; +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.turnstile.Application.Events; import demo.turnstile.Application.States; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @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"; } - -} \ No newline at end of file +} diff --git a/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java b/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java index 783e366f..c0dc1d60 100644 --- a/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java +++ b/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java @@ -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.washer; +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,13 +23,17 @@ import org.springframework.stereotype.Component; import demo.AbstractStateMachineCommands; import demo.washer.Application.Events; import demo.washer.Application.States; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @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"; } diff --git a/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java b/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java index 362578bc..cacf99f4 100644 --- a/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java +++ b/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 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. @@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import demo.web.StateMachineConfig.Events; import demo.web.StateMachineConfig.States; +import reactor.core.publisher.Mono; @Controller public class StateMachineController { @@ -154,7 +155,7 @@ public class StateMachineController { .withPayload(id) .setHeader("testVariable", testVariable) .build(); - stateMachine.sendEvent(message); + stateMachine.sendEvent(Mono.just(message)).subscribe(); } @RequestMapping("/join") diff --git a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java index dc689341..2e2dce6e 100644 --- a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java +++ b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java @@ -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,19 +15,23 @@ */ package demo.zookeeper; +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; import demo.AbstractStateMachineCommands; +import reactor.core.publisher.Mono; @Component public class StateMachineCommands extends AbstractStateMachineCommands { @CliCommand(value = "sm event", help = "Sends an event to a state machine") public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final String event) { - getStateMachine().sendEvent(event); + getStateMachine() + .sendEvent(Mono.just(MessageBuilder + .withPayload(event).build())) + .subscribe(); return "Event " + event + " send"; } - -} \ No newline at end of file +}