All Projects → mapteb → simple-state-machine

mapteb / simple-state-machine

Licence: other
A simple Java state machine for Spring Boot projects

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to simple-state-machine

pastafarian
A tiny event-based finite state machine
Stars: ✭ 20 (-20%)
Mutual labels:  fsm, state-machine, finite-state-machine, statemachine
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+85044%)
Mutual labels:  fsm, state-machine, statechart, finite-state-machine
statemachine-go
🚦 Declarative Finite-State Machines in Go
Stars: ✭ 47 (+88%)
Mutual labels:  fsm, state-machine, finite-state-machine, statemachine
Finity
A finite state machine library for Node.js and the browser with a friendly configuration DSL.
Stars: ✭ 88 (+252%)
Mutual labels:  fsm, state-machine, finite-state-machine
Statecharts.github.io
There is no state but what we make. Feel free to pitch in.
Stars: ✭ 265 (+960%)
Mutual labels:  fsm, state-machine, finite-state-machine
Fsm As Promised
A finite state machine library using ES6 promises
Stars: ✭ 446 (+1684%)
Mutual labels:  fsm, state-machine, finite-state-machine
Afsm
C++14 Finite State Machine library
Stars: ✭ 113 (+352%)
Mutual labels:  fsm, state-machine, finite-state-machine
Squirrel
squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
Stars: ✭ 1,789 (+7056%)
Mutual labels:  fsm, state-machine, statemachine
stateless
Finite State Machine porting from Stateless C#
Stars: ✭ 25 (+0%)
Mutual labels:  fsm, state-machine, finite-state-machine
FiniteStateMachine
This project is a finite state machine designed to be used in games.
Stars: ✭ 45 (+80%)
Mutual labels:  fsm, state-machine, finite-state-machine
Nanostate
🚦- Small Finite State Machines
Stars: ✭ 151 (+504%)
Mutual labels:  fsm, state-machine, finite-state-machine
qp-arduino
QP real-time embedded frameworks/RTOS for Arduino (AVR and SAM)
Stars: ✭ 37 (+48%)
Mutual labels:  fsm, state-machine, statechart
use-state-machine
Use Finite State Machines with React Hooks
Stars: ✭ 28 (+12%)
Mutual labels:  fsm, state-machine, finite-state-machine
qm
QM model-based design tool and code generator based on UML state machines
Stars: ✭ 54 (+116%)
Mutual labels:  fsm, state-machine, statechart
Jstate
Advanced state machines in Java.
Stars: ✭ 84 (+236%)
Mutual labels:  fsm, state-machine, finite-state-machine
UnityHFSM
A simple yet powerful class based hierarchical finite state machine for Unity3D
Stars: ✭ 243 (+872%)
Mutual labels:  fsm, state-machine, finite-state-machine
SimpleStateMachineLibrary
📚 A simple library for realization state machines in C# code
Stars: ✭ 30 (+20%)
Mutual labels:  state-machine, finite-state-machine, statemachine
Django Fsm
Django friendly finite state machine support
Stars: ✭ 1,898 (+7492%)
Mutual labels:  fsm, state-machine, finite-state-machine
Fluent State Machine
Fluent API for creating state machines in C#
Stars: ✭ 195 (+680%)
Mutual labels:  fsm, state-machine, finite-state-machine
StateBuilder
State machine code generator for C++ and Java.
Stars: ✭ 30 (+20%)
Mutual labels:  state-machine, statechart, finite-state-machine

simple-state-machine

A simple state machine for Spring Boot projects

After importing into an IDE like STS can be run as Spring Boot application.

This project contains a framework and an illustration of the usage of the framework for a sample project like online order processing.

Usage

Initial State Pre-event Processor Post-event Final State
DEFAULT -> submit -> orderProcessor() -> orderCreated -> PMTPENDING
PMTPENDING -> pay -> paymentProcessor() -> paymentError -> PMTPENDING
PMTPENDING -> pay -> paymentProcessor() -> paymentSuccess -> COMPLETED
  1. To use this framework first create a state transitions table like above.

  2. Then implement the interfaces ProcessState and ProcessEvent. See OrderState and OrderEvent classes for examples

  3. Identify a primary key for the process. For the order process it would be orderId, for a time sheet application it would be userId-week-ending-date etc.

  4. Implement the StateTransitionsManager. See the OrderStateTransitionsManager class for an example.

  5. Implement the Processor class. See the OrderProcessor and the PaymentProcessor classes for examples.

  6. Create a controller class. See the OrderController for an example.

That is it.

For the order sample considered in this project, the following two APIs are created to test the state machine:

http://localhost:8080/order

http://localhost:8080/order/cart?payment=123&orderId=123

(for quick testing in a browser both of the above are implemented as GET APIs)

When the above APIs are called the console log displays the state transitions that reflect the above table. (Note: payment=0 is used to mock payment error in this example)

Related Projects

A non-blocking version of this project is at: https://github.com/mapteb/non-blocking-state-machine

The technique used in this Java project can be easily adapted to Angular applications. Here is an Angular example.

More Info

More information about this project can be found at: https://dzone.com/articles/a-simple-state-machine-for-spring-boot-projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].