Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending an event while another event is being processed does not work. #1179

Open
brash-ram opened this issue Feb 13, 2025 · 0 comments
Open
Labels
status/need-triage Team needs to triage and take a first look

Comments

@brash-ram
Copy link

On our project, we wanted to update the library version from 2.0.RELEASE to 4.0.0, but because of this, we started having errors.
State machine configurations:

@Override
public void configure(StateMachineTransitionConfigurer<ReplacementState, ReplacementEvent> transitions) throws Exception {
    transitions
            .withExternal().source(ReplacementState.NEW).target(ReplacementState.PREPARED).event(ReplacementEvent.PREPARE)
          .and().withExternal().source(ReplacementState.PREPARED).target(ReplacementState.IN_WORK).event(ReplacementEvent.TO_WORK)
        .guard(toWorkGuard())
        .action(toWorkAction(), errorHandlingAction())
        .action(toReadyToInstallState())

The first action toWorkAction() is handled correctly. During the second action toReadyToInstallState(), a new event READY_TO_INSTALL is sent. But after a new event, the state machine closes without changing the state. In the following StateMachineListenerAdapter code after sending a new event Stage = STATEMACHINE_STOP and the code is not executed by condition.

@Override
public void stateContext(StateContext<ReplacementState, ReplacementEvent> stateContext) {
    if (stateContext.getStage().equals(StateContext.Stage.STATE_CHANGED) && stateContext.getEvent() != null) {
        var replacement = (AbstractReplacement) stateContext
                .getStateMachine()
                .getExtendedState()
                .getVariables()
                .getOrDefault(ReplacementStateMachineContextRepository.ENTITY_CONTEXT_KEY, null);
        ReplacementState state = stateContext.getTarget().getId();
        if (replacement != null) {
            if (ReplacementEvent.CLOSE.equals(stateContext.getEvent())) {
                baseReplacementService.updateStateSystem(replacement, stateContext.getEvent(), state);
            } else {
                baseReplacementService.updateState(replacement, stateContext.getEvent(), state);
            }
        }
    }
}

Let me remind you that no code has changed except for version 2.0.RELEASE to 4.0.0.

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

1 participant