Class DirectSchedulerFactory

  • All Implemented Interfaces:
    SchedulerFactory

    public class DirectSchedulerFactory
    extends java.lang.Object
    implements SchedulerFactory

    A singleton implementation of SchedulerFactory.

    Here are some examples of using this class:

    To create a scheduler that does not write anything to the database (is not persistent), you can call createVolatileScheduler:

      DirectSchedulerFactory.getInstance().createVolatileScheduler(10); // 10 threads * // don't forget to start the scheduler: DirectSchedulerFactory.getInstance().getScheduler().start();
     

    Several create methods are provided for convenience. All create methods eventually end up calling the create method with all the parameters:

      public void createScheduler(String schedulerName, String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore, String rmiRegistryHost, int rmiRegistryPort)
     

    Here is an example of using this method:

    * *
    // create the thread pool SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, Thread.NORM_PRIORITY); threadPool.initialize(); * // create the job store JobStore jobStore = new RAMJobStore();
    
      DirectSchedulerFactory.getInstance().createScheduler("My Quartz Scheduler", "My Instance", threadPool, jobStore, "localhost", 1099); * // don't forget to start the scheduler: DirectSchedulerFactory.getInstance().getScheduler("My Quartz Scheduler", "My Instance").start();
     

    You can also use a JDBCJobStore instead of the RAMJobStore:

      DBConnectionManager.getInstance().addConnectionProvider("someDatasource", new JNDIConnectionProvider("someDatasourceJNDIName"));
    
      JobStoreTX jdbcJobStore = new JobStoreTX(); jdbcJobStore.setDataSource("someDatasource"); jdbcJobStore.setPostgresStyleBlobs(true); jdbcJobStore.setTablePrefix("QRTZ_"); jdbcJobStore.setInstanceId("My Instance");
     
    Author:
    Mohammad Rezaei, James House
    See Also:
    JobStore, ThreadPool
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DirectSchedulerFactory()
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void createRemoteScheduler​(java.lang.String rmiHost, int rmiPort)
      Creates a proxy to a remote scheduler.
      void createRemoteScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, java.lang.String rmiHost, int rmiPort)
      Same as createRemoteScheduler(String rmiHost, int rmiPort), with the addition of specifying the scheduler name and instance ID.
      void createRemoteScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, java.lang.String rmiBindName, java.lang.String rmiHost, int rmiPort)
      Same as createRemoteScheduler(String rmiHost, int rmiPort), with the addition of specifying the scheduler name, instance ID, and rmi bind name.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore)
      Same as createScheduler(ThreadPool threadPool, JobStore jobStore), with the addition of specifying the scheduler name and instance ID.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore, java.lang.String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval)
      Creates a scheduler using the specified thread pool and job store and binds it to RMI.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore, java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap, java.lang.String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval, boolean jmxExport, java.lang.String jmxObjectName)
      Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, ThreadExecutor threadExecutor, JobStore jobStore, java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap, java.lang.String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval, boolean jmxExport, java.lang.String jmxObjectName)
      Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, ThreadExecutor threadExecutor, JobStore jobStore, java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap, java.lang.String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval, boolean jmxExport, java.lang.String jmxObjectName, int maxBatchSize, long batchTimeWindow)
      Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
      void createScheduler​(java.lang.String schedulerName, java.lang.String schedulerInstanceId, ThreadPool threadPool, ThreadExecutor threadExecutor, JobStore jobStore, java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap, java.lang.String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval, boolean jmxExport, java.lang.String jmxObjectName, int maxBatchSize, long batchTimeWindow, boolean makeSchedThreadDaemon)
      Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
      void createScheduler​(ThreadPool threadPool, JobStore jobStore)
      Creates a scheduler using the specified thread pool and job store.
      void createVolatileScheduler​(int maxThreads)
      Creates an in memory job store (RAMJobStore) The thread priority is set to Thread.NORM_PRIORITY
      java.util.Collection<Scheduler> getAllSchedulers()
      Returns a handle to all known Schedulers (made by any StdSchedulerFactory instance.).
      static DirectSchedulerFactory getInstance()  
      protected org.slf4j.Logger getLog()  
      Scheduler getScheduler()
      Returns a handle to the Scheduler produced by this factory.
      Scheduler getScheduler​(java.lang.String schedName)
      Returns a handle to the Scheduler with the given name, if it exists.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_INSTANCE_ID

        public static final java.lang.String DEFAULT_INSTANCE_ID
        See Also:
        Constant Field Values
      • DEFAULT_SCHEDULER_NAME

        public static final java.lang.String DEFAULT_SCHEDULER_NAME
        See Also:
        Constant Field Values
    • Constructor Detail

      • DirectSchedulerFactory

        protected DirectSchedulerFactory()
        Constructor
    • Method Detail

      • getLog

        protected org.slf4j.Logger getLog()
      • createVolatileScheduler

        public void createVolatileScheduler​(int maxThreads)
                                     throws SchedulerException
        Creates an in memory job store (RAMJobStore) The thread priority is set to Thread.NORM_PRIORITY
        Parameters:
        maxThreads - The number of threads in the thread pool
        Throws:
        SchedulerException - if initialization failed.
      • createRemoteScheduler

        public void createRemoteScheduler​(java.lang.String rmiHost,
                                          int rmiPort)
                                   throws SchedulerException
        Creates a proxy to a remote scheduler. This scheduler can be retrieved via getScheduler()
        Parameters:
        rmiHost - The hostname for remote scheduler
        rmiPort - Port for the remote scheduler. The default RMI port is 1099.
        Throws:
        SchedulerException - if the remote scheduler could not be reached.
      • createRemoteScheduler

        public void createRemoteScheduler​(java.lang.String schedulerName,
                                          java.lang.String schedulerInstanceId,
                                          java.lang.String rmiHost,
                                          int rmiPort)
                                   throws SchedulerException
        Same as createRemoteScheduler(String rmiHost, int rmiPort), with the addition of specifying the scheduler name and instance ID. This scheduler can only be retrieved via getScheduler(String)
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        rmiHost - The hostname for remote scheduler
        rmiPort - Port for the remote scheduler. The default RMI port is 1099.
        Throws:
        SchedulerException - if the remote scheduler could not be reached.
      • createRemoteScheduler

        public void createRemoteScheduler​(java.lang.String schedulerName,
                                          java.lang.String schedulerInstanceId,
                                          java.lang.String rmiBindName,
                                          java.lang.String rmiHost,
                                          int rmiPort)
                                   throws SchedulerException
        Same as createRemoteScheduler(String rmiHost, int rmiPort), with the addition of specifying the scheduler name, instance ID, and rmi bind name. This scheduler can only be retrieved via getScheduler(String)
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        rmiBindName - The name of the remote scheduler in the RMI repository. If null defaults to the generated unique identifier.
        rmiHost - The hostname for remote scheduler
        rmiPort - Port for the remote scheduler. The default RMI port is 1099.
        Throws:
        SchedulerException - if the remote scheduler could not be reached.
      • createScheduler

        public void createScheduler​(ThreadPool threadPool,
                                    JobStore jobStore)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool and job store. This scheduler can be retrieved via getScheduler()
        Parameters:
        threadPool - The thread pool for executing jobs
        jobStore - The type of job store
        Throws:
        SchedulerException - if initialization failed
      • createScheduler

        public void createScheduler​(java.lang.String schedulerName,
                                    java.lang.String schedulerInstanceId,
                                    ThreadPool threadPool,
                                    JobStore jobStore,
                                    java.lang.String rmiRegistryHost,
                                    int rmiRegistryPort,
                                    long idleWaitTime,
                                    long dbFailureRetryInterval)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool and job store and binds it to RMI.
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        threadPool - The thread pool for executing jobs
        jobStore - The type of job store
        rmiRegistryHost - The hostname to register this scheduler with for RMI. Can use "null" if no RMI is required.
        rmiRegistryPort - The port for RMI. Typically 1099.
        idleWaitTime - The idle wait time in milliseconds. You can specify "-1" for the default value, which is currently 30000 ms.
        Throws:
        SchedulerException - if initialization failed
      • createScheduler

        public void createScheduler​(java.lang.String schedulerName,
                                    java.lang.String schedulerInstanceId,
                                    ThreadPool threadPool,
                                    JobStore jobStore,
                                    java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap,
                                    java.lang.String rmiRegistryHost,
                                    int rmiRegistryPort,
                                    long idleWaitTime,
                                    long dbFailureRetryInterval,
                                    boolean jmxExport,
                                    java.lang.String jmxObjectName)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        threadPool - The thread pool for executing jobs
        jobStore - The type of job store
        schedulerPluginMap - Map from a String plugin names to SchedulerPlugins. Can use "null" if no plugins are required.
        rmiRegistryHost - The hostname to register this scheduler with for RMI. Can use "null" if no RMI is required.
        rmiRegistryPort - The port for RMI. Typically 1099.
        idleWaitTime - The idle wait time in milliseconds. You can specify "-1" for the default value, which is currently 30000 ms.
        Throws:
        SchedulerException - if initialization failed
      • createScheduler

        public void createScheduler​(java.lang.String schedulerName,
                                    java.lang.String schedulerInstanceId,
                                    ThreadPool threadPool,
                                    ThreadExecutor threadExecutor,
                                    JobStore jobStore,
                                    java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap,
                                    java.lang.String rmiRegistryHost,
                                    int rmiRegistryPort,
                                    long idleWaitTime,
                                    long dbFailureRetryInterval,
                                    boolean jmxExport,
                                    java.lang.String jmxObjectName)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        threadPool - The thread pool for executing jobs
        threadExecutor - The thread executor for executing jobs
        jobStore - The type of job store
        schedulerPluginMap - Map from a String plugin names to SchedulerPlugins. Can use "null" if no plugins are required.
        rmiRegistryHost - The hostname to register this scheduler with for RMI. Can use "null" if no RMI is required.
        rmiRegistryPort - The port for RMI. Typically 1099.
        idleWaitTime - The idle wait time in milliseconds. You can specify "-1" for the default value, which is currently 30000 ms.
        Throws:
        SchedulerException - if initialization failed
      • createScheduler

        public void createScheduler​(java.lang.String schedulerName,
                                    java.lang.String schedulerInstanceId,
                                    ThreadPool threadPool,
                                    ThreadExecutor threadExecutor,
                                    JobStore jobStore,
                                    java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap,
                                    java.lang.String rmiRegistryHost,
                                    int rmiRegistryPort,
                                    long idleWaitTime,
                                    long dbFailureRetryInterval,
                                    boolean jmxExport,
                                    java.lang.String jmxObjectName,
                                    int maxBatchSize,
                                    long batchTimeWindow)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        threadPool - The thread pool for executing jobs
        threadExecutor - The thread executor for executing jobs
        jobStore - The type of job store
        schedulerPluginMap - Map from a String plugin names to SchedulerPlugins. Can use "null" if no plugins are required.
        rmiRegistryHost - The hostname to register this scheduler with for RMI. Can use "null" if no RMI is required.
        rmiRegistryPort - The port for RMI. Typically 1099.
        idleWaitTime - The idle wait time in milliseconds. You can specify "-1" for the default value, which is currently 30000 ms.
        maxBatchSize - The maximum batch size of triggers, when acquiring them
        batchTimeWindow - The time window for which it is allowed to "pre-acquire" triggers to fire
        Throws:
        SchedulerException - if initialization failed
      • createScheduler

        public void createScheduler​(java.lang.String schedulerName,
                                    java.lang.String schedulerInstanceId,
                                    ThreadPool threadPool,
                                    ThreadExecutor threadExecutor,
                                    JobStore jobStore,
                                    java.util.Map<java.lang.String,​SchedulerPlugin> schedulerPluginMap,
                                    java.lang.String rmiRegistryHost,
                                    int rmiRegistryPort,
                                    long idleWaitTime,
                                    long dbFailureRetryInterval,
                                    boolean jmxExport,
                                    java.lang.String jmxObjectName,
                                    int maxBatchSize,
                                    long batchTimeWindow,
                                    boolean makeSchedThreadDaemon)
                             throws SchedulerException
        Creates a scheduler using the specified thread pool, job store, and plugins, and binds it to RMI.
        Parameters:
        schedulerName - The name for the scheduler.
        schedulerInstanceId - The instance ID for the scheduler.
        threadPool - The thread pool for executing jobs
        threadExecutor - The thread executor for executing jobs
        jobStore - The type of job store
        schedulerPluginMap - Map from a String plugin names to SchedulerPlugins. Can use "null" if no plugins are required.
        rmiRegistryHost - The hostname to register this scheduler with for RMI. Can use "null" if no RMI is required.
        rmiRegistryPort - The port for RMI. Typically 1099.
        idleWaitTime - The idle wait time in milliseconds. You can specify "-1" for the default value, which is currently 30000 ms.
        maxBatchSize - The maximum batch size of triggers, when acquiring them
        batchTimeWindow - The time window for which it is allowed to "pre-acquire" triggers to fire
        makeSchedThreadDaemon - Make the SchedulerThread a daemon thread.
        Throws:
        SchedulerException - if initialization failed
      • getScheduler

        public Scheduler getScheduler()
                               throws SchedulerException

        Returns a handle to the Scheduler produced by this factory.

        you must call createRemoteScheduler or createScheduler methods before calling getScheduler()

        Specified by:
        getScheduler in interface SchedulerFactory
        Throws:
        SchedulerException - if there is a problem with the underlying Scheduler.