java flow四舍五入_EasyFlow - 简单、轻量级的Java有限状态机

EasyFlow

EasyFlow 1.3 is out (12 Dec 2013)

refactored to use Java enums for states and events

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

687474703a2f2f6461746173796d70686f6e792e636f6d2e61752f77702d636f6e74656e742f75706c6f6164732f323031332f30342f61746d5f6578616d706c652e706e67

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 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() {

@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());

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

au.com.datasymphony

EasyFlow

1.3.1

See also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值