Class 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 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

      Fields 
      Modifier and Type Field Description
      static java.lang.String INSTANCE_ID  
    • 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 a JobManager 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 info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      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)
      Schedule a job to start at a specific time with specific recurrence info
      static void shutDown()
      Shuts down all job managers.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE_ID

        public static final java.lang.String INSTANCE_ID
    • Method Detail

      • getInstance

        public static JobManager getInstance​(Delegator delegator,
                                             boolean enablePoller)
        Returns a JobManager instance.
        Parameters:
        delegator - the delegator
        enablePoller - Enables polling of the JobSandbox entity.
        Returns:
        the instance
        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 the JobPoller polling thread.
      • reloadCrashedJobs

        public void reloadCrashedJobs()
      • 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 invoke
        context - The context for the service
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        count - The number of times to repeat
        Throws:
        JobManagerException - the job manager exception
      • 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 invoke
        context - The context for the service
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        count - The number of times to repeat
        endTime - The time in milliseconds the service should expire
        Throws:
        JobManagerException - the job manager exception
      • 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 invoke
        context - The context for the service
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        endTime - The time in milliseconds the service should expire
        Throws:
        JobManagerException - the job manager exception
      • 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 from
        serviceName - The name of the service to invoke
        context - The context for the service
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        count - The number of times to repeat
        endTime - The time in milliseconds the service should expire
        Throws:
        JobManagerException - the job manager exception
      • 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 from
        serviceName - The name of the service to invoke
        dataId - The persisted context (RuntimeData.runtimeDataId)
        startTime - The time in milliseconds the service should run
        Throws:
        JobManagerException - the job manager exception
      • 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 job
        poolName - The name of the pool to run the service from
        serviceName - The name of the service to invoke
        context - The context for the service
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        count - The number of times to repeat
        endTime - The time in milliseconds the service should expire
        maxRetry - The max number of retries on failure (-1 for no max)
        Throws:
        JobManagerException - the job manager exception
      • 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 job
        poolName - The name of the pool to run the service from
        serviceName - The name of the service to invoke
        dataId - The persisted context (RuntimeData.runtimeDataId)
        startTime - The time in milliseconds the service should run
        frequency - The frequency of the recurrence (HOURLY, DAILY, MONTHLY etc)
        interval - The interval of the frequency recurrence
        count - The number of times to repeat
        endTime - The time in milliseconds the service should expire
        maxRetry - The max number of retries on failure (-1 for no max)
        Throws:
        JobManagerException - the job manager exception