Apache Camel is an open source integration framework which will help you in this.
You can use Apache Camel to build your own simple workflow manager, where each process implements Processor. Your data can passed through processors using camel Exchange. Check out camel examples for more information.
For information on how to write custom processor, please read here.
You can add Processors to a Camel RouteBuilder dynamically, schedule it using Quartz Scheduler etc., which will more or less address all your requirements.
Here is good introduction to Camel : http://www.kai-waehner.de/blog/2012/05/04/apache-camel-tutorial-introduction/
A simple implementation of Workflow Manager using Camel:
WorkflowManager.java
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class WorkflowManager {
DefaultCamelContext camelContext;
public WorkflowManager() {
camelContext = new DefaultCamelContext();
RouteBuilder routeBuilder = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:schedule?period=1s&daemon=true").process(new ProcessOne()).process(new ProcessTwo());
}
};
try {
camelContext.addRoutes(routeBuilder);
} catch (Exception e) {
e.printStackTrace();
}
}
public void start() throws Exception {
camelContext.start();
}
public void stop() throws Exception {
camelContext.stop();
}
public static void main(String[] args) {
WorkflowManager workflowManager = new WorkflowManager();
try {
workflowManager.start();
while(true) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
ProcessOne.java
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class ProcessOne implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("In ProcessOne");
}
}
ProcessTwo.java
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class ProcessTwo implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("In ProcessTwo");
}
}
I used Camel version 2.9.0 to compile this code. Please note that I've used an infinite loop in main method to keep the main thread alive.
This code will run a route having ProcessOne and ProcessTwo, with a period of 1 second. You can see the period in from(...) method where I add processors to route builder. Hence, this route will run repeatedly. Also, I am not trying to flow any data. You can use exchange in the process method of each processor to flow data.
Output will be:
In ProcessOne
In ProcessTwo
In ProcessOne
In ProcessTwo
You can use camel components to make your WorkflowManager robust.
Best Answer
I'm not sure to have understood correctly your issue. JBpm doesn't clean tables for old process instances when you deploy a new process definition.
When you deploy a new process definition with the same name of an existing one, you get new version of that process definition.
Existing process instances continue running with the process definition version they was started with, while new process instances take the latest version unless you specify the precise version to be used.
In theory, process definition can also be modified for running process instances using the API. In doing so, you must pay attention to make these changes compatible with the flowing of these instances.