org.writersforge.catalan.process
Class WorkProcessor

java.lang.Object
  extended byorg.writersforge.catalan.process.WorkProcessor

public class WorkProcessor
extends java.lang.Object

Top level driver for running worker processes.

Author:
jsheets

Constructor Summary
WorkProcessor(IWorkspace workspace)
          Creates a new instance of WorkProcessor from instantiated workspace and registry objects.
WorkProcessor(java.lang.String[] args)
          Creates a new instance of WorkProcessor, using paths to XML versions of the workspace and registry.
 
Method Summary
 IWorkspace getWorkspace()
          Retrieves this WorkProcessor's workspace.
protected  void handleProcessException(ProcessException e)
          Handles the processing exception.
static void main(java.lang.String[] args)
          Runs the given workers.
 void processBatch(java.lang.String[] workerNames, IWorkProperties runtimeProps)
          Executes the workers in workerNames, in the order they occur in the array, passing the given runtime properties into each invocation.
 void processFromArgs()
          Executes the workers named on the command line, using the command line arguments as the runtime properties.
 void processWorker(java.lang.String name, IWorkProperties runtimeProps)
          Executes the single worker or job of the given name, using the given runtime properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkProcessor

public WorkProcessor(java.lang.String[] args)
              throws WorkspaceException,
                     RegistryException
Creates a new instance of WorkProcessor, using paths to XML versions of the workspace and registry. The XML files can be in the filesystem, relative to the classpath, or inside a JAR file. The workspace should be specified on the command line with the --workspace argument, and the WorkerRegistry with the --registry argument. If either parameter is omitted, the default version of each will be used.

Parameters:
args - command-line arguments
Throws:
WorkspaceException - if specified workspace cannot be loaded
RegistryException - if specified registry cannot be loaded

WorkProcessor

public WorkProcessor(IWorkspace workspace)
              throws WorkspaceException
Creates a new instance of WorkProcessor from instantiated workspace and registry objects.

Parameters:
workspace - workspace for all operations in this processor
Throws:
WorkspaceException - if workspace is null
Method Detail

getWorkspace

public IWorkspace getWorkspace()
Retrieves this WorkProcessor's workspace.

Returns:
processor workspace

processFromArgs

public void processFromArgs()
                     throws ProcessException
Executes the workers named on the command line, using the command line arguments as the runtime properties. For example, consider this command line:
   --workspace workspace.xml --registry registry.xml --count 14
   worker1 worker2
 
The WorkProcessor would invoke the IWorker.process() on "worker1" and "worker2" from the registry associated with this processor. It would pass in runtime properties for "workspace", "registry", and "count", loaded from the command-line arguments.

Throws:
ProcessException - if errors occur during IWorker processing

processBatch

public void processBatch(java.lang.String[] workerNames,
                         IWorkProperties runtimeProps)
                  throws ProcessException
Executes the workers in workerNames, in the order they occur in the array, passing the given runtime properties into each invocation.

Parameters:
workerNames - an array of IWorker names
runtimeProps - runtime properties to pass into each IWorker
Throws:
ProcessException - if errors occur during IWorker processing

processWorker

public void processWorker(java.lang.String name,
                          IWorkProperties runtimeProps)
                   throws ProcessException
Executes the single worker or job of the given name, using the given runtime properties.

Parameters:
name - name of IWorker in registry to run
runtimeProps - runtime properties to pass into IWorker.process()
Throws:
ProcessException - if errors occur during IWorker processing

handleProcessException

protected void handleProcessException(ProcessException e)
                               throws ProcessException
Handles the processing exception. The default implementation lodges the exception as a FATAL Alert in the IWorkspace, and will never re-throw the exception. This allows processing to continue to other Workers in the batch.

A sub-class of WorkProcessor might, for example, choose to set certain ProcessExceptions as ERRORs or WARNINGs instead, or rethrow them to immediately halt all processing.

Parameters:
e - processing exception to handle
Throws:
ProcessException - if the processor should bail out prematurely

main

public static void main(java.lang.String[] args)
Runs the given workers.

Parameters:
args -
Throws:
ProcessException