Replace resetStateMachine with resetStateMachineReactively
- improve AbstractPersistStateMachineHandler#handleEventWithStateReactively - Fixex #949 Signed-off-by: xJoeWoo <xjoewoo@gmail.com>
This commit is contained in:
committed by
Janne Valkealahti
parent
0c88fb9b2c
commit
048e930a19
@@ -24,6 +24,7 @@ import org.springframework.statemachine.support.DefaultStateMachineContext;
|
||||
import org.springframework.statemachine.support.LifecycleObjectSupport;
|
||||
import org.springframework.statemachine.support.StateMachineInterceptorAdapter;
|
||||
import org.springframework.statemachine.transition.Transition;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -63,7 +64,7 @@ public abstract class AbstractPersistStateMachineHandler<S, E> extends Lifecycle
|
||||
stateMachine.stopReactively().block();
|
||||
List<StateMachineAccess<S, E>> withAllRegions = stateMachine.getStateMachineAccessor().withAllRegions();
|
||||
for (StateMachineAccess<S, E> a : withAllRegions) {
|
||||
a.resetStateMachine(new DefaultStateMachineContext<S, E>(state, null, null, null));
|
||||
a.resetStateMachineReactively(new DefaultStateMachineContext<S, E>(state, null, null, null)).block();
|
||||
}
|
||||
stateMachine.startReactively().block();
|
||||
return stateMachine.sendEvent(event);
|
||||
@@ -77,18 +78,18 @@ public abstract class AbstractPersistStateMachineHandler<S, E> extends Lifecycle
|
||||
* @return mono for completion
|
||||
*/
|
||||
public Mono<Void> handleEventWithStateReactively(Message<E> event, S state) {
|
||||
StateMachine<S, E> stateMachine = getInitStateMachine();
|
||||
// TODO: REACTOR add docs and revisit this function concept
|
||||
return Mono.from(stateMachine.stopReactively())
|
||||
.then(Mono.fromRunnable(() -> {
|
||||
List<StateMachineAccess<S, E>> withAllRegions = stateMachine.getStateMachineAccessor().withAllRegions();
|
||||
for (StateMachineAccess<S, E> a : withAllRegions) {
|
||||
a.resetStateMachine(new DefaultStateMachineContext<S, E>(state, null, null, null));
|
||||
}
|
||||
}))
|
||||
.then(stateMachine.startReactively())
|
||||
.thenMany(stateMachine.sendEvent(Mono.just(event)))
|
||||
.then();
|
||||
return Mono.defer(() -> {
|
||||
StateMachine<S, E> stateMachine = getInitStateMachine();
|
||||
// TODO: REACTOR add docs and revisit this function concept
|
||||
return Mono.from(stateMachine.stopReactively())
|
||||
.thenEmpty(
|
||||
Flux.fromIterable(stateMachine.getStateMachineAccessor().withAllRegions())
|
||||
.flatMap(region -> region.resetStateMachineReactively(new DefaultStateMachineContext<S, E>(state, null, null, null)))
|
||||
)
|
||||
.then(stateMachine.startReactively())
|
||||
.thenMany(stateMachine.sendEvent(Mono.just(event)))
|
||||
.then();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -166,7 +166,7 @@ public class TasksHandler {
|
||||
}
|
||||
|
||||
stateMachine.stopReactively().block();
|
||||
stateMachine.getStateMachineAccessor().doWithAllRegions(function -> function.resetStateMachine(context));
|
||||
stateMachine.getStateMachineAccessor().doWithAllRegions(function -> function.resetStateMachineReactively(context).block());
|
||||
stateMachine.startReactively().block();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user