@Test public void testUpdate2() throws Exception { SchedulerResponse schedulerResponse = _quartzSchedulerEngine.getScheduledJob( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY); Trigger trigger = schedulerResponse.getTrigger(); CalendarIntervalTrigger calendarIntervalTrigger = (CalendarIntervalTrigger) trigger.getWrappedTrigger(); Assert.assertEquals(_DEFAULT_INTERVAL, calendarIntervalTrigger.getRepeatInterval()); String cronExpression = "0 0 12 * * ?"; Trigger newTrigger = _quartzTriggerFactory.createTrigger( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, null, null, cronExpression); _quartzSchedulerEngine.update(newTrigger, StorageType.MEMORY); schedulerResponse = _quartzSchedulerEngine.getScheduledJob( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY); trigger = schedulerResponse.getTrigger(); CronTrigger cronTrigger = (CronTrigger) trigger.getWrappedTrigger(); Assert.assertEquals(cronExpression, cronTrigger.getCronExpression()); }
@Test public void testUpdate1() throws Exception { SchedulerResponse schedulerResponse = _quartzSchedulerEngine.getScheduledJob( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY); Trigger trigger = schedulerResponse.getTrigger(); CalendarIntervalTrigger calendarIntervalTrigger = (CalendarIntervalTrigger) trigger.getWrappedTrigger(); Assert.assertEquals(_DEFAULT_INTERVAL, calendarIntervalTrigger.getRepeatInterval()); Trigger newTrigger = _quartzTriggerFactory.createTrigger( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, null, null, _DEFAULT_INTERVAL * 2, TimeUnit.SECOND); _quartzSchedulerEngine.update(newTrigger, StorageType.MEMORY); schedulerResponse = _quartzSchedulerEngine.getScheduledJob( _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY); trigger = schedulerResponse.getTrigger(); calendarIntervalTrigger = (CalendarIntervalTrigger) trigger.getWrappedTrigger(); Assert.assertEquals(_DEFAULT_INTERVAL * 2, calendarIntervalTrigger.getRepeatInterval()); }
protected void update( Scheduler scheduler, com.liferay.portal.kernel.scheduler.Trigger trigger, StorageType storageType) throws Exception { Trigger quartzTrigger = (Trigger) trigger.getWrappedTrigger(); if (quartzTrigger == null) { return; } TriggerKey triggerKey = quartzTrigger.getKey(); if (scheduler.getTrigger(triggerKey) != null) { scheduler.rescheduleJob(triggerKey, quartzTrigger); } else { JobKey jobKey = quartzTrigger.getJobKey(); JobDetail jobDetail = scheduler.getJobDetail(jobKey); if (jobDetail == null) { return; } synchronized (this) { scheduler.deleteJob(jobKey); scheduler.scheduleJob(jobDetail, quartzTrigger); } updateJobState(scheduler, jobKey, TriggerState.NORMAL, true); } }
@Override public void schedule( com.liferay.portal.kernel.scheduler.Trigger trigger, String description, String destination, Message message, StorageType storageType) throws SchedulerException { try { Scheduler scheduler = getScheduler(storageType); Trigger quartzTrigger = (Trigger) trigger.getWrappedTrigger(); if (quartzTrigger == null) { return; } description = fixMaxLength(description, _descriptionMaxLength, storageType); message = message.clone(); message.put(SchedulerEngine.GROUP_NAME, trigger.getGroupName()); message.put(SchedulerEngine.JOB_NAME, trigger.getJobName()); schedule(scheduler, storageType, quartzTrigger, description, destination, message); } catch (RuntimeException re) { if (PortalRunMode.isTestMode()) { StackTraceElement[] stackTraceElements = re.getStackTrace(); for (StackTraceElement stackTraceElement : stackTraceElements) { String className = stackTraceElement.getClassName(); if (className.contains(ServerDetector.class.getName())) { if (_log.isInfoEnabled()) { _log.info(re, re); } return; } throw new SchedulerException("Unable to schedule job", re); } } else { throw new SchedulerException("Unable to schedule job", re); } } catch (Exception e) { throw new SchedulerException("Unable to schedule job", e); } }
public MockScheduler(StorageType storageType, String defaultGroupName) { for (int i = 0; i < _DEFAULT_JOB_NUMBER; i++) { Trigger trigger = _quartzTriggerFactory.createTrigger( _TEST_JOB_NAME_PREFIX + i, defaultGroupName, null, null, _DEFAULT_INTERVAL, TimeUnit.SECOND); addJob( _TEST_JOB_NAME_PREFIX + i, defaultGroupName, storageType, (org.quartz.Trigger) trigger.getWrappedTrigger()); } }