spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.53k stars 599 forks source link

How to add a reactive guard to an external configuration? #1035

Open danitochilin opened 2 years ago

danitochilin commented 2 years ago

I have created this guard:

public class Guard implements ReactiveGuard<State, StateEvent> {

  @Override
  public Mono<Boolean> apply(final StateContext<State, StateEvent> stateStateEventStateContext) {

    // return call to fucntion that return mono<Boolean> calling cassandra database;
  }
}

And then in configuration of state machine, not exist guard function to add this guard

@Override
  public void configure(
      final StateMachineTransitionConfigurer<State, StateEvent> transitions)
      throws Exception {

    transitions
        .withExternal()
        .source(State.INIT)
        .target(State.FINISH)
        .event(StateEvent.INITIALIZE)
        //There is no method to add the guard
        .guardFunction(new Guard())