Skip to content

Commit ec951b5

Browse files
committed
Update reactive docs
- Relates spring-projects#742
1 parent de9de85 commit ec951b5

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== Reactive Examples
2+
While most of an examples are still same, we've overhauled some of them and
3+
created some new:
4+
5+
* Tunrstile Reactive <<statemachine-examples-turnstilereactive>>

docs/src/reference/asciidoc/appendix-reactormigration.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
Main task for a work for `3.x` has been to both internally and externally to move and change
55
as much as we can from imperative code into a reactive world. This means that some
66
of a main interfaces has added a new reative methods and most of a internal execution locig
7-
has been moved over to handled by a reactor. Essentially what this means is that thread handling
8-
is considerably different compared to `2.x`. Following chapters go throught all these changes.
7+
(where applicable) has been moved over to handled by a reactor. Essentially what this means is that thread handling model is considerably different compared to `2.x`. Following chapters
8+
go throught all these changes.
99

1010
include::appendix-reactormigration-communicating.adoc[]
1111

1212
include::appendix-reactormigration-threading.adoc[]
13+
14+
include::appendix-reactormigration-examples.adoc[]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[[sm-actions-reactive]]
2+
=== Reactive Actions
3+
Normal `Action` interface is a simple functional method taking `StateContext`
4+
and returning _void_. There's nothing blocking here until you block
5+
in a method itself and this is a bit of a problem as framework cannot
6+
know what's exactly happening inside of it.
7+
8+
====
9+
[source,java,indent=0]
10+
----
11+
public interface Action<S, E> {
12+
void execute(StateContext<S, E> context);
13+
}
14+
----
15+
====
16+
17+
To overcome this issue we've internally changed `Action` handling to
18+
process a plain java's `Function` taking `StateContext` and returning
19+
`Mono`. This way we can call action and fully in a reactive way to
20+
execute action only when it's subscribed and in a non-blocking way
21+
to wait it's completion.
22+
23+
====
24+
[source,java,indent=0]
25+
----
26+
public interface ReactiveAction<S, E> extends Function<StateContext<S, E>, Mono<Void>> {
27+
}
28+
----
29+
====
30+
31+
[NOTE]
32+
====
33+
Internally old `Action` interface is wrapped with a Reactor Mono Runnable as it
34+
shares same return type. We have no control what you do in that method!
35+
====

docs/src/reference/asciidoc/sm-actions.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ NOTE: `StateContext` is described in <<sm-statecontext>>.
3838
You can also use a SpEL expression as a replacement for a
3939
full `Action` implementation.
4040
// TODO An example would help
41+
42+
include::sm-actions-reactive.adoc[]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[[sm-guards-reactive]]
2+
=== Reactive Guards
3+
Normal `Guard` interface is a simple functional method taking `StateContext`
4+
and returning _boolean_. There's nothing blocking here until you block
5+
in a method itself and this is a bit of a problem as framework cannot
6+
know what's exactly happening inside of it.
7+
8+
====
9+
[source,java,indent=0]
10+
----
11+
public interface Guard<S, E> {
12+
boolean evaluate(StateContext<S, E> context);
13+
}
14+
----
15+
====
16+
17+
To overcome this issue we've internally changed `Guard` handling to
18+
process a plain java's `Function` taking `StateContext` and returning
19+
`Mono<Boolean>`. This way we can call guard and fully in a reactive way
20+
to evaluate it only when it's subscribed and in a non-blocking way
21+
to wait it's completion with a return value.
22+
23+
====
24+
[source,java,indent=0]
25+
----
26+
public interface ReactiveGuard<S, E> extends Function<StateContext<S, E>, Mono<Boolean>> {
27+
}
28+
----
29+
====
30+
31+
[NOTE]
32+
====
33+
Internally old `Guard` interface is wrapped with a Reactor Mono Function. We have no
34+
control what you do in that method!
35+
====

docs/src/reference/asciidoc/sm-guards.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[sm-guards]]
22
== Using Guards
33

4-
As shown in <<statemachine\-config\-thingstoremember>>, the `guard1` and `guard2` beans are attached to the entry and
4+
As shown in <<statemachine-config-thingstoremember>>, the `guard1` and `guard2` beans are attached to the entry and
55
exit states, respectively.
66
The following example also uses guards on events:
77

@@ -35,3 +35,5 @@ to return a `Boolean` value to satisfy the `Guard` implementation. This can be
3535
demonstrated with a `guardExpression()` function that takes an
3636
expression as an argument.
3737
// TODO Good spot for an example
38+
39+
include::sm-guards-reactive.adoc[]

0 commit comments

Comments
 (0)