Package org.apache.ofbiz.service.job
Class JobManager
- java.lang.Object
-
- org.apache.ofbiz.service.job.JobManager
-
public final class JobManager extends java.lang.Object
Job manager. The job manager queues and manages jobs. Client code can queue a job to be run immediately by calling therunJob(Job)
method, or schedule a job to be run later by calling theschedule(String, String, String, Map, long, int, int, int, long, int)
method. Scheduled jobs are persisted in the JobSandbox entity.A scheduled job's start time is an approximation - the actual start time will depend on the job manager/job poller configuration (poll interval) and the load on the server. Scheduled jobs might be rescheduled if the server is busy. Therefore, applications requiring a precise job start time should use a different mechanism to schedule the job.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
instanceId
static java.lang.String
module
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Delegator
getDelegator()
Returns the Delegator.LocalDispatcher
getDispatcher()
Returns the LocalDispatcher.static JobManager
getInstance(Delegator delegator, boolean enablePoller)
Returns aJobManager
instance.java.util.Map<java.lang.String,java.lang.Object>
getPoolState()
Get a List of each threads current state.boolean
isAvailable()
Return true if the jobManager can run job.protected java.util.List<Job>
poll(int limit)
Scans the JobSandbox entity and returns a list of jobs that are due to run.void
reloadCrashedJobs()
void
runJob(Job job)
Queues a Job to run now.void
schedule(java.lang.String poolName, java.lang.String serviceName, java.lang.String dataId, long startTime)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String jobName, java.lang.String poolName, java.lang.String serviceName, java.lang.String dataId, long startTime, int frequency, int interval, int count, long endTime, int maxRetry)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String jobName, java.lang.String poolName, java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime, int maxRetry)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String poolName, java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime)
Schedule a job to start at a specific time with specific recurrence infovoid
schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, long endTime)
Schedule a job to start at a specific time with specific recurrence infostatic void
shutDown()
Shuts down all job managers.
-
-
-
Method Detail
-
getInstance
public static JobManager getInstance(Delegator delegator, boolean enablePoller)
Returns aJobManager
instance.- Parameters:
delegator
-enablePoller
- Enables polling of the JobSandbox entity.- Throws:
java.lang.IllegalStateException
- if the Job Manager is shut down.
-
shutDown
public static void shutDown()
Shuts down all job managers. This method is called when OFBiz shuts down.
-
getDelegator
public Delegator getDelegator()
Returns the Delegator.
-
getDispatcher
public LocalDispatcher getDispatcher()
Returns the LocalDispatcher.
-
getPoolState
public java.util.Map<java.lang.String,java.lang.Object> getPoolState()
Get a List of each threads current state.- Returns:
- List containing a Map of each thread's state.
-
isAvailable
public boolean isAvailable()
Return true if the jobManager can run job.- Returns:
- boolean.
-
poll
protected java.util.List<Job> poll(int limit)
Scans the JobSandbox entity and returns a list of jobs that are due to run. Returns an empty list if there are no jobs due to run. This method is called by theJobPoller
polling thread.
-
reloadCrashedJobs
public void reloadCrashedJobs()
-
runJob
public void runJob(Job job) throws JobManagerException
Queues a Job to run now.- Throws:
java.lang.IllegalStateException
- if the Job Manager is shut down.java.util.concurrent.RejectedExecutionException
- if the poller is stopped.JobManagerException
-
schedule
public void schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
serviceName
- The name of the service to invokecontext
- The context for the servicestartTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrencecount
- The number of times to repeat- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
serviceName
- The name of the service to invokecontext
- The context for the servicestartTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrencecount
- The number of times to repeatendTime
- The time in milliseconds the service should expire- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, long endTime) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
serviceName
- The name of the service to invokecontext
- The context for the servicestartTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrenceendTime
- The time in milliseconds the service should expire- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String poolName, java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
poolName
- The name of the pool to run the service fromserviceName
- The name of the service to invokecontext
- The context for the servicestartTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrencecount
- The number of times to repeatendTime
- The time in milliseconds the service should expire- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String poolName, java.lang.String serviceName, java.lang.String dataId, long startTime) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
poolName
- The name of the pool to run the service fromserviceName
- The name of the service to invokedataId
- The persisted context (RuntimeData.runtimeDataId)startTime
- The time in milliseconds the service should run- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String jobName, java.lang.String poolName, java.lang.String serviceName, java.util.Map<java.lang.String,? extends java.lang.Object> context, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
jobName
- The name of the jobpoolName
- The name of the pool to run the service fromserviceName
- The name of the service to invokecontext
- The context for the servicestartTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrencecount
- The number of times to repeatendTime
- The time in milliseconds the service should expiremaxRetry
- The max number of retries on failure (-1 for no max)- Throws:
JobManagerException
-
schedule
public void schedule(java.lang.String jobName, java.lang.String poolName, java.lang.String serviceName, java.lang.String dataId, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws JobManagerException
Schedule a job to start at a specific time with specific recurrence info- Parameters:
jobName
- The name of the jobpoolName
- The name of the pool to run the service fromserviceName
- The name of the service to invokedataId
- The persisted context (RuntimeData.runtimeDataId)startTime
- The time in milliseconds the service should runfrequency
- The frequency of the recurrence (HOURLY,DAILY,MONTHLY,etc)interval
- The interval of the frequency recurrencecount
- The number of times to repeatendTime
- The time in milliseconds the service should expiremaxRetry
- The max number of retries on failure (-1 for no max)- Throws:
java.lang.IllegalStateException
- if the Job Manager is shut down.JobManagerException
-
-