Beh01der / EasyFlow

EasyFlow - Simple and lightweight Finite State Machine for Java
http://datasymphony.com.au/open-source/easyflow
Apache License 2.0
445 stars 86 forks source link

Support possibility to create flow in a step by step manner #18

Open dany52 opened 9 years ago

dany52 commented 9 years ago

instead of "tree style" like

 flow = FlowBuilder

            .from(SHOWING_WELCOME).transit(
                onCardPresent.to(WAITING_FOR_PIN).transit(
                    onPinProvided.to(CHECKING_PIN).transit(
                        onPinValid.to(SHOWING_MAIN_MENU).transit(
                            onMenuShowBalance.to(SHOWING_BALANCE).transit(
                                onCancel.to(SHOWING_MAIN_MENU)
                            ),
                            onMenuWithdrawCash.to(SHOWING_WITHDRAW_MENU).transit(
                                onCancel.to(SHOWING_MAIN_MENU),
                                onConfirm.to(SHOWING_TAKE_CASH).transit(
                                    onCashExtracted.to(SHOWING_MAIN_MENU)
                                )
                            ),
                            onMenuExit.to(RETURNING_CARD)
                        ),
                        onPinInvalid.to(SHOWING_PIN_INVALID).transit(
                            onTryAgain.to(WAITING_FOR_PIN),
                            onNoMoreTries.to(SHOWING_CARD_LOCKED).transit(
                                onConfirm.to(SHOWING_WELCOME)
                            ),
                            onCancel.to(RETURNING_CARD)
                        )
                    ),
                    onCancel.to(RETURNING_CARD).transit(
                        onCardExtracted.to(SHOWING_WELCOME)
                    )
                )
            )
                                  ...

something like

flow = FlowBuilder.register(SHOWING_WELCOME,
                onCardPresent.to(WAITING_FOR_PIN)
);

FlowBuilder.register(WAITING_FOR_PIN,
                onPinProvided.to(CHECKING_PIN),
                onCancel.to(RETURNING_CARD)
);
                      ...
FlowBuilder.register(SHOWING_PIN_INVALID,
                 onTryAgain.to(WAITING_FOR_PIN),
                 onNoMoreTries.to(SHOWING_CARD_LOCKED),
                 onCancel.to(RETURNING_CARD)
);
                      ...                                  ...
Beh01der commented 9 years ago

I guess I need to re-visit this project. It may be useful if you want to build FSM dynamically. Although, the whole point of EasyFlow is to build static FSM in form of a tree.

dany52 commented 9 years ago

Exactly. Now there is no simple method to build FSM when FSM model store in database.

Beh01der commented 9 years ago

Sorry for long delay. I added a new method to FlowBuilder. fromTransitions(StateEnum startState, Collection transitions, boolean skipValidation) Plus I added public constructor to Transition()

If you want to dynamically create EasyFlow instance, first prepare collection of transitions, then create it with FlowBuilder. fromTransitions(...)

Sorry, I don't have time to release it now, so you will have to build it from sources. Also, I haven't tested it.