当前位置: 首页>>代码示例>>Java>>正文


Java JobDetailFactoryBean.setName方法代码示例

本文整理汇总了Java中org.springframework.scheduling.quartz.JobDetailFactoryBean.setName方法的典型用法代码示例。如果您正苦于以下问题:Java JobDetailFactoryBean.setName方法的具体用法?Java JobDetailFactoryBean.setName怎么用?Java JobDetailFactoryBean.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.scheduling.quartz.JobDetailFactoryBean的用法示例。


在下文中一共展示了JobDetailFactoryBean.setName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createJob

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
/**
 * Create Quartz Job.
 * 
 * @param jobClass Class whose executeInternal() method needs to be called. 
 * @param isDurable Job needs to be persisted even after completion. if true, job will be persisted, not otherwise. 
 * @param context Spring application context.
 * @param jobName Job name.
 * @param jobGroup Job group.
 * 
 * @return JobDetail object
 */
protected static JobDetail createJob(Class<? extends QuartzJobBean> jobClass, boolean isDurable, 
		ApplicationContext context, String jobName, String jobGroup){
    JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
    factoryBean.setJobClass(jobClass);
    factoryBean.setDurability(isDurable);
    factoryBean.setApplicationContext(context);
    factoryBean.setName(jobName);
    factoryBean.setGroup(jobGroup);
       
    // set job data map
       JobDataMap jobDataMap = new JobDataMap();
       jobDataMap.put("myKey", "myValue");
       factoryBean.setJobDataMap(jobDataMap);
       
       factoryBean.afterPropertiesSet();
       
    return factoryBean.getObject();
}
 
开发者ID:javabypatel,项目名称:spring-boot-quartz-demo,代码行数:30,代码来源:JobUtil.java

示例2: autowireJobTest

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
/**
 * Test if Job instances are autowired with the required beans and the
 * method ingest is called at least once (the job has been executed).
 * 
 * @throws SchedulerException
 *             if there is any problem launching the job.
 * @throws InterruptedException
 *             if test is interrupted while waiting for the job to start.
 */
@Test
@DatabaseSetup("schedulerData.xml")
public void autowireJobTest() throws SchedulerException,
		InterruptedException {

	JobDetailFactoryBean jdFactory = new JobDetailFactoryBean();
	jdFactory.setName("jdFactory");
	jdFactory.setJobClass(IngestJob.class);
	Map<String, Object> jobDataMap = Maps.newHashMap();
	jobDataMap.put(IngestJob.INGEST_ID, Long.toString(10L));
	jdFactory.setJobDataAsMap(jobDataMap);
	jdFactory.afterPropertiesSet();
	JobDetail jobDetail = jdFactory.getObject();

	SimpleTrigger trigger = (SimpleTrigger) newTrigger()
			.withIdentity("jdFactory", "DEFAULT").forJob(jobDetail).build();

	schedulerFactoryBean.getScheduler().scheduleJob(jobDetail, trigger);
	Thread.sleep(5000L);
	// verify(metadataIngester, atLeastOnce()).ingest(any(Metadata.class));
}
 
开发者ID:OpenGeoportal,项目名称:ogpHarvester,代码行数:31,代码来源:SchedulerTest.java

示例3: createJobDetail

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
private JobDetailFactoryBean createJobDetail(String name, Class<?> jobClass) {
	JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
	factoryBean.setName(name);
	factoryBean.setJobClass(jobClass);
	factoryBean.setApplicationContext(context);
	factoryBean.setApplicationContextJobDataKey(AbstractJob.KEY_APPLICATION_CONTEXT);
	// job has to be durable to be stored in DB:
	factoryBean.setDurability(true);
	factoryBean.afterPropertiesSet();
	return factoryBean;
}
 
开发者ID:mazhaoyong,项目名称:api-server-seed,代码行数:12,代码来源:QuartzFactory.java

示例4: createJobDetail

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
private JobDetail createJobDetail(final PiSchedule piSchedule) {
    final JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
    jobDetailFactoryBean.setApplicationContext(context);
    jobDetailFactoryBean.setName(piSchedule.getScheduleName());
    jobDetailFactoryBean.setJobClass(PiJob.class);
    jobDetailFactoryBean.getJobDataMap().put("piSchedule", piSchedule);
    jobDetailFactoryBean.afterPropertiesSet();

    return jobDetailFactoryBean.getObject();
}
 
开发者ID:justinhrobbins,项目名称:raspberry-pi-api,代码行数:11,代码来源:PiScheduleServiceImpl.java

示例5: createJobDetail

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
/**
 * Create a {@link JobDetail} based on the ingest passed as parameter.
 *
 * @param ingest the ingest to be scheduled.
 * @return a JobDetail base on the ingest passed.
 */
private JobDetail createJobDetail(Ingest ingest) {
    JobDetailFactoryBean jdFactory = new JobDetailFactoryBean();
    jdFactory.setName(generateJobName(ingest));
    jdFactory.setJobClass(IngestJob.class);
    jdFactory.getJobDataMap().put(IngestJob.INGEST_ID,
            ingest.getId().toString());
    jdFactory.afterPropertiesSet();
    return jdFactory.getObject();
}
 
开发者ID:OpenGeoportal,项目名称:ogpHarvester,代码行数:16,代码来源:IngestScheduler.java

示例6: lastRunSavedWhenExceptionTest

import org.springframework.scheduling.quartz.JobDetailFactoryBean; //导入方法依赖的package包/类
@Test
@DatabaseSetup("schedulerData.xml")
public void lastRunSavedWhenExceptionTest() throws Exception {
	Long ingestId = 10L;
	Ingest ingest = ingestService.findById(ingestId);
	ingest.setLastRun(null);
	ingestService.save(ingest);
	JobDetailFactoryBean jdFactory = new JobDetailFactoryBean();
	jdFactory.setName("jdFactory");
	jdFactory.setJobClass(IngestJob.class);
	Map<String, Object> jobDataMap = Maps.newHashMap();
	jobDataMap.put(IngestJob.INGEST_ID, Long.toString(ingestId));
	jdFactory.setJobDataAsMap(jobDataMap);
	jdFactory.afterPropertiesSet();
	JobDetail jobDetail = jdFactory.getObject();

	SimpleTriggerImpl trigger = (SimpleTriggerImpl) SimpleScheduleBuilder
			.simpleSchedule().withRepeatCount(0).build();
	TriggerFiredBundle bundle = mock(TriggerFiredBundle.class);
	when(bundle.getJobDetail()).thenReturn(jobDetail);
	when(bundle.getTrigger()).thenReturn(trigger);
	Object job = autowiringSpringBeanJobFactory.createJobInstance(bundle);

	RuntimeException mockedException = new RuntimeException();
	BaseIngestJob baseIngestJobMock = mock(BaseIngestJob.class);
	doThrow(mockedException).when(baseIngestJobMock).run();

	IngestJobFactory jobFactoryMock = mock(IngestJobFactory.class);
	when(jobFactoryMock.newIngestJob(any(Ingest.class))).thenReturn(
			baseIngestJobMock);

	Method setJobFactoryMethod = job.getClass().getMethod(
			"setIngestJobFactory", IngestJobFactory.class);
	ReflectionUtils.invokeJdbcMethod(setJobFactoryMethod, job,
			jobFactoryMock);

	JobExecutionContext context = mock(JobExecutionContext.class);
	when(context.getJobDetail()).thenReturn(jobDetail);
	Method executeMethod = job.getClass().getMethod("execute",
			JobExecutionContext.class);
	try {
		ReflectionUtils.invokeMethod(executeMethod, job, context);
	} catch (UndeclaredThrowableException ute) {
		Assert.assertEquals(
				"Cause exception must be the same we created in test method",
				mockedException, ute.getUndeclaredThrowable().getCause());
		ingest = ingestService.findById(ingestId);
		Assert.assertNotNull("LastRun must not be null",
				ingest.getLastRun());

	}

	// verify(metadataIngester, atLeastOnce()).ingest(any(Metadata.class));
}
 
开发者ID:OpenGeoportal,项目名称:ogpHarvester,代码行数:55,代码来源:SchedulerTest.java


注:本文中的org.springframework.scheduling.quartz.JobDetailFactoryBean.setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。