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

java.lang.Object
  extended byorg.jmonks.batch.framework.controller.pool.AbstractPoolJobLoader
All Implemented Interfaces:
PoolJobLoader

public abstract class AbstractPoolJobLoader
extends java.lang.Object
implements PoolJobLoader

AbstractPoolJobLoader implements all the management and monitoring methods and abstracts the user from the job pool. This allows the loader implementers to concentrate on the business logic. Following is an example, how to write your own loader by using AbstractPoolJobLoader.

      public class MyPoolJobLoader extends AbstractPoolJobLoader
      {
          public ErrorCode loadPool(JobContext jobContext)
          {
              for(int i=0;i<100;i++)
              {
                  loadJobData(new Integer(i));
                  if(super.stopLoading())
                  {
                      doCleanup();
                      super.loaderStatus=ProcessorStatus.STOPPED;
                      break;
                  }
              }
              loadJobData(null);
              return ErrorCode.JOB_COMPLETED_SUCCESSFULLY;
          }
      }
  

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Field Summary
protected  ProcessorStatus loaderStatus
          Holds the status of the loader.
 
Constructor Summary
AbstractPoolJobLoader()
           
 
Method Summary
 java.lang.Object getLoaderState()
          Returns the processing state of the loader.
 ProcessorStatus getLoaderStatus()
          Returns the status of the loader.
abstract  long getTotalJobDataCount()
          Returns the number of job data objects that this loader is going to load.
protected  boolean loadJobData(java.lang.Object jobData)
          Loads the given job data into the job pool.This method is for the final loaders to load the job data into the pool.
abstract  ErrorCode loadPool(JobContext jobContext)
           Load the job data into the pool that needs to be processed by job processor(s).
 ErrorCode loadPool(JobContext jobContext, JobPool pool)
          Abstracts the job pool details from the final loader by defining other set of methods for the final loader and implements the management and monitoring related methods.
 boolean resume()
          Resumes the loading of the jobs.
 boolean stop()
          Stops the loading of the jobs into the pool.
protected  boolean stopLoading()
          Tells whether the loading of the jobs needs to be stopped or not.
 boolean suspend()
          Suspends loading of the jobs into the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loaderStatus

protected ProcessorStatus loaderStatus
Holds the status of the loader.

Constructor Detail

AbstractPoolJobLoader

public AbstractPoolJobLoader()
Method Detail

loadPool

public final ErrorCode loadPool(JobContext jobContext,
                                JobPool pool)
Abstracts the job pool details from the final loader by defining other set of methods for the final loader and implements the management and monitoring related methods.

Specified by:
loadPool in interface PoolJobLoader
Parameters:
jobContext - Context of the job being run.
pool - Job Pool reference.
Returns:
Returns the final status of loading.

loadJobData

protected final boolean loadJobData(java.lang.Object jobData)
Loads the given job data into the job pool.This method is for the final loaders to load the job data into the pool.

Parameters:
jobData - Job data object that needs to be processed.
Returns:
Returns true if the job data is loaded into the pool, false otherwise.

stopLoading

protected final boolean stopLoading()
Tells whether the loading of the jobs needs to be stopped or not. Loader implementation should check for this flag before loading the jobs into the pool.

Returns:
Returns true if loader to be stopped, false continue loading the jobs.

resume

public boolean resume()
Resumes the loading of the jobs.

Specified by:
resume in interface PoolJobLoader
Returns:
Returns true if loader is resumed, false otherwise.

stop

public boolean stop()
Stops the loading of the jobs into the pool.

Specified by:
stop in interface PoolJobLoader
Returns:
Returns true if loader is stopped, false otherwise.

suspend

public boolean suspend()
Suspends loading of the jobs into the pool.

Specified by:
suspend in interface PoolJobLoader
Returns:
Returns true if loader is suspended, false otherwise.

getLoaderStatus

public ProcessorStatus getLoaderStatus()
Returns the status of the loader.

Specified by:
getLoaderStatus in interface PoolJobLoader
Returns:
Returns the status of the loader.

getLoaderState

public java.lang.Object getLoaderState()
Returns the processing state of the loader.

Specified by:
getLoaderState in interface PoolJobLoader
Returns:
Returns the job data that this loader is loading.

loadPool

public abstract ErrorCode loadPool(JobContext jobContext)

Load the job data into the pool that needs to be processed by job processor(s). Implementers can take the help of the loadJobData(Object) method defined here to load the jobs into the pool. Please see the example given in class description to how to implement the loadPool method.

Parameters:
jobContext - Context of the job being run.
Returns:
Returns the final status of the loader.

getTotalJobDataCount

public abstract long getTotalJobDataCount()
Returns the number of job data objects that this loader is going to load.

Specified by:
getTotalJobDataCount in interface PoolJobLoader
Returns:
Return the number of job data object its going to load.