magoffin.matt.ma2.biz.impl
Class WorkBizImpl

java.lang.Object
  extended by magoffin.matt.ma2.biz.impl.WorkBizImpl
All Implemented Interfaces:
WorkBiz

public class WorkBizImpl
extends java.lang.Object
implements WorkBiz

Implementation of WorkBiz that uses an ExecutorService to schedule the work in different threads.

The configurable properties of this class are:

executor
The ExecutorService to use for executing the submitted work in WorkBiz.submitWork(WorkRequest). If not configured,
completedJobMinRememberTimeMs
The length of time, in milliseconds, to maintain a reference to completed jobs. Defaults to 10 minutes.
delayedJobMaxRememberTimeMs
The length of time, in milliseconds, to maintain a refernce to a delayed job. If a delayed job is found to be delayed longer than this amount of time, it will be cancelled and removed.
scanJobTimerMs
The frequency at which to look for completed jobs to purge as well as delayed jobs to start. Completed jobs will have to be completed longer than completedJobMinRememberTimeMs milliseconds ago. Defaults to 2 minutes.
transactionManager
The PlatformTransactionManager to manage transactions with. Each job is executed in a transaction, either by joining an exiting one or starting a new one. If left null then no transactions will be used.
forceTransactionRollback
Force all transactions to be rolled back when the job completes. This can be used for testing. Defaults to false.

Version:
$Revision: 43 $ $Date: 2007-10-21 11:10:01 +1300 (Sun, 21 Oct 2007) $
Author:
matt.magoffin

Nested Class Summary
 
Nested classes/interfaces inherited from interface magoffin.matt.ma2.biz.WorkBiz
WorkBiz.WorkInfo, WorkBiz.WorkRequest
 
Field Summary
 
Fields inherited from interface magoffin.matt.ma2.biz.WorkBiz
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY
 
Constructor Summary
WorkBizImpl()
           
 
Method Summary
 void finish()
          Shutdown the work queue.
 long getCompletedJobMinRememberTimeMs()
           
 long getDelayedJobMaxRememberTimeMs()
           
 java.util.concurrent.ExecutorService getExecutor()
           
 WorkBiz.WorkInfo getInfo(long ticket)
          Get information about a running or recently running job.
 long getScanJobTimerMs()
           
 org.springframework.transaction.PlatformTransactionManager getTransactionManager()
           
 boolean infoExists(long ticket)
          Check for the existance of a running or recently complete job.
 void init()
          Initialize this instance.
 boolean isForceTransactionRollback()
           
 void setCompletedJobMinRememberTimeMs(long completedJobMinRememberTimeMs)
           
 void setDelayedJobMaxRememberTimeMs(long delayedJobMaxRememberTimeMs)
           
 void setExecutor(java.util.concurrent.ExecutorService executor)
           
 void setForceTransactionRollback(boolean forceTransactionRollback)
           
 void setScanJobTimerMs(long scanJobTimerMs)
           
 void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
           
 WorkBiz.WorkInfo submitWork(WorkBiz.WorkRequest work)
          Submit a work request for processing.
 boolean workReadyNow(long ticket)
          Signal that a particular job is ready to begin work now, presumably after being delayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkBizImpl

public WorkBizImpl()
Method Detail

init

public void init()
Initialize this instance.


finish

public void finish()
Shutdown the work queue.


submitWork

public WorkBiz.WorkInfo submitWork(WorkBiz.WorkRequest work)
Description copied from interface: WorkBiz
Submit a work request for processing.

Specified by:
submitWork in interface WorkBiz
Parameters:
work - the work to perform
Returns:
a WorkInfo detailing the status of the work

workReadyNow

public boolean workReadyNow(long ticket)
Description copied from interface: WorkBiz
Signal that a particular job is ready to begin work now, presumably after being delayed.

Specified by:
workReadyNow in interface WorkBiz
Parameters:
ticket - the work ticket number that is ready
Returns:
boolean if that work was found

getInfo

public WorkBiz.WorkInfo getInfo(long ticket)
Description copied from interface: WorkBiz
Get information about a running or recently running job.

If the job is still running calling this method must always return the work info. If the job has completed, it is up to the implementation of this API if the info is returned or not. For practical purposes implementations should be able to return information about completed jobs for a reasonable length of time after the job completes, to give time for clients to query the status of the job.

Note: calling this method might have side effects, like purging completed jobs. Use the WorkBiz.infoExists(long) method to test for the existance of a job without any of these potential side effects.

Specified by:
getInfo in interface WorkBiz
Parameters:
ticket - the work ticket number
Returns:
the WorkInfo for the requested ticket, or null if not available

infoExists

public boolean infoExists(long ticket)
Description copied from interface: WorkBiz
Check for the existance of a running or recently complete job.

This method can be used to check if a job is known, without any side-effects calling WorkBiz.getInfo(long) might include (such as resetting access statitics, purging a complete job, etc).

Specified by:
infoExists in interface WorkBiz
Parameters:
ticket - the work ticket number
Returns:
boolean if info is available for the given work ticket number

getExecutor

public java.util.concurrent.ExecutorService getExecutor()
Returns:
Returns the executor.

setExecutor

public void setExecutor(java.util.concurrent.ExecutorService executor)
Parameters:
executor - The executor to set.

getScanJobTimerMs

public long getScanJobTimerMs()
Returns:
Returns the scanJobTimerMs.

setScanJobTimerMs

public void setScanJobTimerMs(long scanJobTimerMs)
Parameters:
scanJobTimerMs - The scanJobTimerMs to set.

getCompletedJobMinRememberTimeMs

public long getCompletedJobMinRememberTimeMs()
Returns:
Returns the completedJobMinRememberTimeMs.

setCompletedJobMinRememberTimeMs

public void setCompletedJobMinRememberTimeMs(long completedJobMinRememberTimeMs)
Parameters:
completedJobMinRememberTimeMs - The completedJobMinRememberTimeMs to set.

getTransactionManager

public org.springframework.transaction.PlatformTransactionManager getTransactionManager()
Returns:
Returns the transactionManager.

setTransactionManager

public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
Parameters:
transactionManager - The transactionManager to set.

isForceTransactionRollback

public boolean isForceTransactionRollback()
Returns:
Returns the forceTransactionRollback.

setForceTransactionRollback

public void setForceTransactionRollback(boolean forceTransactionRollback)
Parameters:
forceTransactionRollback - The forceTransactionRollback to set.

getDelayedJobMaxRememberTimeMs

public long getDelayedJobMaxRememberTimeMs()
Returns:
the delayedJobMaxRememberTimeMs

setDelayedJobMaxRememberTimeMs

public void setDelayedJobMaxRememberTimeMs(long delayedJobMaxRememberTimeMs)
Parameters:
delayedJobMaxRememberTimeMs - the delayedJobMaxRememberTimeMs to set