org.writersforge.catalan.process.workers
Class BaseJob

java.lang.Object
  extended byorg.writersforge.catalan.process.workers.BaseMetadataHolder
      extended byorg.writersforge.catalan.process.workers.BaseJob
All Implemented Interfaces:
IMetadataHolder, IWorker
Direct Known Subclasses:
XmlJob

public abstract class BaseJob
extends BaseMetadataHolder
implements IWorker

Base implementation of BaseJob API. All BaseJob properties are passed into embedded IWorker objects as runtime or IWorkspace properties. However, properties of embedded Workers are not reflected in the properties of the owning BaseJob. When BaseJob.init() is called, the same init properties will be passed into each embedded IWorker.

Author:
jsheets

Constructor Summary
BaseJob(IWorkMetadata metadata)
          Creates a new instance of BaseJob.
 
Method Summary
 IWorkProperties getDefaultProperties()
          Retrieves the default properties for this IWorker.
protected  IWorkProperties[] getWorkerRuntimeProperties()
          Retrieves customized runtime properties for each IWorker returned in getWorkers().
abstract  IWorker[] getWorkers()
          Retrieves all embedded Workers associated with this BaseJob, in the order they will run for this BaseJob.
 void process(IWorkProperties runtimeProps, IWorkspace workspace)
          Perform one stage of processing in the workspace.
 void setDefaultProperties(IWorkProperties defaultProps)
          Initializes IWorker with default properties.
 
Methods inherited from class org.writersforge.catalan.process.workers.BaseMetadataHolder
getMetadata, setOptionalProperties, setRequiredProperties, validateProperties, validateType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.writersforge.catalan.process.workers.IMetadataHolder
getMetadata, validateProperties, validateType
 

Constructor Detail

BaseJob

public BaseJob(IWorkMetadata metadata)
Creates a new instance of BaseJob.

Parameters:
metadata - metadata describing this job implementation
Method Detail

getDefaultProperties

public IWorkProperties getDefaultProperties()
Retrieves the default properties for this IWorker. It is up to the IWorker implementation how these properties are merged into the other available properties at process time.

Specified by:
getDefaultProperties in interface IWorker
Returns:
default properties

setDefaultProperties

public void setDefaultProperties(IWorkProperties defaultProps)
                          throws WorkPropertyException
Initializes IWorker with default properties. The IWorker implementation can throw an exception if the default properties are invalid for that IWorker. The old set of properties is completely removed.

Specified by:
setDefaultProperties in interface IWorker
Parameters:
defaultProps - default initialization data
Throws:
WorkPropertyException - if any given config parameters are invalid for any embedded IWorker, or if init() is called from inside process()

getWorkers

public abstract IWorker[] getWorkers()
Retrieves all embedded Workers associated with this BaseJob, in the order they will run for this BaseJob. The process() method will run on each IWorker, using the runtime properties passed into BaseJob.process() merged with the runtime properties for each IWorker from getWorkerRuntimeProperties().

Returns:
embedded Workers

getWorkerRuntimeProperties

protected IWorkProperties[] getWorkerRuntimeProperties()
Retrieves customized runtime properties for each IWorker returned in getWorkers(). The arrays returned by these two methods must be the same size and contain no nulls. The BaseJob will pass the runtime properties into each IWorker.process() method. By default, returns EmptyProperties for all workers.

Returns:
runtime properties for each embedded IWorker

process

public void process(IWorkProperties runtimeProps,
                    IWorkspace workspace)
             throws ProcessException
Perform one stage of processing in the workspace. If the IWorker needs to operate on any Queues, they must be specified in either the IWorker's defaultProps, or in the runtimeConfig supplied here. The process() method can be called many times for a single IWorker instance throughout a processing run; state should not be cached between process() invocations.

This implementation calls process() on each of its embedded IWorker objects, in the same order they appear in getWorkers(). The BaseJob assembles runtime properties for each IWorker in the following order of precedence:

  1. BaseJob.process() runtime props
  2. BaseJob.getWorkerRuntimeProperties()
  3. BaseJob.getDefaultProperties()

Specified by:
process in interface IWorker
Parameters:
runtimeProps - extra runtime parameters
workspace - processing environment
Throws:
ProcessException - if a fatal error occurs during processing; throws WorkPropertyException if any mandatory parameters are missing, or if any supplied parameters are invalid; throws ProcessException if arrays returned by getWorkers() and getRuntimeWorkerProperties() are null or do not match lengths