Java Code Examples for org.quartz.spi.JobFactory

The following examples show how to use org.quartz.spi.JobFactory. These examples are extracted from open source projects. 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 Project: hsweb-framework   Source File: ScheduleAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setApplicationContext(applicationContext);
    schedulerFactoryBean.setAutoStartup(schedulerProperties.isAutoStartup());
    schedulerFactoryBean.setDataSource(dataSource);
    schedulerFactoryBean.setTransactionManager(platformTransactionManager);
    schedulerFactoryBean.setOverwriteExistingJobs(schedulerProperties.isOverwriteExistingJobs());
    schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class);
    schedulerFactoryBean.setBeanName(schedulerProperties.getBeanName());
    schedulerFactoryBean.setJobFactory(jobFactory);
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(schedulerProperties.isWaitOnShutdown());
    schedulerFactoryBean.setQuartzProperties(schedulerProperties.getProperties());
    schedulerFactoryBean.setStartupDelay(schedulerProperties.getStartupDelay());
    schedulerFactoryBean.setCalendars(calendarMap);
    schedulerFactoryBean.setSchedulerListeners(schedulerListeners);
    return schedulerFactoryBean;
}
 
Example 2
Source Project: pacbot   Source File: PacmanQuartzConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory) throws IOException {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setOverwriteExistingJobs(true);
	factory.setDataSource(dataSource);
	factory.setJobFactory(jobFactory);
	factory.setQuartzProperties(quartzProperties());

	// Here we will set all the trigger beans we have defined.
	if (!NotificationUtil.isObjectEmpty(listOfTrigger)) {
		factory.setTriggers(listOfTrigger.toArray(new Trigger[listOfTrigger.size()]));
	}

	return factory;
}
 
Example 3
Source Project: griffin   Source File: SchedulerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource,
                                                 JobFactory jobFactory) {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    factory.setQuartzProperties(quartzConf);
    return factory;
}
 
Example 4
Source Project: ehousechina   Source File: SchedulerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory, @Qualifier("sampleJobTrigger") Trigger sampleJobTrigger) throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);
    factory.setJobFactory(jobFactory);
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    factory.setQuartzProperties(propertiesFactoryBean.getObject());
    return factory;
}
 
Example 5
@Bean(name = QUARTZ_JOB_FACTORY_BEAN_NAME)
@ConditionalOnMissingBean(name = QUARTZ_JOB_FACTORY_BEAN_NAME)
   public JobFactory autoJobFactory(ApplicationContext applicationContext,
   		@Autowired(required=false) QuartzSchedulerProperties properties) {
	if (null == properties) {
		LOGGER.warn("no QuartzSchedulerProperties found, consider to set quartz.enabled=true in properties");
		return null;
	}
       AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
       jobFactory.setApplicationContext(applicationContext);
       return jobFactory;
   }
 
Example 6
Source Project: quartz-manager   Source File: SchedulerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "scheduler")
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory,
		@Qualifier("jobTrigger") Trigger sampleJobTrigger) throws IOException {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setJobFactory(jobFactory);
	factory.setQuartzProperties(quartzProperties());
	factory.setTriggers(sampleJobTrigger);
	factory.setAutoStartup(false);
	return factory;
}
 
Example 7
@Inject
public QuartzSchedulerProvider(final NodeAccess nodeAccess,
                               final Provider<JobStore> jobStore,
                               final JobFactory jobFactory,
                               @Named("${nexus.quartz.poolSize:-20}") final int threadPoolSize,
                               @Named("${nexus.quartz.taskThreadPriority:-5}") final int threadPriority)
{
  this.nodeAccess = checkNotNull(nodeAccess);
  this.jobStore = checkNotNull(jobStore);
  this.jobFactory = checkNotNull(jobFactory);
  checkArgument(threadPoolSize > 0, "Invalid thread-pool size: %s", threadPoolSize);
  this.threadPoolSize = threadPoolSize;
  this.threadPriority = threadPriority;
  log.info("Thread-pool size: {}, Thread-pool priority: {}", threadPoolSize, threadPriority);
}
 
Example 8
Source Project: mangooio   Source File: Module.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    Names.bindProperties(binder(), config.toProperties());
    
    bind(JobFactory.class).to(SchedulerFactory.class);
    bind(Cache.class).toProvider(CacheProvider.class);
    bind(MangooAuthorizationService.class).to(AuthorizationService.class);
}
 
Example 9
Source Project: mangooio   Source File: ModuleTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBindings() {
       //given
	Injector guice = Application.getInjector();
	
       //when
	Binding<Stage> stage = guice.getBinding(Stage.class);
	Binding<Injector> injector = guice.getBinding(Injector.class);
	Binding<Logger> logger = guice.getBinding(Logger.class);
	Binding<Config> config = guice.getBinding(Config.class);
	Binding<JobFactory> jobFactory = guice.getBinding(JobFactory.class);
	Binding<Cache> cache = guice.getBinding(Cache.class);
	Binding<TemplateEngine> templateEngine = guice.getBinding(TemplateEngine.class);		
	Binding<OncePerRequestFilter> mangooRequestFilter = guice.getBinding(OncePerRequestFilter.class);
	Binding<MangooBootstrap> mangooBootstrap = guice.getBinding(MangooBootstrap.class);
	
	//then
	assertThat(stage.getKey().getTypeLiteral().getType().getTypeName(), equalTo("com.google.inject.Stage"));
	assertThat(injector.getKey().getTypeLiteral().getType().getTypeName(), equalTo("com.google.inject.Injector"));
	assertThat(logger.getKey().getTypeLiteral().getType().getTypeName(), equalTo("java.util.logging.Logger"));
	assertThat(config.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.core.Config"));
	assertThat(jobFactory.getKey().getTypeLiteral().getType().getTypeName(), equalTo("org.quartz.spi.JobFactory"));
	assertThat(cache.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.cache.Cache"));
	assertThat(templateEngine.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.templating.TemplateEngine"));
	assertThat(mangooRequestFilter.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.filters.OncePerRequestFilter"));
	assertThat(mangooBootstrap.getKey().getTypeLiteral().getType().getTypeName(), equalTo("io.mangoo.interfaces.MangooBootstrap"));
}
 
Example 10
Source Project: TrackRay   Source File: QuartzConfig.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Bean
public Scheduler scheduler(JobFactory jobFactory) {
    return schedulerFactoryBean(jobFactory).getScheduler();
}
 
Example 11
Source Project: lams   Source File: RemoteMBeanScheduler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new SchedulerException("Operation not supported for remote schedulers.");
}
 
Example 12
Source Project: lams   Source File: StdScheduler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    sched.setJobFactory(factory);
}
 
Example 13
Source Project: lams   Source File: RemoteScheduler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.");
}
 
Example 14
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 4 votes vote down vote up
public JobFactory getJobFactory()  {
    return jobFactory;
}
 
Example 15
Source Project: AsuraFramework   Source File: RemoteMBeanScheduler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 16
Source Project: AsuraFramework   Source File: StdScheduler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    sched.setJobFactory(factory);
}
 
Example 17
Source Project: AsuraFramework   Source File: RemoteScheduler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.quartz.Scheduler#setJobFactory(org.quartz.spi.JobFactory)
 */
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new SchedulerException(
            "Operation not supported for remote schedulers.",
            SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION);
}
 
Example 18
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 4 votes vote down vote up
public JobFactory getJobFactory()  {
    return jobFactory;
}
 
Example 19
@Bean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)
@ConditionalOnMissingBean
public SchedulerFactoryBean autoSchedulerFactory(ApplicationContext applicationContext, JobFactory jobFactory,
		@Autowired(required=false) QuartzSchedulerProperties properties,
		@Qualifier(QUARTZ_PROPERTIES_BEAN_NAME) Properties quartzProperties,
		@Autowired(required=false) List<TriggerListener> triggerListeners,
		@Autowired(required=false) List<JobListener> jobListeners,
		@Autowired(required=false) List<SchedulerListener> schedulerListeners) {
	
	if (null == properties) {
		LOGGER.warn("no QuartzSchedulerProperties found, consider to set quartz.enabled=true in properties");
		return null;
	}
	
	LOGGER.debug("creating SchedulerFactory");
	 
       SchedulerFactory factorySettings = properties.getSchedulerFactory();
	SchedulerRepository schedulerRepo = SchedulerRepository.getInstance();
	if (schedulerRepo.remove(QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)) {
		LOGGER.debug("removed scheduler from SchedulerRepository with name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME);
	}
	if (null != factorySettings.getSchedulerName() && schedulerRepo.remove(factorySettings.getSchedulerName())) {
		LOGGER.debug("removed scheduler from SchedulerRepository with name: " + factorySettings.getSchedulerName());
	}
	
	SchedulerFactoryBean factory = BeanUtils.instantiateClass(SchedulerFactoryBean.class);
	
       factory.setApplicationContext(applicationContext);
       factory.setJobFactory(jobFactory);
       
       Persistence persistenceSettings = properties.getPersistence();
       if (persistenceSettings.isPersisted()) {
       	factory.setDataSource(getDataSource(applicationContext, persistenceSettings));
       	if (persistenceSettings.isUsePlatformTxManager()) {
       		PlatformTransactionManager txManager = getTransactionManager(applicationContext, persistenceSettings.getPlatformTxManagerBeanName());
           	if (null != txManager) {
               	factory.setTransactionManager(txManager);
               }
       	}
       }
       
       if (!StringUtils.isEmpty(factorySettings.getSchedulerName())) {
       	factory.setSchedulerName(factorySettings.getSchedulerName());
       } else {
       	LOGGER.debug("no SchedulerName configured, using bean name: " + QUARTZ_SCHEDULER_FACTORY_BEAN_NAME);
       }
       factory.setPhase(factorySettings.getPhase());
       factory.setStartupDelay(factorySettings.getStartupDelay());
       factory.setAutoStartup(factorySettings.isAutoStartup());
       factory.setWaitForJobsToCompleteOnShutdown(factorySettings.isWaitForJobsToCompleteOnShutdown());
       factory.setOverwriteExistingJobs(factorySettings.isOverwriteExistingJobs());
       factory.setExposeSchedulerInRepository(factorySettings.isExposeSchedulerInRepository());
       
       factory.setQuartzProperties(quartzProperties);
       
       if (!CollectionUtils.isEmpty(jobListeners)) {
       	LOGGER.info("configuring " + jobListeners.size() + " job listeners");
       	factory.setGlobalJobListeners(jobListeners.toArray(new JobListener[]{}));
       }
       if (!CollectionUtils.isEmpty(triggerListeners)) {
       	LOGGER.info("configuring " + triggerListeners.size() + " trigger listeners");
       	factory.setGlobalTriggerListeners(triggerListeners.toArray(new TriggerListener[]{}));
       }
       if (!CollectionUtils.isEmpty(schedulerListeners)) {
       	LOGGER.info("configuring " + schedulerListeners.size() + " scheduler listeners");
       	factory.setSchedulerListeners(schedulerListeners.toArray(new SchedulerListener[]{}));
       }
       
       Collection<Trigger> triggers = getTriggers(applicationContext);
       if (null != triggers && !triggers.isEmpty()) {
       	factory.setTriggers(triggers.toArray(new Trigger[triggers.size()]));
       	LOGGER.info("staring scheduler factory with " + triggers.size() + " job triggers");
       } else {
       	LOGGER.info("staring scheduler factory with 0 job triggers");
       }
       
       QuartzSchedulerFactoryOverrideHook hook = getQuartzSchedulerFactoryOverrideHook(applicationContext);
       if (null != hook) {
       	factory = hook.override(factory, properties, quartzProperties);
       }
       
	return factory;
}
 
Example 20
Source Project: hsweb-framework   Source File: ScheduleAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public JobFactory jobFactory() {
    return new DynamicJobFactory(new AdaptableJobFactory());
}
 
Example 21
Source Project: hsweb-framework   Source File: DynamicJobFactory.java    License: Apache License 2.0 4 votes vote down vote up
public DynamicJobFactory(JobFactory defaultFactory) {
    this.defaultFactory = defaultFactory;
}
 
Example 22
Source Project: nexus-public   Source File: TaskSchedulerHelper.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void init(@Nullable final Integer poolSize, @Nullable final JobFactory factory) throws Exception {
  eventManager = new SimpleEventManager();
  applicationDirectories = mock(ApplicationDirectories.class);
  baseUrlManager = mock(BaseUrlManager.class);
  nodeAccess = mock(NodeAccess.class);
  lastShutdownTimeService = mock(LastShutdownTimeService.class);
  statusDelayedExecutor = mock(DatabaseStatusDelayedExecutor.class);

  Module module = binder -> {
    Properties properties = new Properties();
    properties.put("basedir", util.getBaseDir());
    if (poolSize != null) {
      properties.put("nexus.quartz.poolSize", poolSize);
    }
    binder.bind(ParameterKeys.PROPERTIES)
        .toInstance(properties);

    binder.bind(EventManager.class).toInstance(eventManager);

    File workDir = util.createTempDir(util.getTargetDir(), "workdir");
    when(applicationDirectories.getWorkDirectory(anyString())).thenReturn(workDir);
    binder.bind(ApplicationDirectories.class)
        .toInstance(applicationDirectories);

    binder.bind(BaseUrlManager.class)
        .toInstance(baseUrlManager);

    binder.bind(DatabaseInstance.class)
        .annotatedWith(Names.named("config"))
        .toInstance(databaseInstance);

    doAnswer(i  -> {
      ((Runnable) i.getArguments()[0]).run();
      return null;
    }).when(statusDelayedExecutor).execute(notNull(Runnable.class));
    binder.bind(DatabaseStatusDelayedExecutor.class)
        .toInstance(statusDelayedExecutor);

    when(nodeAccess.getId()).thenReturn("test-12345");
    when(nodeAccess.getMemberIds()).thenReturn(ImmutableSet.of("test-12345"));
    binder.bind(NodeAccess.class)
        .toInstance(nodeAccess);
    if (factory != null) {
      binder.bind(JobFactory.class).toInstance(factory);
    }

    binder.bind(LastShutdownTimeService.class).toInstance(lastShutdownTimeService);
    when(lastShutdownTimeService.estimateLastShutdownTime()).thenReturn(Optional.empty());

    // filtering by feature flag is not supported here yet
    binder.bind(JobStore.class).to(JobStoreImpl.class);
  };

  this.injector = Guice.createInjector(new WireModule(
      module, new StateGuardModule(),
      new SpaceModule(new URLClassSpace(TaskSchedulerHelper.class.getClassLoader()), BeanScanning.INDEX)
  ));
  injector.injectMembers(this);
}
 
Example 23
Source Project: FoxBPM   Source File: FoxbpmScheduler.java    License: Apache License 2.0 4 votes vote down vote up
public void setJobFactory(JobFactory factory) throws SchedulerException {
	scheduler.setJobFactory(factory);
}
 
Example 24
Source Project: smarthome   Source File: AbstractScheduler.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setJobFactory(JobFactory factory) throws SchedulerException {
    throw new UnsupportedOperationException();
}
 
Example 25
Source Project: deltaspike   Source File: CdiAwareJobFactory.java    License: Apache License 2.0 4 votes vote down vote up
public CdiAwareJobFactory()
{
    String defaultJobFactoryName = SchedulerBaseConfig.JobCustomization.DEFAULT_JOB_FACTORY_CLASS_NAME;

    defaultFactory = ClassUtils.tryToInstantiateClassForName(defaultJobFactoryName, JobFactory.class);
}
 
Example 26
Source Project: lams   Source File: QuartzScheduler.java    License: GNU General Public License v2.0 3 votes vote down vote up
public void setJobFactory(JobFactory factory) throws SchedulerException {

        if(factory == null) {
            throw new IllegalArgumentException("JobFactory cannot be set to null!");
        }

        getLog().info("JobFactory set to: " + factory);

        this.jobFactory = factory;
    }
 
Example 27
Source Project: AsuraFramework   Source File: QuartzScheduler.java    License: Apache License 2.0 3 votes vote down vote up
public void setJobFactory(JobFactory factory) throws SchedulerException {

        if(factory == null) {
            throw new IllegalArgumentException("JobFactory cannot be set to null!");
        }

        getLog().info("JobFactory set to: " + factory);

        this.jobFactory = factory;
    }
 
Example 28
Source Project: spring-analysis-note   Source File: SchedulerFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Set the Quartz {@link JobFactory} to use for this Scheduler.
 * <p>Default is Spring's {@link AdaptableJobFactory}, which supports
 * {@link java.lang.Runnable} objects as well as standard Quartz
 * {@link org.quartz.Job} instances. Note that this default only applies
 * to a <i>local</i> Scheduler, not to a RemoteScheduler (where setting
 * a custom JobFactory is not supported by Quartz).
 * <p>Specify an instance of Spring's {@link SpringBeanJobFactory} here
 * (typically as an inner bean definition) to automatically populate a job's
 * bean properties from the specified job data map and scheduler context.
 * @since 2.0
 * @see AdaptableJobFactory
 * @see SpringBeanJobFactory
 */
public void setJobFactory(JobFactory jobFactory) {
	this.jobFactory = jobFactory;
	this.jobFactorySet = true;
}
 
Example 29
Source Project: java-technology-stack   Source File: SchedulerFactoryBean.java    License: MIT License 2 votes vote down vote up
/**
 * Set the Quartz {@link JobFactory} to use for this Scheduler.
 * <p>Default is Spring's {@link AdaptableJobFactory}, which supports
 * {@link java.lang.Runnable} objects as well as standard Quartz
 * {@link org.quartz.Job} instances. Note that this default only applies
 * to a <i>local</i> Scheduler, not to a RemoteScheduler (where setting
 * a custom JobFactory is not supported by Quartz).
 * <p>Specify an instance of Spring's {@link SpringBeanJobFactory} here
 * (typically as an inner bean definition) to automatically populate a job's
 * bean properties from the specified job data map and scheduler context.
 * @since 2.0
 * @see AdaptableJobFactory
 * @see SpringBeanJobFactory
 */
public void setJobFactory(JobFactory jobFactory) {
	this.jobFactory = jobFactory;
	this.jobFactorySet = true;
}
 
Example 30
Source Project: lams   Source File: SchedulerFactoryBean.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the Quartz JobFactory to use for this Scheduler.
 * <p>Default is Spring's {@link AdaptableJobFactory}, which supports
 * {@link java.lang.Runnable} objects as well as standard Quartz
 * {@link org.quartz.Job} instances. Note that this default only applies
 * to a <i>local</i> Scheduler, not to a RemoteScheduler (where setting
 * a custom JobFactory is not supported by Quartz).
 * <p>Specify an instance of Spring's {@link SpringBeanJobFactory} here
 * (typically as an inner bean definition) to automatically populate a job's
 * bean properties from the specified job data map and scheduler context.
 * @see AdaptableJobFactory
 * @see SpringBeanJobFactory
 */
public void setJobFactory(JobFactory jobFactory) {
	this.jobFactory = jobFactory;
	this.jobFactorySet = true;
}