Java Code Examples for org.quartz.impl.StdSchedulerFactory#initialize()

The following examples show how to use org.quartz.impl.StdSchedulerFactory#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTaskScheduler.java    From onedev with MIT License 6 votes vote down vote up
public DefaultTaskScheduler() {
	StdSchedulerFactory schedFactory = new StdSchedulerFactory();
	Properties props = new Properties();
	props.setProperty("org.quartz.scheduler.instanceName", "DefaultQuartzScheduler");
	props.setProperty("org.quartz.scheduler.rmi.export", "false");
	props.setProperty("org.quartz.scheduler.rmi.proxy", "false");
       props.setProperty("org.quartz.scheduler.wrapJobExecutionInUserTransaction", "false");
       props.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
       props.setProperty("org.quartz.threadPool.threadCount", "10");
       props.setProperty("org.quartz.jobStore.misfireThreshold", "60000");
       props.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
	try {
		schedFactory.initialize(props);
		quartz = schedFactory.getScheduler();
	} catch (SchedulerException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
Source File: SolrTrackerScheduler.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public SolrTrackerScheduler(AlfrescoCoreAdminHandler adminHandler)
{
    // TODO: pick scheduler properties from SOLR config or file ...
    try
    {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        Properties properties = new Properties();
        properties.setProperty("org.quartz.scheduler.instanceName", adminHandler.toString());
        properties.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
        properties.setProperty("org.quartz.threadPool.threadCount", "40");
        properties.setProperty("org.quartz.threadPool.makeThreadsDaemons", "true");
        properties.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", "true");
        properties.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
        properties.setProperty("org.quartz.scheduler.skipUpdateCheck","true");
        factory.initialize(properties);
        scheduler = factory.getScheduler();
        scheduler.start();

    }
    catch (SchedulerException e)
    {
        logError("SolrTrackerScheduler", e);
    }
}
 
Example 3
Source File: QuartzInitializer.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void init(SourceBean config) {
	StdSchedulerFactory stdSchedFact = new StdSchedulerFactory();
	Properties properties = new Properties();
	try {
		Thread currThread = Thread.currentThread();
		ClassLoader classLoader = currThread.getContextClassLoader();
		InputStream propIs = classLoader.getResourceAsStream("quartz.properties");
		properties.load(propIs);

		String figuredOutValue = null;

		if (properties.containsKey(PROPERTY_DELEGATE_CLASS)) {
			logger.info("Quartz delegate class set to " + properties.get(PROPERTY_DELEGATE_CLASS));
		} else {
			logger.warn("Property " + PROPERTY_DELEGATE_CLASS + " not set! Trying to figure out what delegate class needs to be used...");
			determineDelegateClass(properties);
		}

		stdSchedFact.initialize(properties);
		Scheduler sched = stdSchedFact.getScheduler();
		sched.start();
	} catch (Exception e) {
		SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "init", "Error while initializing scheduler " + e);
	}
}
 
Example 4
Source File: TaskManager.java    From WeCross with Apache License 2.0 5 votes vote down vote up
public TaskManager(TaskFactory taskFactory) {
    this.taskFactory = taskFactory;
    try {
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Properties props = new Properties();
        props.put(
                StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
                "org.quartz.simpl.SimpleThreadPool");
        props.put("org.quartz.threadPool.threadCount", "1");
        stdSchedulerFactory.initialize(props);
        scheduler = stdSchedulerFactory.getScheduler();
    } catch (SchedulerException e) {
        logger.error("something wrong with getting scheduler: {}", e.getLocalizedMessage());
    }
}
 
Example 5
Source File: TransientProducerScheduler.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
private Scheduler getScheduler() {
    StdSchedulerFactory factory = new StdSchedulerFactory();
    try {
        factory.initialize(getQuartzProperties());
        return factory.getScheduler();
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
}
 
Example 6
Source File: StatisticsScheduler.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
StatisticsScheduler() {
    factory = new StdSchedulerFactory();
    try {
        factory.initialize(getQuartzProperties());
    } catch (final SchedulerException ex) {
        throw new JobStatisticException(ex);
    }
}
 
Example 7
Source File: QuartzService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void createService() throws Exception {
    log.info("Create QuartzService(" + jndiName + ")...");

    if (error) {
        log
                .error("Must specify only one of 'Properties' or 'PropertiesFile'");

        throw new Exception(
                "Must specify only one of 'Properties' or 'PropertiesFile'");
    }

    schedulerFactory = new StdSchedulerFactory();

    try {
        if (useProperties) {
            schedulerFactory.initialize(properties);
        }

        if (usePropertiesFile) {
            schedulerFactory.initialize(propertiesFile);
        }
    } catch (Exception e) {
        log.error("Failed to initialize Scheduler", e);

        throw new SchedulerConfigException(
                "Failed to initialize Scheduler - ", e);
    }

    log.info("QuartzService(" + jndiName + ") created.");
}
 
Example 8
Source File: InstanceDetection.java    From uflo with Apache License 2.0 5 votes vote down vote up
private void initDetectionScheduler() throws Exception{
	StdSchedulerFactory factory=new StdSchedulerFactory();
	Properties mergedProps = new Properties();
	mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
	mergedProps.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", "true");
	mergedProps.setProperty("org.quartz.scheduler.instanceName", "UfloClusterHeartbeatScheduler");
	mergedProps.setProperty("org.quartz.scheduler.instanceId", "UfloHeartbeatDetectionScheduler");
	mergedProps.setProperty("org.quartz.threadPool.threadCount","2");
	factory.initialize(mergedProps);
	scheduler=factory.getScheduler();
}
 
Example 9
Source File: AbstractScheduleManager.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
protected void initScheduler(Properties properties) {
    this.properties = properties;
    try {
        StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
        schedulerFactory.initialize(properties);
        scheduler = schedulerFactory.getScheduler();
        scheduler.start();
    } catch (SchedulerException e) {
        LoggerHelper.error("create scheduler failed.", e);
        throw new NiubiException(e);
    }
}
 
Example 10
Source File: JobScheduler.java    From shardingsphere-elasticjob-lite with Apache License 2.0 5 votes vote down vote up
private Scheduler createScheduler() {
    Scheduler result;
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(getQuartzProps());
        result = factory.getScheduler();
        result.getListenerManager().addTriggerListener(schedulerFacade.newJobTriggerListener());
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
    return result;
}
 
Example 11
Source File: BaseTest.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
protected void testJobStore(Properties quartzProperties) throws SchedulerException {
    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
    schedulerFactory.initialize(quartzProperties);

    Scheduler scheduler = schedulerFactory.getScheduler();
    scheduler.start();

    JobDetail job = getJobDetail("testJob1", "testJobGroup1");
    CronTriggerImpl trigger = getCronTrigger("testTrigger1", "testTriggerGroup1", job.getKey(), "0/5 * * * * ?");

    scheduler.scheduleJob(job, trigger);

    JobDetail retrievedJob = jobStore.retrieveJob(job.getKey());
    assertThat(retrievedJob, not(nullValue()));
    assertThat(retrievedJob.getJobDataMap(), hasKey("timeout"));

    CronTriggerImpl retrievedTrigger = (CronTriggerImpl) jobStore.retrieveTrigger(trigger.getKey());
    assertThat(retrievedTrigger, not(nullValue()));
    assertEquals(trigger.getCronExpression(), retrievedTrigger.getCronExpression());

    scheduler.deleteJob(job.getKey());

    assertThat(jobStore.retrieveJob(job.getKey()), nullValue());
    assertThat(jobStore.retrieveTrigger(trigger.getKey()), nullValue());

    scheduler.shutdown();
}
 
Example 12
Source File: SchedulerService.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override protected void startUp() throws SchedulerException  {
  StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
  if (this.quartzProps.isPresent() && this.quartzProps.get().size() > 0) {
    schedulerFactory.initialize(this.quartzProps.get());
  }
  this.scheduler = schedulerFactory.getScheduler();
  this.scheduler.start();
}
 
Example 13
Source File: RoboconfScheduler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the scheduler.
 * <p>
 * Invoked by iPojo.
 * </p>
 */
public void start() throws Exception {
	this.logger.info( "Roboconf's scheduler is starting..." );

	// Verify the "scheduler" directory exists
	File schedulerDirectory = getSchedulerDirectory();
	Utils.createDirectory( schedulerDirectory );

	// Disable Quartz update checks
	StringBuilder quartzProperties = new StringBuilder();
	quartzProperties.append( "org.quartz.scheduler.instanceName: Roboconf Quartz Scheduler\n" );
	quartzProperties.append( "org.quartz.threadPool.threadCount = 3\n" );
	quartzProperties.append( "org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore\n" );
	quartzProperties.append( "org.quartz.scheduler.skipUpdateCheck: false\n" );

	StdSchedulerFactory factory = new StdSchedulerFactory();
	factory.initialize( new ByteArrayInputStream( quartzProperties.toString().getBytes( StandardCharsets.UTF_8 )));

	// Create a new scheduler
	this.scheduler = factory.getScheduler();
	this.scheduler.start();
	this.scheduler.getContext().put( MANAGER, this.manager );

	// Add a listener to the DM
	this.dmListener = new ManagerListener( this );
	this.manager.listenerAppears( this.dmListener );

	// Reload all the jobs
	loadJobs();
}
 
Example 14
Source File: SchedulerFactoryBean.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	Properties mergedProps = new Properties();
	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
	if (this.dataSource != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Determine scheduler name across local settings and Quartz properties...
	if (this.schedulerName != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}
	else {
		String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
		if (nameProp != null) {
			this.schedulerName = nameProp;
		}
		else if (this.beanName != null) {
			mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName);
			this.schedulerName = this.beanName;
		}
	}

	schedulerFactory.initialize(mergedProps);
}
 
Example 15
Source File: SchedulerFactoryBean.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it.
 * @param schedulerFactory the SchedulerFactory to initialize
 */
private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws SchedulerException, IOException {
	Properties mergedProps = new Properties();
	if (this.resourceLoader != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
				ResourceLoaderClassLoadHelper.class.getName());
	}

	if (this.taskExecutor != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
				LocalTaskExecutorThreadPool.class.getName());
	}
	else {
		// Set necessary default properties here, as Quartz will not apply
		// its default configuration when explicitly given properties.
		mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
		mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
	}

	if (this.configLocation != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Loading Quartz config from [" + this.configLocation + "]");
		}
		PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
	}

	CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
	if (this.dataSource != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
	}

	// Determine scheduler name across local settings and Quartz properties...
	if (this.schedulerName != null) {
		mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
	}
	else {
		String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
		if (nameProp != null) {
			this.schedulerName = nameProp;
		}
		else if (this.beanName != null) {
			mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName);
			this.schedulerName = this.beanName;
		}
	}

	schedulerFactory.initialize(mergedProps);
}
 
Example 16
Source File: DaemonTaskScheduler.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 4 votes vote down vote up
private Scheduler initializeScheduler() throws SchedulerException {
    StdSchedulerFactory factory = new StdSchedulerFactory();
    factory.initialize(getBaseQuartzProperties());
    return factory.getScheduler();
}