Cave Process Framework

The Cave Process Framework is a framework for running background processes and keeping track with their states. Processes can be executed separately or together with other processes depending on each process' configuration. Currently, it requires the Spring Framework.

TODO: Update this page.

API and Diagrams

Basic Use

A process implements the Process interface, and is mapped up as a prototype Spring bean with a special ID (we'll get back to this in a second). This process can be loaded and request for execution using the ProcessCoordinator (implementation: SpringProcessCoordinator). The process is loaded using the newProcess(type, owner) method, where the type, together with a prefix and postfix, is the ID of the process bean. An example:

Application beans:

<bean id="processCoordinator" class="org.amplecode.cave.process.SpringProcessCoordinator"
  destroy-method="close"/>

<bean id="internal-process-foo" class="my.project.FooProcess"
  scope="prototype"/>

<bean id="myService" class="my.project.MyService">
  <property name="processCoordinator" ref="processCoordinator"/>
</bean>

The beans are: The process coordinator, a process with type "foo" (default prefix is "internal-process-", default postfix is ""), and some service using the process coordinator.

MyService.java:

public class MyService
{
    // -----------------------------------------------------------------------------------
    // Dependencies
    // -----------------------------------------------------------------------------------

    private ProcessCoordinator processCoordinator;

    public void setProcessCoordinator( ProcessCoordinator processCoordinator )
    {
        this.processCoordinator = processCoordinator;
    }

    // -----------------------------------------------------------------------------------
    // Service methods
    // -----------------------------------------------------------------------------------

    public void runFoo()
    {
        ProcessExecutor executor = processCoordinator.newProcess( "foo", "admin" );

        processCoordinator.requestForExecution( executor );
    }
}

The service, which has a reference to the process coordinator, asks the process coordinator to load the process typed "foo", and requests that it is put on the queue for execution. The loaded process and its status can be fetched through the process executor. The process executor also has a unique ID which can be used for retrieving it from the process coordinator at a later stage.

If the process implements the SerialToAll interface, then the process will be executed separately, in turn, from all other processes. If the process implements the SerialToGroup interface, then the process will be executed separately, in turn, from all other processes in the specified group.

Attachments