Docs changes
- Add some notes for threading and wipe out TaskExecutor and TaskScheduler from docs. - Some notes about replacement with reactor. - Relates #742
This commit is contained in:
@@ -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 <<statemachine-config-commonsettings>>.
|
||||
@@ -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[]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<States, Events>())
|
||||
.transitionConflictPolicy(TransitionConflictPolicy.CHILD);
|
||||
.transitionConflictPolicy(TransitionConflictPolicy.CHILD)
|
||||
.regionExecutionPolicy(RegionExecutionPolicy.PARALLEL);
|
||||
}
|
||||
}
|
||||
// end::snippetYA[]
|
||||
|
||||
Reference in New Issue
Block a user