org.jmonks.batch.framework.controller.pool
Class AbstractPoolJobProcessor

java.lang.Object
  extended byorg.jmonks.batch.framework.controller.pool.AbstractPoolJobProcessor
All Implemented Interfaces:
PoolJobProcessor

public abstract class AbstractPoolJobProcessor
extends java.lang.Object
implements PoolJobProcessor

Abstract pool job processor implements some of the responsiblites defined by the pool job processor and leaves the application specific functionality implementation to the final processor. Following is an example class shows how to make use of the AbstractPoolJobProcessor.

      public class MyPoolJobProcessor extends AbstractPoolJobProcessor
      {
          private Connection connection=null;

          public void initialize(JobContext jobContext)
          {
              // Perform the initialization for this instance of job processor.
              // Good place to get any references to any resources to be used to
              // to processing of all the job data.
              connection=ConnectionManager.getDBConnection();
          }
  
          public ErrorCode process(Object jobData)
          {
              // Perform the business logic on the incoming jobData.
              connection.performBusinessLogic(jobData);

              return ErrorCode.JOB_COMPLETED_SUCCESSFULLY;
          }

          public void cleanup()
          {
              // Do some cleanup after all the jobData has been processed.
              connection.close();
          }
      }
  

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Field Summary
protected  ProcessorStatus processorStatus
          Holds the processor status.
 
Constructor Summary
AbstractPoolJobProcessor()
           
 
Method Summary
abstract  void cleanup()
          Chance to do any cleanup at the end of the processing.
 long getProcessedJobDataCount()
          Returns the number of job data objects this particular job processor has finsihed.
 java.lang.Object getProcessorState()
          Gets the processor to be displyed or anaylyzed for the monitoring purposes.
 ProcessorStatus getProcessorStatus()
          Gets the processor status being used by the management clients.
abstract  void initialize(JobContext jobContext)
          Chance to initialize itself using the information provided through job context.
abstract  ErrorCode process(java.lang.Object jobData)
          Execute the business logic on the given jobData and return the appropriate error code.
 ErrorCode processPool(JobContext jobContext, JobPool pool)
           Initializes the processor implementation by calling the initialize method by passing job context reference, gets the job data from the pool and passes that information to the processor implementation for processing and cleans up the processor implementation by calling the cleanup method.
 boolean resume()
          Resumes the processor.
 boolean stop()
          Stops the processor.
 boolean suspend()
          Suspends the processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

processorStatus

protected ProcessorStatus processorStatus
Holds the processor status.

Constructor Detail

AbstractPoolJobProcessor

public AbstractPoolJobProcessor()
Method Detail

processPool

public ErrorCode processPool(JobContext jobContext,
                             JobPool pool)

Initializes the processor implementation by calling the initialize method by passing job context reference, gets the job data from the pool and passes that information to the processor implementation for processing and cleans up the processor implementation by calling the cleanup method. It consolidates all the return codes from the processor implementation process method and return the final error code. If it receives null as the return code, continues the processing, but returns pool job processor exception return code.

Specified by:
processPool in interface PoolJobProcessor
Parameters:
jobContext - Context the job is being run.
pool - Job pool reference where job data needs to be pulled.
Returns:
Returns the status code of this job processor.

suspend

public boolean suspend()
Suspends the processor.

Specified by:
suspend in interface PoolJobProcessor
Returns:
Returns true if the processor is suspended, false otherwise.

resume

public boolean resume()
Resumes the processor.

Specified by:
resume in interface PoolJobProcessor
Returns:
Retrurns true if the processor is resumed, false otherwise.

stop

public boolean stop()
Stops the processor.

Specified by:
stop in interface PoolJobProcessor
Returns:
Retrurns true if the processor has stopped, false otherwise.

getProcessorState

public java.lang.Object getProcessorState()
Description copied from interface: PoolJobProcessor
Gets the processor to be displyed or anaylyzed for the monitoring purposes.

Specified by:
getProcessorState in interface PoolJobProcessor
Returns:
Returns an object understanble/displayable by monitoring client.
See Also:
PoolJobProcessor.getProcessorState()

getProcessorStatus

public ProcessorStatus getProcessorStatus()
Description copied from interface: PoolJobProcessor
Gets the processor status being used by the management clients.

Specified by:
getProcessorStatus in interface PoolJobProcessor
Returns:
Returns the status of the job.
See Also:
PoolJobProcessor.getProcessorStatus()

getProcessedJobDataCount

public long getProcessedJobDataCount()
Description copied from interface: PoolJobProcessor
Returns the number of job data objects this particular job processor has finsihed.

Specified by:
getProcessedJobDataCount in interface PoolJobProcessor
Returns:
Returns the number of job data objects processed.
See Also:
PoolJobProcessor.getProcessedJobDataCount()

initialize

public abstract void initialize(JobContext jobContext)
Chance to initialize itself using the information provided through job context. This will be called only once for each processor and before it start processing job data using process method.

Parameters:
jobContext - Context the job is being run.

process

public abstract ErrorCode process(java.lang.Object jobData)
Execute the business logic on the given jobData and return the appropriate error code. The format and type of jobData is depends on the job loader configured for the same job. Usually, there will be an understanding between the loader and processor on the type of jobData being loaded into the pool.

Parameters:
jobData - Data to be processed.
Returns:
Returns the status of the processing of this jobData.

cleanup

public abstract void cleanup()
Chance to do any cleanup at the end of the processing. Called once per each processor at the end of processing of all the jobs.