Skip to content

EasyFlow - Simple and lightweight Finite State Machine for Java

Notifications You must be signed in to change notification settings

maximdim/EasyFlow

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyFlow

by DataSymphony.com.au

EasyFlow 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 applications

All this in less then 30kB and no run-time overhead! Download EasyFlow 1.1

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

State diagram fragment

With EasyFlow we can define the above state machine like this

EasyFlow<FlowContext> flow = FlowBuilder

    .from(SHOWING_WELCOME).transit(
        onCardPresent.to(WAITING_FOR_PIN).transit(
            onPinProvided.to(...).transit(
                ...
            ),
            onCancel.to(RETURNING_CARD).transit(
                onCardExtracted.to(SHOWING_WELCOME)
            )
        )
    )

then all what's left to do is to implement our state handlers like so

SHOWING_WELCOME.whenEnter(new StateHandler<FlowContext>() {
    @Override
    public void call(State<FlowContext> state, final FlowContext context) throws Exception {
        ...
        btnOption1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCardPresent.trigger(context);
            }
        });
        ...
    }
});
...

and start the flow

flow.start(new FlowContext());

See the complete example

About

EasyFlow - Simple and lightweight Finite State Machine for Java

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%