The simple, easy-used, stupid workflow engine for Java™
📖 English | 📖 中文
Easy Work is a workflow engine for Java. It provides concise APIs and building blocks for creating and running composable workflows.
In Easy Work, work units are represented by the Work interface, while workflows are represented by the WorkFlow interface.
Easy Work provides six implementation methods for the WorkFlow interface:
Those are the only basic flows you need to know to start creating workflows with Easy Work.
You don't need to learn a complex notation or concepts, just a few natural APIs that are easy to think about.
First let's write some work:
public class PrintMessageWork implements Work {
private final String message;
public PrintMessageWork(String message) {
this.message = message;
}
@Override
public String execute(WorkContext workContext) {
System.out.println(message);
return message;
}
}This unit of work prints a given message to the standard output. Now let's suppose we want to create the following workflow:
- print
athree times - then print
bcdin sequence - then print
efin parallel - then if both
eandfhave been successfully printed to the console, printg, otherwise printh - finally print
z
This workflow can be illustrated as follows:
flow1is aRepeatFlowof work which printathree timesflow2is aSequentialFlowof work which printbcdin sequence orderflow3is aParallelFlowof work which respectively printeandfin parallelflow4is aConditionalFlowbased on conditional judgment. It first executesflow3then if the result is successful (in the state of 'Complete') executeg, otherwise, executehflow5is aSequentialFlow, which ensures the sequential execution ofFlow1,Flow2,Flow4, and finally executesz
With Easy Work,this workflow can be implemented with the following snippet:
PrintMessageWork a = new PrintMessageWork("a");
PrintMessageWork b = new PrintMessageWork("b");
PrintMessageWork c = new PrintMessageWork("c");
PrintMessageWork d = new PrintMessageWork("d");
PrintMessageWork e = new PrintMessageWork("e");
PrintMessageWork f = new PrintMessageWork("f");
PrintMessageWork g = new PrintMessageWork("g");
PrintMessageWork h = new PrintMessageWork("h");
PrintMessageWork z = new PrintMessageWork("z");
WorkFlow flow = aNewSequentialFlow(
aNewRepeatFlow(a).times(3),
aNewSequentialFlow(b,c,d),
aNewConditionalFlow(
aNewParallelFlow(e,f).withAutoShutDown(true)
).when(
WorkReportPredicate.COMPLETED,
g,
h
),
z
);
aNewWorkFlowEngine().run(flow, new WorkContext());This is not a very useful workflow, but just to give you an idea about how to write workflows with Easy Work.
You can view more test cases in test/java.
You can find more details about all of this in the wiki
Note: Some of the naming conventions for the APIs in this project refer to Easy flow, a very simple and easy-to-use process engine.
Easy Work is released under the Apache License Version 2.0

