I have created several tasks, each takes an input, an execution function which keeps updating its status, and a function to get output of this task. They will execute in serial or parallel. Some outputs are List so there will be loops as well.
public class Task1 { //each task looks like this
void addInput(String key, String value){
....
}
void run(){
....
updateStatus();
....
}
HashMap getOutput(){
....
}
Status getStatus(){
....
}
}
I want to make a workflow from these tasks and then I will use the workflow structure information to build a dynamic GUI and monitor outputs of each task. Do I have to write a workflow execution system from scratch or is there any simple alternative available?
Is there any workflow engine to which I can give (in XML may be) my Java classes, input and output and execution functions and let it execute?
In Java world, your use case is called as BPM (Business process management).
In .Net world, this is called as Windows Workflow Foundation (WWF).
There are many java based open source BPM tools. The one i like is jBPM.
This is more powerful and can be integrated with rule engines like Drools.
Sample jBPM Screenshot:
Also Activiti is another good choice.
Sample Activiti Screenshot:
Check out Activity. This is not strictly designed to solve your use case, but you may use and adapt it's process engine to help you because it's written purely in java. Activity is rather process modeling engine so it's not designed to controll tasks running in parallel at runtime, howerver you will get many things which you can reuse "out of the box".
So going in this direction you will get many things for free. From programmer point of View you can for example inherit from Task
class from Activity api. Late when the task is completed call
taskService.complete(task.getId(), taskVariables);
You can also go another way arround. So supossing that your class which calculates in background is called CalculationTask, you can connect CalculatinTasks with new instance of Activity Task. By this you will get a bridge to Activity process engine. So you can do something like
class CustomActivityTask extends Task { // inherit from Activity Task class to add your own fields
private int someStateOne;
private String someOtherState;
(...)
// getters and setters
}
class CalculationTask {
private CustomActivityTask avtivityTask; // by updating the state of this task you are updating the state of the task in Activity process engine
private RuntimeService activityRuntimeServiece;
public void run() { // this is your execution functin
while (true) {
// calulate
activityTask.setSomeStateOne(45)
activityTask.setSomeOtherState("Task is almost completing...");
(...)
if (allCompleted) {
activityRuntimeServiece.complete(avtivityTask.getId(), taskVariables);
break;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With