Search in sources :

Example 6 with ClassLoadHelper

use of org.quartz.spi.ClassLoadHelper in project weicoder by wdcode.

the class CascadingClassLoadHelper method getResourceAsStream.

/**
 * Finds a resource with a given name. This method returns null if no
 * resource with this name is found.
 * @param name name of the desired resource
 * @return a java.io.InputStream object
 */
public InputStream getResourceAsStream(String name) {
    InputStream result = null;
    if (bestCandidate != null) {
        result = bestCandidate.getResourceAsStream(name);
        if (result == null) {
            bestCandidate = null;
        } else {
            return result;
        }
    }
    ClassLoadHelper loadHelper = null;
    Iterator<ClassLoadHelper> iter = loadHelpers.iterator();
    while (iter.hasNext()) {
        loadHelper = iter.next();
        result = loadHelper.getResourceAsStream(name);
        if (result != null) {
            break;
        }
    }
    bestCandidate = loadHelper;
    return result;
}
Also used : InputStream(java.io.InputStream) ClassLoadHelper(org.quartz.spi.ClassLoadHelper)

Example 7 with ClassLoadHelper

use of org.quartz.spi.ClassLoadHelper in project weicoder by wdcode.

the class DirectSchedulerFactory method createScheduler.

/**
 * Creates a scheduler using the specified thread pool, job store, and
 * plugins, and binds it to RMI.
 *
 * @param schedulerName
 *          The name for the scheduler.
 * @param schedulerInstanceId
 *          The instance ID for the scheduler.
 * @param threadPool
 *          The thread pool for executing jobs
 * @param threadExecutor
 *          The thread executor for executing jobs
 * @param jobStore
 *          The type of job store
 * @param schedulerPluginMap
 *          Map from a <code>String</code> plugin names to
 *          <code>{@link org.quartz.spi.SchedulerPlugin}</code>s.  Can use
 *          "null" if no plugins are required.
 * @param rmiRegistryHost
 *          The hostname to register this scheduler with for RMI. Can use
 *          "null" if no RMI is required.
 * @param rmiRegistryPort
 *          The port for RMI. Typically 1099.
 * @param idleWaitTime
 *          The idle wait time in milliseconds. You can specify "-1" for
 *          the default value, which is currently 30000 ms.
 * @param maxBatchSize
 *          The maximum batch size of triggers, when acquiring them
 * @param batchTimeWindow
 *          The time window for which it is allowed to "pre-acquire" triggers to fire
 * @throws SchedulerException
 *           if initialization failed
 */
public void createScheduler(String schedulerName, String schedulerInstanceId, ThreadPool threadPool, ThreadExecutor threadExecutor, JobStore jobStore, Map<String, SchedulerPlugin> schedulerPluginMap, String rmiRegistryHost, int rmiRegistryPort, long idleWaitTime, long dbFailureRetryInterval, boolean jmxExport, String jmxObjectName, int maxBatchSize, long batchTimeWindow) throws SchedulerException {
    // Currently only one run-shell factory is available...
    JobRunShellFactory jrsf = new StdJobRunShellFactory();
    // Fire everything up
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    threadPool.setInstanceName(schedulerName);
    threadPool.initialize();
    QuartzSchedulerResources qrs = new QuartzSchedulerResources();
    qrs.setName(schedulerName);
    qrs.setInstanceId(schedulerInstanceId);
    SchedulerDetailsSetter.setDetails(threadPool, schedulerName, schedulerInstanceId);
    qrs.setJobRunShellFactory(jrsf);
    qrs.setThreadPool(threadPool);
    qrs.setThreadExecutor(threadExecutor);
    qrs.setJobStore(jobStore);
    qrs.setMaxBatchSize(maxBatchSize);
    qrs.setBatchTimeWindow(batchTimeWindow);
    qrs.setRMIRegistryHost(rmiRegistryHost);
    qrs.setRMIRegistryPort(rmiRegistryPort);
    qrs.setJMXExport(jmxExport);
    if (jmxObjectName != null) {
        qrs.setJMXObjectName(jmxObjectName);
    }
    // add plugins
    if (schedulerPluginMap != null) {
        for (Iterator<SchedulerPlugin> pluginIter = schedulerPluginMap.values().iterator(); pluginIter.hasNext(); ) {
            qrs.addSchedulerPlugin(pluginIter.next());
        }
    }
    QuartzScheduler qs = new QuartzScheduler(qrs, idleWaitTime, dbFailureRetryInterval);
    ClassLoadHelper cch = new CascadingClassLoadHelper();
    cch.initialize();
    SchedulerDetailsSetter.setDetails(jobStore, schedulerName, schedulerInstanceId);
    jobStore.initialize(cch, qs.getSchedulerSignaler());
    Scheduler scheduler = new StdScheduler(qs);
    jrsf.initialize(scheduler);
    qs.initialize();
    // Initialize plugins now that we have a Scheduler instance.
    if (schedulerPluginMap != null) {
        for (Iterator<Entry<String, SchedulerPlugin>> pluginEntryIter = schedulerPluginMap.entrySet().iterator(); pluginEntryIter.hasNext(); ) {
            Entry<String, SchedulerPlugin> pluginEntry = pluginEntryIter.next();
            pluginEntry.getValue().initialize(pluginEntry.getKey(), scheduler, cch);
        }
    }
    getLog().info("Quartz scheduler '" + scheduler.getSchedulerName());
    getLog().info("Quartz scheduler version: " + qs.getVersion());
    SchedulerRepository schedRep = SchedulerRepository.getInstance();
    // prevents the repository from being
    qs.addNoGCObject(schedRep);
    // garbage collected
    schedRep.bind(scheduler);
    initialized = true;
}
Also used : SchedulerPlugin(org.quartz.spi.SchedulerPlugin) Scheduler(org.quartz.Scheduler) QuartzScheduler(org.quartz.core.QuartzScheduler) QuartzScheduler(org.quartz.core.QuartzScheduler) ClassLoadHelper(org.quartz.spi.ClassLoadHelper) CascadingClassLoadHelper(org.quartz.simpl.CascadingClassLoadHelper) QuartzSchedulerResources(org.quartz.core.QuartzSchedulerResources) CascadingClassLoadHelper(org.quartz.simpl.CascadingClassLoadHelper) Entry(java.util.Map.Entry) JobRunShellFactory(org.quartz.core.JobRunShellFactory)

Aggregations

ClassLoadHelper (org.quartz.spi.ClassLoadHelper)7 Scheduler (org.quartz.Scheduler)2 SchedulerException (org.quartz.SchedulerException)2 JobRunShellFactory (org.quartz.core.JobRunShellFactory)2 QuartzScheduler (org.quartz.core.QuartzScheduler)2 QuartzSchedulerResources (org.quartz.core.QuartzSchedulerResources)2 SchedulerPlugin (org.quartz.spi.SchedulerPlugin)2 IntrospectionException (java.beans.IntrospectionException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 AccessControlException (java.security.AccessControlException)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Calendar (org.quartz.Calendar)1 JobDetail (org.quartz.JobDetail)1 JobListener (org.quartz.JobListener)1 ObjectAlreadyExistsException (org.quartz.ObjectAlreadyExistsException)1 SchedulerConfigException (org.quartz.SchedulerConfigException)1