GithubHelp home page GithubHelp logo

zhaoyta / easyflow-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beh01der/easyflow

0.0 1.0 0.0 121 KB

EasyFlow - Simple and lightweight Finite State Machine for Java

Home Page: http://datasymphony.com.au/open-source/easyflow

License: Apache License 2.0

Java 100.00%

easyflow-1's Introduction

EasyFlow

by DataSymphony.com.au

EasyFlow 1.3 is out (12 Dec 2013)

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.3

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

enum States implements StateEnum {
    SHOWING_WELCOME, WAITING_FOR_PIN, RETURNING_CARD, SHOWING_WELCOME, ...
}

enum Events implements EventEnum {
    cardPresent, pinProvided, cardExtracted, cancel, ...
}
...
EasyFlow<FlowContext> 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

whenEnter(SHOWING_WELCOME, new ContextHandler<FlowContext>() {
    @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

flow.start(new FlowContext());

See complete example ATM emulator - Android application

To start using EasyFlow on your project, define Maven dependency like so

<dependency>
    <groupId>au.com.datasymphony</groupId>
    <artifactId>EasyFlow</artifactId>
    <version>1.3.1</version>
</dependency>

See also

EasyFlow for Node.js

License Apache 2.0

easyflow-1's People

Contributors

bachi76 avatar beh01der avatar hank-cp avatar johnnylambada avatar maximdim avatar mpontes avatar sergeyzenchenko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.