Give a possibility to set up a handler for transition #1

Open
opened 2022-07-14 16:30:16 +03:00 by bvn13 · 0 comments

When FSM checks transition for condition in order to be performed, there is a neccessity to perform custom handler just right after transition is performed.

An example may be like below

        SimpleFsm<String> simpleFsm = Fsm
                .<SimpleFsm<String>, String>from(SimpleFsm::new)
                .withStates()
                .from("init")
                    .withBeforeHandler(fsm -> initBefore.set(true))
                    .withAfterHandler(fsm -> initAfter.set(true))
                    .withProcessor((fsm, event) -> initProcess.set(true))
                .end()
                .state("intermediate")
                .end()
                .finish("finish")
                    .withBeforeHandler(fsm -> finishBefore.set(true))
                    .withAfterHandler(fsm -> finishAfter.set(true))
                    .withProcessor((fsm, event) -> finishProcess.set(true))
                .end()
                .withTransition()
                    .from("init")
                    .to("intermediate")
                    .checking((fsm, event) -> true)
                    .withHandler((fsm, event) -> { /* some code here */ })
                .end()
                .withTransition()
                    .from("intermediate")
                    .to("finish")
                    .checking((fsm, event) -> true)
                .end()
                .create();

When FSM checks transition for condition in order to be performed, there is a neccessity to perform custom handler just right after transition is performed. An example may be like below ```java SimpleFsm<String> simpleFsm = Fsm .<SimpleFsm<String>, String>from(SimpleFsm::new) .withStates() .from("init") .withBeforeHandler(fsm -> initBefore.set(true)) .withAfterHandler(fsm -> initAfter.set(true)) .withProcessor((fsm, event) -> initProcess.set(true)) .end() .state("intermediate") .end() .finish("finish") .withBeforeHandler(fsm -> finishBefore.set(true)) .withAfterHandler(fsm -> finishAfter.set(true)) .withProcessor((fsm, event) -> finishProcess.set(true)) .end() .withTransition() .from("init") .to("intermediate") .checking((fsm, event) -> true) .withHandler((fsm, event) -> { /* some code here */ }) .end() .withTransition() .from("intermediate") .to("finish") .checking((fsm, event) -> true) .end() .create(); ```
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bvn13/FinalStateMachine#1
There is no content yet.