com.wm.app.tn.delivery
Class JobMgr

java.lang.Object
  extended by com.wm.app.tn.delivery.JobMgr
All Implemented Interfaces:
java.lang.Runnable

public class JobMgr
extends java.lang.Object
implements java.lang.Runnable

Implemented as a singleton in order to provide only one job store, job list and background processing thread (for job processing and expiration).


Method Summary
 void access()
          Register with the job manager
 void changeServerForJob(java.lang.String jobId, java.lang.String serverId)
          Changes the job from one server to another server.
 void changeSweepTime(long t)
          Change the time to wait between runs of the main processing thread.
 boolean enabled()
          Job manager singleton has been initialized and is referenced.
 int getActiveJobCount()
           
 GuaranteedJob getAnyJob(java.lang.String jobId, boolean content)
          Used to get any GuaranteedJob regardless of the server it is on.
 GuaranteedJob getJob(java.lang.String jobId, boolean content)
           
 java.lang.String[] getJobIds()
           
static JobMgr getJobMgr()
          Use this method to get a handle to the job manager in order to manage jobs.
 com.wm.data.IData getJobOutput(java.lang.String jobId, long maxWaitTime)
          Gets the output of a job.
 java.lang.String getJobStatus(java.lang.String jobId)
           
 int getMaxJobs()
           
 double getMaxThreadPoolPct()
           
 java.lang.String getServerId()
           
 long getSweepTime()
           
 boolean hasJobs()
           
static JobMgr init()
          Initialize the singleton job manager if not already initialized and start background thread.
 boolean jobExists(java.lang.String jobId)
           
 void release()
          Deregister from job manager.
 void removeJob(java.lang.String jobId)
          Remove a job from the job manager.
 void reset()
          Reset the job manager.
 void restartJob(java.lang.String jobId)
          Restart a job that has failed or been stopped.
 void run()
          Background Thread
 void setMaxThreadPoolPct(double max)
          Sets the portion of the server's threadpool that will be used by the JobMgr.
 boolean shutdown(boolean force)
          Terminate the job manager if no users are registered or if force is specified.
 int size()
           
 void startDbUpdaterThread()
           
 void startJob(GuaranteedJob job, boolean hold)
          Start a new job
 void stopJob(java.lang.String jobId)
          Stop a job that is running.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static JobMgr init()
                   throws DeliveryException
Initialize the singleton job manager if not already initialized and start background thread.

Throws:
DeliveryException - Unable to initialize job manager

access

public void access()
Register with the job manager


getJobMgr

public static JobMgr getJobMgr()
Use this method to get a handle to the job manager in order to manage jobs.


getServerId

public java.lang.String getServerId()
Returns:
server id associated with the job manager

changeSweepTime

public void changeSweepTime(long t)
Change the time to wait between runs of the main processing thread. Value is saved to the tn.task.sweepTime property.

Parameters:
t - Time to wait (in seconds). If 0 (zero), the current value of tn.task.sweepTime is used.

getSweepTime

public long getSweepTime()

release

public void release()
Deregister from job manager.


enabled

public boolean enabled()
Job manager singleton has been initialized and is referenced.

Returns:
Job manager initialized and referenced

reset

public void reset()
           throws DeliveryException
Reset the job manager.

Throws:
DeliveryException

shutdown

public boolean shutdown(boolean force)
                 throws DeliveryException
Terminate the job manager if no users are registered or if force is specified.

Parameters:
force - force a shutdown even if jobs are being processed
Returns:
true if shutdown successful
Throws:
DeliveryException - Active jobs without a forceful shutdown

changeServerForJob

public void changeServerForJob(java.lang.String jobId,
                               java.lang.String serverId)
                        throws DeliveryException
Changes the job from one server to another server. In order to move the job in a clustered environment the original server must be down AND the job not DONE else the job must be FAILED. If not clustered then the job cannot be DONE.

Parameters:
jobId - id of the job to move
serverId - id of the server to move the job to
Throws:
DeliveryException

getJobIds

public java.lang.String[] getJobIds()
Returns:
an array of job Ids

getJob

public GuaranteedJob getJob(java.lang.String jobId,
                            boolean content)
Parameters:
jobId - Id of job to retrieve
content - indicate whether or not to retrieve the content of the associated bizdoc
Returns:
a delivery job (possibly null)

getAnyJob

public GuaranteedJob getAnyJob(java.lang.String jobId,
                               boolean content)
Used to get any GuaranteedJob regardless of the server it is on. This is an admin level type call as it may have to go the database to retrieve instead of the job cache.

Parameters:
jobId - Id of job to retrieve
content - indicate whether or not to retrieve the content of the associated bizdoc
Returns:
a delivery job (possibly null)

getJobOutput

public com.wm.data.IData getJobOutput(java.lang.String jobId,
                                      long maxWaitTime)
                               throws DeliveryException
Gets the output of a job. The job must be completed (eg, DONE or FAILED) in order to get output from it. A timeout can be specified to wait for a job to finish. A timeout of 0 can be used for asynchronous (eg, return immediately) or something > 0 to wait. If the job still has not completed after the maximum wait time then an exception is thrown.

Parameters:
jobId - Id of job to retrieve output from
maxWaitTime - maximum time (in millisec) to block waiting for job output
Returns:
the output (if any, possibly null) from the job
Throws:
DeliveryException

getJobStatus

public java.lang.String getJobStatus(java.lang.String jobId)
                              throws DeliveryException
Parameters:
jobId - id of the job to check
Returns:
the status of a job (possibly null if job doesnt exist)
Throws:
DeliveryException

hasJobs

public boolean hasJobs()
Returns:
true if there are jobs being processed

jobExists

public boolean jobExists(java.lang.String jobId)
Parameters:
jobId - id of job
Returns:
true if job exists

removeJob

public void removeJob(java.lang.String jobId)
               throws DeliveryException
Remove a job from the job manager.

Parameters:
jobId - id of the job to remove
Throws:
DeliveryException

restartJob

public void restartJob(java.lang.String jobId)
                throws DeliveryException
Restart a job that has failed or been stopped.

Parameters:
jobId - id of the job to restart
Throws:
DeliveryException

startJob

public void startJob(GuaranteedJob job,
                     boolean hold)
              throws DeliveryException
Start a new job

Parameters:
job - GuaranteedJob to be run
hold - boolean - indicating whether the job is to be held as the profile is set for Routing being switched off
Throws:
com.wm.tn.app.delivery.DeliveryException
DeliveryException

stopJob

public void stopJob(java.lang.String jobId)
             throws DeliveryException
Stop a job that is running. Job status must be NEW or PENDING.

Parameters:
jobId - id of the job to stop
Throws:
com.wm.tn.app.delivery.DeliveryException
DeliveryException

size

public int size()
Returns:
number of jobs being processed

getActiveJobCount

public int getActiveJobCount()

getMaxThreadPoolPct

public double getMaxThreadPoolPct()

getMaxJobs

public int getMaxJobs()

setMaxThreadPoolPct

public void setMaxThreadPoolPct(double max)
Sets the portion of the server's threadpool that will be used by the JobMgr. In effect, this is the number of jobs that can be processed at once. This is the value of the tn.task.threadpool.pct property.

Parameters:
max - Specify a value from .25 to .8. If max is too small or too large, its value is reset to .25 or .8 and a warning is logged. If you pass 0 (zero), the value will be read from tn.task.threadpool.pct.

run

public void run()
Background Thread

Specified by:
run in interface java.lang.Runnable

startDbUpdaterThread

public void startDbUpdaterThread()