https://github.com/beh01der/easyflow
EasyFlow - Simple and lightweight Finite State Machine for Java
https://github.com/beh01der/easyflow
Last synced: 2 months ago
JSON representation
EasyFlow - Simple and lightweight Finite State Machine for Java
- Host: GitHub
- URL: https://github.com/beh01der/easyflow
- Owner: Beh01der
- License: apache-2.0
- Created: 2013-04-12T02:00:25.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-02-17T10:13:09.000Z (over 2 years ago)
- Last Synced: 2025-03-28T16:05:26.084Z (2 months ago)
- Language: Java
- Homepage: http://datasymphony.com.au/open-source/easyflow
- Size: 77.1 KB
- Stars: 448
- Watchers: 33
- Forks: 87
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
EasyFlow
========EasyFlow 1.3 is out (12 Dec 2013)
* refactored to use Java **enums** for states and events
* added new exampleEasyFlow is a simple and lightweight Finite State Machine for Java
With **EasyFlow** you can:
* implement complex logic but keep your code simple and clean
* handle asynchronous calls with ease and elegance
* avoid concurrency by using event-driven programming approach
* avoid *StackOverflow* error by avoiding recursion
* simplify design, programming and testing of complex java applicationsAll this in less then 30kB and no run-time overhead!
Here is a simple example illustrating how a state machine can be definded and implemented with **EasyFlow**
This is a State diargam fragment describing a simple ATM workflow
With **EasyFlow** we can define the above state machine like this
```java
enum States implements StateEnum {
SHOWING_WELCOME, WAITING_FOR_PIN, RETURNING_CARD, SHOWING_WELCOME, ...
}enum Events implements EventEnum {
cardPresent, pinProvided, cardExtracted, cancel, ...
}
...
EasyFlow flow =from(SHOWING_WELCOME).transit(
on(cardPresent).to(WAITING_FOR_PIN).transit(
on(pinProvided).to(...).transit(
...
),
on(cancel).to(RETURNING_CARD).transit(
on(cardExtracted).to(SHOWING_WELCOME)
)
)
);
```
then all what's left to do is to implement our state handlers like so
```java
whenEnter(SHOWING_WELCOME, new ContextHandler() {
@Override
public void call(final FlowContext context) throws Exception {
...
btnOption1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.trigger(cardPresent);
}
});
...
}
});
...
```
and start the flow
```java
flow.start(new FlowContext());
```
See complete example [ATM emulator - Android application](https://github.com/Beh01der/EasyFlow-example-AtmEmulator/blob/master/src/au/com/ds/ef/ae/AtmEmulator/MainActivity.java)To start using EasyFlow on your project, define Maven dependency like so
```xmlau.com.datasymphony
EasyFlow
1.3.1```
## See also
[EasyFlow for Node.js](https://github.com/Beh01der/node-easy-flow)License [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)