org.quartz.impl.JobDetailImpl Java Examples

The following examples show how to use org.quartz.impl.JobDetailImpl. 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: DelayedAsynchronousServiceCallProxy.java    From rice with Educational Community License v2.0 6 votes vote down vote up
protected void scheduleMessage(PersistedMessageBO message) throws SchedulerException {
 LOG.debug("Scheduling execution of a delayed asynchronous message.");
 Scheduler scheduler = KSBServiceLocator.getScheduler();
 JobDataMap jobData = new JobDataMap();
 jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, message);

    JobDetailImpl jobDetail = new JobDetailImpl("Delayed_Asynchronous_Call-" + Math.random(), "Delayed_Asynchronous_Call",
  MessageServiceExecutorJob.class);
 jobDetail.setJobDataMap(jobData);

    scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());

    SimpleTriggerImpl trigger = new SimpleTriggerImpl("Delayed_Asynchronous_Call_Trigger-" + Math.random(),
  "Delayed_Asynchronous_Call", message.getQueueDate());

    trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke
 scheduler.scheduleJob(jobDetail, trigger);
}
 
Example #2
Source File: MethodInvokingJobDetailFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name);
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example #3
Source File: EntityMocksHelper.java    From griffin with Apache License 2.0 6 votes vote down vote up
public static JobDetailImpl createJobDetail(
    String measureJson,
    String predicatesJson) {
    JobDetailImpl jobDetail = new JobDetailImpl();
    JobKey jobKey = new JobKey("name", "group");
    jobDetail.setKey(jobKey);
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(MEASURE_KEY, measureJson);
    jobDataMap.put(PREDICATES_KEY, predicatesJson);
    jobDataMap.put(JOB_NAME, "jobName");
    jobDataMap.put("jobName", "jobName");
    jobDataMap.put(PREDICATE_JOB_NAME, "predicateJobName");
    jobDataMap.put(GRIFFIN_JOB_ID, 1L);
    jobDetail.setJobDataMap(jobDataMap);
    return jobDetail;
}
 
Example #4
Source File: JobDetailControllerTest.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws SchedulerException {
    when(scheduler.getJobGroupNames()).thenReturn(newArrayList("g1"));
    when(scheduler.getJobKeys(any())).thenReturn(Sets.newHashSet(new JobKey("g1", "jd1"), new JobKey("g1", "jd2")));
    doReturn(Lists.newArrayList((Trigger) newTrigger()
            .withSchedule(cronSchedule("0/1 * * * * ?"))
            .build())).when(scheduler).getTriggersOfJob(any());

    when(scheduler.getJobDetail(any(JobKey.class))).thenAnswer(i -> {
        JobDetailImpl jobDetail = new JobDetailImpl();
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put(QuartzJobLauncher.JOB_NAME, ((JobKey) i.getArgument(0)).getName());
        jobDetail.setJobDataMap(jobDataMap);
        return jobDetail;
    });
}
 
Example #5
Source File: JobBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Produce the <code>JobDetail</code> instance defined by this 
 * <code>JobBuilder</code>.
 * 
 * @return the defined JobDetail.
 */
public JobDetail build() {

    JobDetailImpl job = new JobDetailImpl();
    
    job.setJobClass(jobClass);
    job.setDescription(description);
    if(key == null)
        key = new JobKey(Key.createUniqueName(null), null);
    job.setKey(key); 
    job.setDurability(durability);
    job.setRequestsRecovery(shouldRecover);
    
    
    if(!jobDataMap.isEmpty())
        job.setJobDataMap(jobDataMap);
    
    return job;
}
 
Example #6
Source File: JobDetailSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param cData
 * @return JobDetail
 */
public static JobDetail newJobDetail(CompositeData cData)
  throws ClassNotFoundException
{
    JobDetailImpl jobDetail = new JobDetailImpl();

    int i = 0;
    jobDetail.setName((String) cData.get(ITEM_NAMES[i++]));
    jobDetail.setGroup((String) cData.get(ITEM_NAMES[i++]));
    jobDetail.setDescription((String) cData.get(ITEM_NAMES[i++]));
    Class<?> jobClass = Class.forName((String) cData.get(ITEM_NAMES[i++]));
    @SuppressWarnings("unchecked")
    Class<? extends Job> jobClassTyped = (Class<? extends Job>)jobClass;
    jobDetail.setJobClass(jobClassTyped);
    jobDetail.setJobDataMap(JobDataMapSupport.newJobDataMap((TabularData) cData.get(ITEM_NAMES[i++])));
    jobDetail.setDurability((Boolean) cData.get(ITEM_NAMES[i++]));
    jobDetail.setRequestsRecovery((Boolean) cData.get(ITEM_NAMES[i++]));

    return jobDetail;
}
 
Example #7
Source File: AbstractRedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve a job from redis
 * @param jobKey the job key detailing the identity of the job to be retrieved
 * @param jedis a thread-safe Redis connection
 * @return the {@link org.quartz.JobDetail} of the desired job
 * @throws JobPersistenceException if the desired job does not exist
 * @throws ClassNotFoundException
 */
public JobDetail retrieveJob(JobKey jobKey, T jedis) throws JobPersistenceException, ClassNotFoundException{
    final String jobHashKey = redisSchema.jobHashKey(jobKey);
    final String jobDataMapHashKey = redisSchema.jobDataMapHashKey(jobKey);

    final Map<String, String> jobDetailMap = jedis.hgetAll(jobHashKey);
    if(jobDetailMap == null || jobDetailMap.size() == 0){
        // desired job does not exist
        return null;
    }
    JobDetailImpl jobDetail = mapper.convertValue(jobDetailMap, JobDetailImpl.class);
    jobDetail.setKey(jobKey);

    final Map<String, String> jobData = jedis.hgetAll(jobDataMapHashKey);
    if(jobData != null && !jobData.isEmpty()){
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.putAll(jobData);
        jobDetail.setJobDataMap(jobDataMap);
    }

    return jobDetail;
}
 
Example #8
Source File: JobDetailMixinTest.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
@Test
public void serializeJobDetail() throws Exception {
    JobDetail testJob = JobBuilder.newJob(TestJob.class)
            .withIdentity("testJob", "testGroup")
            .usingJobData("timeout", 42)
            .withDescription("I am describing a job!")
            .build();

    String json = mapper.writeValueAsString(testJob);
    Map<String, Object> jsonMap = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
    });

    assertThat(jsonMap, hasKey("name"));
    assertEquals(testJob.getKey().getName(), jsonMap.get("name"));
    assertThat(jsonMap, hasKey("group"));
    assertEquals(testJob.getKey().getGroup(), jsonMap.get("group"));
    assertThat(jsonMap, hasKey("jobClass"));
    assertEquals(testJob.getJobClass().getName(), jsonMap.get("jobClass"));

    JobDetailImpl jobDetail = mapper.readValue(json, JobDetailImpl.class);

    assertEquals(testJob.getKey().getName(), jobDetail.getKey().getName());
    assertEquals(testJob.getKey().getGroup(), jobDetail.getKey().getGroup());
    assertEquals(testJob.getJobClass(), jobDetail.getJobClass());
}
 
Example #9
Source File: DefaultExceptionServiceImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
public void scheduleExecution(Throwable throwable, PersistedMessageBO message, String description) throws Exception {
	KSBServiceLocator.getMessageQueueService().delete(message);
       PersistedMessageBO messageCopy = message.copy();
	Scheduler scheduler = KSBServiceLocator.getScheduler();
	JobDataMap jobData = new JobDataMap();
	jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, messageCopy);
	JobDetailImpl jobDetail = new JobDetailImpl("Exception_Message_Job " + Math.random(), "Exception Messaging",
		MessageServiceExecutorJob.class);
	jobDetail.setJobDataMap(jobData);

       if (!StringUtils.isBlank(description)) {
	    jobDetail.setDescription(description);
	}

       scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());

       SimpleTriggerImpl trigger = new SimpleTriggerImpl("Exception_Message_Trigger " + Math.random(), "Exception Messaging", messageCopy
		.getQueueDate());
	trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke

       scheduler.scheduleJob(jobDetail, trigger);
}
 
Example #10
Source File: MethodInvokingJobDetailFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name != null ? name : toString());
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example #11
Source File: QuartzTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Test
   public void testSchedulingJob() throws Exception {
Scheduler scheduler = KSBServiceLocator.getScheduler();
JobDataMap datMap = new JobDataMap();
datMap.put("yo", "yo");
JobDetailImpl jobDetail = new JobDetailImpl("myJob", null, TestJob.class);
jobDetail.setJobDataMap(datMap);

   TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
   triggerBuilder.startAt(new Date());
   triggerBuilder.withIdentity("i'm a trigger puller");
   triggerBuilder.usingJobData(datMap);
   triggerBuilder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(1).withIntervalInMilliseconds(1L));

   Trigger trigger = triggerBuilder.build();

scheduler.scheduleJob(jobDetail, trigger);


synchronized (TestJob.LOCK) {
    TestJob.LOCK.wait(30 * 1000);    
}

assertTrue("job never fired", TestJob.EXECUTED);
   }
 
Example #12
Source File: MethodInvokingJobDetailFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name != null ? name : toString());
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example #13
Source File: AuroraCronJobTest.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  storage = MemStorageModule.newEmptyStorage();
  stateManager = createMock(StateManager.class);
  backoffHelper = createMock(BackoffHelper.class);
  context = createMock(JobExecutionContext.class);

  jobDetails = new JobDetailImpl();
  jobDetails.setKey(Quartz.jobKey(AURORA_JOB_KEY));
  jobDetails.setJobDataMap(new JobDataMap(new HashMap()));
  expect(context.getJobDetail()).andReturn(jobDetails).anyTimes();

  batchWorker = createMock(CronBatchWorker.class);
  expectBatchExecute(batchWorker, storage, control).anyTimes();

  auroraCronJob = new AuroraCronJob(
      new AuroraCronJob.Config(backoffHelper),
      stateManager,
      batchWorker);
}
 
Example #14
Source File: MethodInvokingJobDetailFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
	prepare();

	// Use specific name if given, else fall back to bean name.
	String name = (this.name != null ? this.name : this.beanName);

	// Consider the concurrent flag to choose between stateful and stateless job.
	Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);

	// Build JobDetail instance.
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(name);
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) jobClass);
	jdi.setDurability(true);
	jdi.getJobDataMap().put("methodInvoker", this);
	this.jobDetail = jdi;

	postProcessJobDetail(this.jobDetail);
}
 
Example #15
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
  this.fSignaler = new SampleSignaler();
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
  loadHelper.initialize();
  this.fJobStore = createJobStore("AbstractJobStoreTest");
  this.fJobStore.initialize(loadHelper, this.fSignaler);
  this.fJobStore.schedulerStarted();

  this.fJobDetail = new JobDetailImpl("job1", "jobGroup1", MyJob.class);
  this.fJobDetail.setDurability(true);
  this.fJobStore.storeJob(this.fJobDetail, false);
}
 
Example #16
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example #17
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithTaskExecutor() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setTaskExecutor(taskExecutor);
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
	assertEquals(DummyJob.count, taskExecutor.count);

	bean.destroy();
}
 
Example #18
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}
 
Example #19
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("para", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	SpringBeanJobFactory jobFactory = new SpringBeanJobFactory();
	jobFactory.setIgnoredUnknownProperties("ignoredParam");
	bean.setJobFactory(jobFactory);
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();

	Thread.sleep(500);
	assertEquals(0, DummyJob.param);
	assertTrue(DummyJob.count == 0);

	bean.destroy();
}
 
Example #20
Source File: JobDetailFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
	if (this.name == null) {
		this.name = this.beanName;
	}
	if (this.group == null) {
		this.group = Scheduler.DEFAULT_GROUP;
	}
	if (this.applicationContextJobDataKey != null) {
		if (this.applicationContext == null) {
			throw new IllegalStateException(
				"JobDetailBean needs to be set up in an ApplicationContext " +
				"to be able to handle an 'applicationContextJobDataKey'");
		}
		getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext);
	}

	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(this.name);
	jdi.setGroup(this.group);
	jdi.setJobClass((Class) this.jobClass);
	jdi.setJobDataMap(this.jobDataMap);
	jdi.setDurability(this.durability);
	jdi.setRequestsRecovery(this.requestsRecovery);
	jdi.setDescription(this.description);
	this.jobDetail = jdi;
}
 
Example #21
Source File: QuartzSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	DummyJobBean.param = 0;
	DummyJobBean.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJobBean.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJobBean.param);
	assertTrue(DummyJobBean.count > 0);

	bean.destroy();
}
 
Example #22
Source File: JobStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testStoreTriggerReplacesTrigger() throws Exception {
  String jobName = "StoreTriggerReplacesTrigger";
  String jobGroup = "StoreTriggerReplacesTriggerGroup";
  JobDetailImpl detail = new JobDetailImpl(jobName, jobGroup, MyJob.class);
  jobStore.storeJob(detail, false);

  String trName = "StoreTriggerReplacesTrigger";
  String trGroup = "StoreTriggerReplacesTriggerGroup";
  OperableTrigger tr = new SimpleTriggerImpl(trName, trGroup, new Date());
  tr.setJobKey(new JobKey(jobName, jobGroup));
  tr.setCalendarName(null);

  jobStore.storeTrigger(tr, false);
  assertEquals(tr, jobStore.retrieveTrigger(tr.getKey()));

  try {
    jobStore.storeTrigger(tr, false);
    fail("an attempt to store duplicate trigger succeeded");
  }
  catch (ObjectAlreadyExistsException oaee) {
    // expected
  }

  tr.setCalendarName("QQ");
  jobStore.storeTrigger(tr, true); //fails here
  assertEquals(tr, jobStore.retrieveTrigger(tr.getKey()));
  assertEquals("StoreJob doesn't replace triggers", "QQ", jobStore.retrieveTrigger(tr.getKey()).getCalendarName());
}
 
Example #23
Source File: HRCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
public void task(List<Long> users,String cronExpression) throws SchedulerException
{
    // Initiate a Schedule Factory
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    // Retrieve a scheduler from schedule factory
    Scheduler scheduler = schedulerFactory.getScheduler();
    
    // Initiate JobDetail with job name, job group, and executable job class
    JobDetailImpl jobDetailImpl = 
    	new JobDetailImpl();
    jobDetailImpl.setJobClass(HRJob.class);
    jobDetailImpl.setKey(new JobKey("HRJob1"));
    jobDetailImpl.getJobDataMap().put("users",users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("HRCronTrigger1");
    
    try {
        // setup CronExpression
        CronExpression cexp = new CronExpression(cronExpression);
        // Assign the CronExpression to CronTrigger
        cronTriggerImpl.setCronExpression(cexp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // schedule a job with JobDetail and Trigger
    scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl);
    
    // start the scheduler
    scheduler.start();
}
 
Example #24
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void testStoreTriggerReplacesTrigger() throws Exception {

  String jobName = "StoreTriggerReplacesTrigger";
  String jobGroup = "StoreTriggerReplacesTriggerGroup";
  JobDetailImpl detail = new JobDetailImpl(jobName, jobGroup, MyJob.class);
  fJobStore.storeJob(detail, false);

  String trName = "StoreTriggerReplacesTrigger";
  String trGroup = "StoreTriggerReplacesTriggerGroup";
  OperableTrigger tr = new SimpleTriggerImpl(trName ,trGroup, new Date());
  tr.setJobKey(new JobKey(jobName, jobGroup));
  tr.setCalendarName(null);

  fJobStore.storeTrigger(tr, false);
  assertEquals(tr,fJobStore.retrieveTrigger(tr.getKey()));

  try {
    fJobStore.storeTrigger(tr, false);
    fail("an attempt to store duplicate trigger succeeded");
  } catch(ObjectAlreadyExistsException oaee) {
    // expected
  }

  tr.setCalendarName("QQ");
  fJobStore.storeTrigger(tr, true); //fails here
  assertEquals(tr, fJobStore.retrieveTrigger(tr.getKey()));
  assertEquals( "StoreJob doesn't replace triggers", "QQ", fJobStore.retrieveTrigger(tr.getKey()).getCalendarName());
}
 
Example #25
Source File: ActionListEmailServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public void scheduleBatchEmailReminders() throws Exception {
    String emailBatchGroup = "Email Batch";
    String dailyCron = ConfigContext.getCurrentContextConfig()
            .getProperty(KewApiConstants.DAILY_EMAIL_CRON_EXPRESSION);
    if (!StringUtils.isBlank(dailyCron)) {
        LOG.info("Scheduling Daily Email batch with cron expression: " + dailyCron);
        CronTriggerImpl dailyTrigger = new CronTriggerImpl(DAILY_TRIGGER_NAME, emailBatchGroup, dailyCron);
        JobDetailImpl dailyJobDetail = new JobDetailImpl(DAILY_JOB_NAME, emailBatchGroup, DailyEmailJob.class);
        dailyTrigger.setJobName(dailyJobDetail.getName());
        dailyTrigger.setJobGroup(dailyJobDetail.getGroup());
        addJobToScheduler(dailyJobDetail);
        addTriggerToScheduler(dailyTrigger);
    } else {
        LOG.warn("No " + KewApiConstants.DAILY_EMAIL_CRON_EXPRESSION
                + " parameter was configured.  Daily Email batch was not scheduled!");
    }

    String weeklyCron = ConfigContext.getCurrentContextConfig().getProperty(
            KewApiConstants.WEEKLY_EMAIL_CRON_EXPRESSION);
    if (!StringUtils.isBlank(weeklyCron)) {
        LOG.info("Scheduling Weekly Email batch with cron expression: " + weeklyCron);
        CronTriggerImpl weeklyTrigger = new CronTriggerImpl(WEEKLY_TRIGGER_NAME, emailBatchGroup, weeklyCron);
        JobDetailImpl weeklyJobDetail = new JobDetailImpl(WEEKLY_JOB_NAME, emailBatchGroup, WeeklyEmailJob.class);
        weeklyTrigger.setJobName(weeklyJobDetail.getName());
        weeklyTrigger.setJobGroup(weeklyJobDetail.getGroup());
        addJobToScheduler(weeklyJobDetail);
        addTriggerToScheduler(weeklyTrigger);
    } else {
        LOG.warn("No " + KewApiConstants.WEEKLY_EMAIL_CRON_EXPRESSION
                + " parameter was configured.  Weekly Email batch was not scheduled!");
    }
}
 
Example #26
Source File: MockEmailNotificationServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public void scheduleBatchEmailReminders() throws Exception {
    sendDailyReminderCalled = false;
    sendWeeklyReminderCalled = false;
    LOG.info("Scheduling Batch Email Reminders.");
    String emailBatchGroup = "Email Batch";
    String dailyCron = ConfigContext.getCurrentContextConfig()
            .getProperty(KewApiConstants.DAILY_EMAIL_CRON_EXPRESSION);
    if (!StringUtils.isBlank(dailyCron)) {
        LOG.info("Scheduling Daily Email batch with cron expression: " + dailyCron);
        CronTriggerImpl dailyTrigger = new CronTriggerImpl(DAILY_TRIGGER_NAME, emailBatchGroup, dailyCron);
        JobDetailImpl dailyJobDetail = new JobDetailImpl(DAILY_JOB_NAME, emailBatchGroup, DailyEmailJob.class);
        dailyTrigger.setJobName(dailyJobDetail.getName());
        dailyTrigger.setJobGroup(dailyJobDetail.getGroup());
        sendDailyReminderCalled = true;
    } else {
        LOG.warn("No " + KewApiConstants.DAILY_EMAIL_CRON_EXPRESSION
                + " parameter was configured.  Daily Email batch was not scheduled!");
    }

    String weeklyCron = ConfigContext.getCurrentContextConfig().getProperty(
            KewApiConstants.WEEKLY_EMAIL_CRON_EXPRESSION);
    if (!StringUtils.isBlank(weeklyCron)) {
        LOG.info("Scheduling Weekly Email batch with cron expression: " + weeklyCron);
        CronTriggerImpl weeklyTrigger = new CronTriggerImpl(WEEKLY_TRIGGER_NAME, emailBatchGroup, weeklyCron);
        JobDetailImpl weeklyJobDetail = new JobDetailImpl(WEEKLY_JOB_NAME, emailBatchGroup, WeeklyEmailJob.class);
        weeklyTrigger.setJobName(weeklyJobDetail.getName());
        weeklyTrigger.setJobGroup(weeklyJobDetail.getGroup());
        sendWeeklyReminderCalled = true;
    } else {
        LOG.warn("No " + KewApiConstants.WEEKLY_EMAIL_CRON_EXPRESSION
                + " parameter was configured.  Weekly Email batch was not scheduled!");
    }
}
 
Example #27
Source File: MessagingServiceTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void registerJobListener() throws SchedulerException {
    KSBServiceLocator.getScheduler().getListenerManager().addJobListener(new JobListenerSupport() {
        @Override
        public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
            log.info("Job was executed: " + context);
            if (MessageProcessingJob.NAME.equals(((JobDetailImpl) context.getJobDetail()).getName())) {
                signal.countDown();
            }
        }

        public String getName() {
            return System.currentTimeMillis() + RandomStringUtils.randomAlphanumeric(10);
        }
    });
}
 
Example #28
Source File: FolderBasedScriptJobResolverTest.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testResolveJobs() throws Exception {
    List<JobContext> jobContexts = resolver.resolveJobs(siteContext);

    assertNotNull(jobContexts);
    assertEquals(1, jobContexts.size());

    JobDetailImpl jobDetail = (JobDetailImpl)jobContexts.get(0).getDetail();
    CronTrigger trigger = (CronTrigger)jobContexts.get(0).getTrigger();

    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/testJob.groovy",
                 jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals(HOURLY_CRON_EXPRESSION, trigger.getCronExpression());
}
 
Example #29
Source File: UtilsToolTest.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInterruptable() throws Exception {
    JobDetailImpl job = new JobDetailImpl();
    job.setJobClass(DummyJob.class);

    Assert.assertEquals(true, utilsTool.isInterruptible(job));
}
 
Example #30
Source File: QuartzSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void schedulerWithSpringBeanJobFactory() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DummyJob.param = 0;
	DummyJob.count = 0;

	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setDurability(true);
	jobDetail.setJobClass(DummyJob.class);
	jobDetail.setName("myJob");
	jobDetail.getJobDataMap().put("param", "10");
	jobDetail.getJobDataMap().put("ignoredParam", "10");

	SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
	trigger.setName("myTrigger");
	trigger.setJobDetail(jobDetail);
	trigger.setStartDelay(1);
	trigger.setRepeatInterval(500);
	trigger.setRepeatCount(1);
	trigger.afterPropertiesSet();

	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setJobFactory(new SpringBeanJobFactory());
	bean.setTriggers(trigger.getObject());
	bean.setJobDetails(jobDetail);
	bean.afterPropertiesSet();
	bean.start();

	Thread.sleep(500);
	assertEquals(10, DummyJob.param);
	assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);

	bean.destroy();
}