org.umber.catalan.process.workers
Class BaseWorker

java.lang.Object
  extended byorg.umber.catalan.process.workers.BaseMetadataHolder
      extended byorg.umber.catalan.process.workers.BaseWorker
All Implemented Interfaces:
IMetadataHolder, IWorker
Direct Known Subclasses:
BaseCommandWorker, ControlWorker, DispatchWorker, LogWorker, PartitionWorker, PdfWorker, QueueNodeWorker, QueueSortWorker, QueueWorker, SqlWorker, VelocityWorker, XmlBuilderWorker

public abstract class BaseWorker
extends BaseMetadataHolder
implements IWorker

Shared implementation of the IWorker interface.

Author:
jsheets

Constructor Summary
BaseWorker()
          Creates a new instance of BaseWorker with default autogenerated metadata.
BaseWorker(IWorkMetadata info)
          Creates a new instance of BaseWorker.
 
Method Summary
protected abstract  void doWork()
          Core executor for descendents of BaseWorker.
protected  java.util.List getActiveNodes()
          Retrieves the nodes currently active for processing.
protected  IQueue getActiveQueue()
          Retrieves the primary target queue for this IWorker.
 IWorkProperties getDefaultProperties()
          Retrieves the default properties for this IWorker.
 IWorkProperties getRuntimeProperties()
          Retrieves this IWorker's default and runtime properties.
protected  IWorkspace getWorkspace()
          Retrieves current IWorkspace if inside the process() method, or null if outside.
protected  void handleErrorProblem(java.lang.String message, ProcessException e)
          Handles an ERROR problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.
protected  void handleFatalProblem(java.lang.String message, ProcessException e)
          Handles a FATAL problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.
protected  void handleInfoProblem(java.lang.String message, ProcessException e)
          Handles an INFO problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.
protected  void handleWarningProblem(java.lang.String message, ProcessException e)
          Handles a WARNING problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.
 boolean isProcessing()
          Determines if the IWorker is currently processing data in its process() method.
 void process(IWorkProperties runtimeProps, IWorkspace workspace)
          Perform one stage of processing in the workspace.
 void setDefaultProperties(IWorkProperties defaultProps)
          Initializes IWorker with default properties.
protected  void setTerminalPriority(AlertPriority priority)
          Assigns the AlertPriority level at which this IWorker will throw an exception.
 
Methods inherited from class org.umber.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.umber.catalan.process.workers.IMetadataHolder
getMetadata, validateProperties, validateType
 

Constructor Detail

BaseWorker

public BaseWorker()
Creates a new instance of BaseWorker with default autogenerated metadata.


BaseWorker

public BaseWorker(IWorkMetadata info)
Creates a new instance of BaseWorker.

Parameters:
info - metadata for this worker
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.

If the Object[] constructor is used to create this IWorker object, it will attempt to validate the "command" property if it is set.

Specified by:
setDefaultProperties in interface IWorker
Parameters:
defaultProps - default initialization data
Throws:
WorkPropertyException - if any given config parameters are invalid

isProcessing

public boolean isProcessing()
Determines if the IWorker is currently processing data in its process() method.

Returns:
true if currently processing

getRuntimeProperties

public IWorkProperties getRuntimeProperties()
                                     throws WorkPropertyException
Retrieves this IWorker's default and runtime properties. Default properties are pulled from getDefaultProperties(), and runtime properties are pulled from the runtimeProps parameter of the process() method. If a property exists in both the runtime and default property sets, the runtime property will be used. If this method is called outside the process() method, it will throw an exception.

Returns:
IWorker runtime properties
Throws:
WorkPropertyException - if called outside of process()

getWorkspace

protected IWorkspace getWorkspace()
Retrieves current IWorkspace if inside the process() method, or null if outside.

Returns:
current IWorkspace

getActiveQueue

protected final IQueue getActiveQueue()
                               throws WorkPropertyException
Retrieves the primary target queue for this IWorker. First attempts to look up the named queue in the "queue" config property. Falls back on the default queue if that fails. This method should only be called from inside a call to process(); if called elsewhere, it should always return a null.

Lookup order:

  1. Runtime config from IWorker.process()
  2. Default IWorker config from IWorker.init()
  3. IWorkspace global properties
  4. Default queue from QueueManager

Returns:
the target queue for this IWorker
Throws:
WorkPropertyException - if called outside of process()

getActiveNodes

protected java.util.List getActiveNodes()
                                 throws WorkPropertyException
Retrieves the nodes currently active for processing. Uses getActiveQueue() to get the current IQueue, and the "start-index" and "end-index" properties to choose a subset of the nodes in the active queue. Both start and end indices are inclusive, so given an array of [0, 1, 2, 3, 4], with a start-index of 1 and an end-index of 3, the subset of active nodes would be [1, 2, 3].

Returns:
the set of nodes currently available for processing
Throws:
WorkPropertyException - if called outside of process()

doWork

protected abstract void doWork()
                        throws ProcessException
Core executor for descendents of BaseWorker. The process() method sets up the in-process properties, then calls into this method.

Throws:
ProcessException - if a fatal error occurs during processing

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 runtimeProps supplied here. The runtime config can be null if the IWorker's default config contains a complete set of parameters; the workspace cannot be null.

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.

Specified by:
process in interface IWorker
Parameters:
runtimeProps - extra runtime parameters
workspace - processing environment
Throws:
ProcessException - if a fatal error occurs during processing, if any mandatory parameters are missing, if any parameters are invalid, or if workspace parameter is null

setTerminalPriority

protected void setTerminalPriority(AlertPriority priority)
Assigns the AlertPriority level at which this IWorker will throw an exception. Any problems of a lower level will be logged in the AlertQueue; any problems of equal or greater level will be logged in the AlertQueue and the exception will be re-thrown. The default terminal priority is FATAL. If the priority is set to null, the IWorker will never throw exceptions for problems.

The problem levels are, in order of decreasing priority:

  1. AlertPriority.FATAL
  2. AlertPriority.ERROR
  3. AlertPriority.WARNING
  4. AlertPriority.INFO

Parameters:
priority - level or above to throw exceptions, or null to never throw exceptions

handleFatalProblem

protected void handleFatalProblem(java.lang.String message,
                                  ProcessException e)
                           throws ProcessException
Handles a FATAL problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.

Parameters:
message - problem description
e - the thrown exception, if any
Throws:
ProcessException - if IWorker is set up to rethrow this type of problem; will always be the same exception passed in

handleErrorProblem

protected void handleErrorProblem(java.lang.String message,
                                  ProcessException e)
                           throws ProcessException
Handles an ERROR problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.

Parameters:
message - problem description
e - the thrown exception, if any
Throws:
ProcessException - if IWorker is set up to rethrow this type of problem; will always be the same exception passed in

handleWarningProblem

protected void handleWarningProblem(java.lang.String message,
                                    ProcessException e)
                             throws ProcessException
Handles a WARNING problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.

Parameters:
message - problem description
e - the thrown exception, if any
Throws:
ProcessException - if IWorker is set up to rethrow this type of problem; will always be the same exception passed in

handleInfoProblem

protected void handleInfoProblem(java.lang.String message,
                                 ProcessException e)
                          throws ProcessException
Handles an INFO problem; might throw the exception or post it as an Alert in the AlertQueue, or both, depending on the config of the IWorker.

Parameters:
message - problem description
e - the thrown exception, if any
Throws:
ProcessException - if IWorker is set up to rethrow this type of problem; will always be the same exception passed in