Package org.apache.ofbiz.service.job
Class JobManager
java.lang.Object
org.apache.ofbiz.service.job.JobManager
Job manager. The job manager queues and manages jobs. Client code can queue a job to be run immediately
by calling the
runJob(Job)
method, or schedule a job to be run later by calling the
schedule(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
-
Method Summary
Modifier and TypeMethodDescriptionReturns the Delegator.Returns the LocalDispatcher.static JobManager
getInstance
(Delegator delegator, boolean enablePoller) Returns aJobManager
instance.static List<GenericValue>
getJobsToPurge
(Delegator delegator, String poolId, String instanceId, int limit, Timestamp purgeTime) Get a List of each threads current state.boolean
Return true if the jobManager can run job.poll
(int limit) Scans the JobSandbox entity and returns a list of jobs that are due to run.void
void
Queues a Job to run now.void
Schedule a job to start at a specific time with specific recurrence infovoid
schedule
(String jobName, String poolName, String serviceName, 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
(String jobName, String poolName, String serviceName, Map<String, ? extends 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
(String poolName, String serviceName, Map<String, ? extends 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
(String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, int count) Schedule a job to start at a specific time with specific recurrence infovoid
schedule
(String serviceName, Map<String, ? extends 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
(String serviceName, Map<String, ? extends 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.
-
Field Details
-
INSTANCE_ID
-
-
Method Details
-
getInstance
Returns aJobManager
instance.- Parameters:
delegator
- the delegatorenablePoller
- Enables polling of the JobSandbox entity.- Returns:
- the instance
- Throws:
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
Returns the Delegator. -
getDispatcher
Returns the LocalDispatcher. -
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
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. -
getJobsToPurge
public static List<GenericValue> getJobsToPurge(Delegator delegator, String poolId, String instanceId, int limit, Timestamp purgeTime) throws GenericEntityException - Throws:
GenericEntityException
-
reloadCrashedJobs
public void reloadCrashedJobs() -
runJob
Queues a Job to run now.- Throws:
IllegalStateException
- if the Job Manager is shut down.JobManagerException
-
schedule
public void schedule(String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, int count) throws JobManagerExceptionSchedule 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
- the job manager exception
-
schedule
public void schedule(String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerExceptionSchedule 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
- the job manager exception
-
schedule
public void schedule(String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, long endTime) throws JobManagerExceptionSchedule 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
- the job manager exception
-
schedule
public void schedule(String poolName, String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, int count, long endTime) throws JobManagerExceptionSchedule 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
- the job manager exception
-
schedule
public void schedule(String poolName, String serviceName, 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
- the job manager exception
-
schedule
public void schedule(String jobName, String poolName, String serviceName, Map<String, ? extends Object> context, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws JobManagerExceptionSchedule 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
- the job manager exception
-
schedule
public void schedule(String jobName, String poolName, String serviceName, 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:
JobManagerException
- the job manager exception
-