spring-projects / spring-statemachine

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

Implement named transitions (fix #850) #984

Closed hielsnoppe closed 3 years ago

hielsnoppe commented 3 years ago

Use case

Given two instances of a StateMachine<S, E> resulting from the same StateMachineFactory<S, E> and a StateMachineListener<S, E>, I can listen for state changes and uniquely identify the state by its id, regardless of the state machine instance:

@Override
stateEntered(State<S, E> state) {
    S id = state.getId();
    // "state" is a different object depending on the state machine instance
    // "id" is the same in different state machine instances
}

For transitions, this is not possible:

@Override
public void transition(Transition<S, E> transition) {
    // "transition" is a different object depending on the state machine instance
    // there is no "id" available
}

In the current implementation I did not find a way to uniquely identify the Transition across StateMachine instances. In UML, transitions can be identified by name. Consequently, I implemented named transitions as a solution for above use case.

JIRA

There is no related issue in JIRA (as to my knowledge).

CLA

Yes, I have signed the CLA.

jvalkeal commented 3 years ago

Could you rebase as I added a pr workflow to run tests.

hielsnoppe commented 3 years ago

Thank you for the review! I will add the fixes you recommend and try to figure out how to rebase.

jvalkeal commented 3 years ago

I think this looks good now.