diff --git a/docs/src/reference/asciidoc/appendix-reactormigration-threading.adoc b/docs/src/reference/asciidoc/appendix-reactormigration-threading.adoc new file mode 100644 index 00000000..5bfd034f --- /dev/null +++ b/docs/src/reference/asciidoc/appendix-reactormigration-threading.adoc @@ -0,0 +1,4 @@ +=== TaskExecutor and TaskScheduler +StateMachine execution with `TaskExecutor` and state action scheduling with `TaskScheduler` +has been fully replaced in favour or Reactor execution and scheduling. For configuring +parallel region execution see <>. diff --git a/docs/src/reference/asciidoc/appendix-reactormigration.adoc b/docs/src/reference/asciidoc/appendix-reactormigration.adoc index 013941b9..1f950d56 100644 --- a/docs/src/reference/asciidoc/appendix-reactormigration.adoc +++ b/docs/src/reference/asciidoc/appendix-reactormigration.adoc @@ -8,3 +8,5 @@ has been moved over to handled by a reactor. Essentially what this means is that is considerably different compared to `2.x`. Following chapters go throught all these changes. include::appendix-reactormigration-communicating.adoc[] + +include::appendix-reactormigration-threading.adoc[] diff --git a/docs/src/reference/asciidoc/recipes.adoc b/docs/src/reference/asciidoc/recipes.adoc index 307b128d..59f31ca8 100644 --- a/docs/src/reference/asciidoc/recipes.adoc +++ b/docs/src/reference/asciidoc/recipes.adoc @@ -68,8 +68,8 @@ errors manually. `TasksHandler` contains a builder method to configure a handler instance and follows a simple builder pattern. You can use this builder to -register `Runnable` tasks and `TasksListener` instances, define -`StateMachinePersist` hook, and set up custom `TaskExecutor` instance. +register `Runnable` tasks and `TasksListener` instances and define +`StateMachinePersist` hook. Now we can take a simple `Runnable` that runs a simple sleep as the following example shows: diff --git a/docs/src/reference/asciidoc/sm-config.adoc b/docs/src/reference/asciidoc/sm-config.adoc index 8923bce7..b78ba877 100644 --- a/docs/src/reference/asciidoc/sm-config.adoc +++ b/docs/src/reference/asciidoc/sm-config.adoc @@ -199,9 +199,8 @@ actions, because execution happens after state has been entered and can be cancelled if state exit happens before a particular action has been completed. -State actions are run by using a normal Spring `TaskScheduler` -wrapped within a `Runnable` that can get cancelled through -`ScheduledFuture`. This means that, whatever you do in your +State actions are executed using normal reactive flow by subscribing with +a Reactor's default parallel scheduler. This means that, whatever you do in your action, you need to be able to catch `InterruptedException` or, more generally, periodically check whether `Thread` is interrupted. @@ -478,9 +477,9 @@ exit and entry respectively. === Configuring Common Settings You can set part of a common state machine configuration by using -`ConfigurationConfigurer`. This you set set `BeanFactory`, -`TaskExecutor`, `TaskScheduler`, and an autostart flag for a state machine≄ -It also lets you register `StateMachineListener` instances. +`ConfigurationConfigurer`. With it you can set `BeanFactory` and an autostart flag +for a state machine. It also lets you register `StateMachineListener` instances, +configure transition conflict policy and region execution policy. The following example shows how to use `ConfigurationConfigurer`: ==== @@ -500,9 +499,6 @@ top-level state machine. Setting `machineId` within a configuration class is simply a convenience for those times when you want or need to do it there. -Setting a `BeanFactory`, `TaskExecutor`, or `TaskScheduler` is another -convenience for you, and those settings are also used within the framework itself. - Registering `StateMachineListener` instances is also partly for convenience but is required if you want to catch a callback during a state machine lifecycle, such as getting notified of a state machine's diff --git a/docs/src/reference/asciidoc/sm-factories.adoc b/docs/src/reference/asciidoc/sm-factories.adoc index 01a3360b..86a0377a 100644 --- a/docs/src/reference/asciidoc/sm-factories.adoc +++ b/docs/src/reference/asciidoc/sm-factories.adoc @@ -88,10 +88,8 @@ include::samples/DocsConfigurationSampleTests.java[tags=snippetFC] You need to understand when common configuration needs to be used with machines instantiated from a builder. You can use a configurer -returned from a `withConfiguration()` to setup `autoStart`, -`TaskScheduler`, `TaskExecutor`, and `BeanFactory`. You can also use one to register -a `StateMachineListener`. If a `StateMachine` instance returned from -a builder is registered as a bean by using `@Bean`, `BeanFactory` -is attached automatically and you can find the default `TaskExecutor` -from there. If you use instances outside of a spring application context, +returned from a `withConfiguration()` to setup `autoStart` and `BeanFactory`. +You can also use one to register a `StateMachineListener`. If a `StateMachine` +instance returned from a builder is registered as a bean by using `@Bean`, `BeanFactory` +is attached automatically. If you use instances outside of a spring application context, you must use these methods to set up the needed facilities. diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests.java index ff019268..9d4f3774 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests.java @@ -55,6 +55,7 @@ import org.springframework.statemachine.event.OnStateMachineError; import org.springframework.statemachine.event.StateMachineEvent; import org.springframework.statemachine.guard.Guard; import org.springframework.statemachine.listener.StateMachineListenerAdapter; +import org.springframework.statemachine.region.RegionExecutionPolicy; import org.springframework.statemachine.state.State; import org.springframework.statemachine.support.StateMachineInterceptor; import org.springframework.statemachine.support.StateMachineInterceptorAdapter; @@ -1190,7 +1191,8 @@ public class DocsConfigurationSampleTests extends AbstractStateMachineTests { .machineId("myMachineId") .beanFactory(new StaticListableBeanFactory()) .listener(new StateMachineListenerAdapter()) - .transitionConflictPolicy(TransitionConflictPolicy.CHILD); + .transitionConflictPolicy(TransitionConflictPolicy.CHILD) + .regionExecutionPolicy(RegionExecutionPolicy.PARALLEL); } } // end::snippetYA[]