/** * <p> * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it * now) - with a non-volatile trigger. * </p> */ @SuppressWarnings("deprecation") public void triggerJob(JobKey jobKey, JobDataMap data) throws SchedulerException { validateState(); OperableTrigger trig = (OperableTrigger) newTrigger().withIdentity(newTriggerId(), Scheduler.DEFAULT_GROUP).forJob(jobKey).build(); trig.computeFirstFireTime(null); if(data != null) { trig.setJobDataMap(data); } boolean collision = true; while (collision) { try { resources.getJobStore().storeTrigger(trig, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP)); } } notifySchedulerThread(trig.getNextFireTime().getTime()); notifySchedulerListenersSchduled(trig); }
/** * <p> * Store and schedule the identified <code>{@link org.quartz.spi.OperableTrigger}</code> * </p> */ public void triggerJob(OperableTrigger trig) throws SchedulerException { validateState(); trig.computeFirstFireTime(null); boolean collision = true; while (collision) { try { resources.getJobStore().storeTrigger(trig, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP)); } } notifySchedulerThread(trig.getNextFireTime().getTime()); notifySchedulerListenersSchduled(trig); }
/** * <p> * Store the given <code>{@link org.quartz.JobDetail}</code> and <code>{@link org.quartz.Trigger}</code>. * </p> * * @param newJob * The <code>JobDetail</code> to be stored. * @param newTrigger * The <code>Trigger</code> to be stored. * @throws ObjectAlreadyExistsException * if a <code>Job</code> with the same name/group already * exists. */ public void storeJobAndTrigger(final SchedulingContext ctxt, final JobDetail newJob, final Trigger newTrigger) throws ObjectAlreadyExistsException, JobPersistenceException { executeInLock( (isLockOnInsert()) ? LOCK_TRIGGER_ACCESS : null, new VoidTransactionCallback() { public void execute(Connection conn) throws JobPersistenceException { if (newJob.isVolatile() && !newTrigger.isVolatile()) { JobPersistenceException jpe = new JobPersistenceException( "Cannot associate non-volatile trigger with a volatile job!"); jpe.setErrorCode(SchedulerException.ERR_CLIENT_ERROR); throw jpe; } storeJob(conn, ctxt, newJob, false); storeTrigger(conn, ctxt, newTrigger, newJob, false, Constants.STATE_WAITING, false, false); } }); }
/** * <p> * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it * now) - with a non-volatile trigger. * </p> */ public void triggerJob(SchedulingContext ctxt, String jobName, String groupName, JobDataMap data) throws SchedulerException { validateState(); if(groupName == null) { groupName = Scheduler.DEFAULT_GROUP; } Trigger trig = new org.quartz.SimpleTrigger(newTriggerId(), Scheduler.DEFAULT_MANUAL_TRIGGERS, jobName, groupName, new Date(), null, 0, 0); trig.setVolatility(false); trig.computeFirstFireTime(null); if(data != null) { trig.setJobDataMap(data); } boolean collision = true; while (collision) { try { resources.getJobStore().storeTrigger(ctxt, trig, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { trig.setName(newTriggerId()); } } notifySchedulerThread(trig.getNextFireTime().getTime()); notifySchedulerListenersSchduled(trig); }
/** * <p> * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it * now) - with a volatile trigger. * </p> */ public void triggerJobWithVolatileTrigger(SchedulingContext ctxt, String jobName, String groupName, JobDataMap data) throws SchedulerException { validateState(); if(groupName == null) { groupName = Scheduler.DEFAULT_GROUP; } Trigger trig = new org.quartz.SimpleTrigger(newTriggerId(), Scheduler.DEFAULT_MANUAL_TRIGGERS, jobName, groupName, new Date(), null, 0, 0); trig.setVolatility(true); trig.computeFirstFireTime(null); if(data != null) { trig.setJobDataMap(data); } boolean collision = true; while (collision) { try { resources.getJobStore().storeTrigger(ctxt, trig, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { trig.setName(newTriggerId()); } } notifySchedulerThread(trig.getNextFireTime().getTime()); notifySchedulerListenersSchduled(trig); }
private void scheduleJob(final JobDetail jobDetail, final Trigger trigger) throws SchedulerException { final boolean triggerExists = (this.scheduler.getTrigger(trigger.getKey()) != null); this.scheduler.addJob(jobDetail, true); if (triggerExists) { this.scheduler.rescheduleJob(trigger.getKey(), trigger); } else { try { this.scheduler.scheduleJob(trigger); } catch (ObjectAlreadyExistsException ex) { LOG.debug("Unexpectedly found existing trigger, assumably due to cluster race condition: " + ex.getMessage() + " - can safely be ignored"); this.scheduler.rescheduleJob(trigger.getKey(), trigger); } } }
private void storeJob(final ODatabaseDocumentTx db, final JobDetail jobDetail, final boolean replaceExisting) throws JobPersistenceException { log.debug("Store job: jobDetail={}, replaceExisting={}", jobDetail, replaceExisting); JobDetailEntity entity = jobDetailEntityAdapter.readByKey(db, jobDetail.getKey()); if (entity == null) { // no existing entity, add new one entity = new JobDetailEntity(jobDetail); jobDetailEntityAdapter.addEntity(db, entity); } else { // otherwise entity exists, maybe replace if allowed if (replaceExisting) { entity.setValue(jobDetail); jobDetailEntityAdapter.editEntity(db, entity); } else { throw new ObjectAlreadyExistsException(jobDetail); } } }
@Override public void storeJob(final JobDetail job, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { final JobDetail newJob = (JobDetail) job.clone(); final JobKey newJobKey = newJob.getKey(); if (jobsByKey.containsKey(newJobKey) && !replaceExisting) { throw new ObjectAlreadyExistsException(newJob); } jobsByKey.lock(newJobKey, 5, TimeUnit.SECONDS); try { jobsByKey.set(newJobKey, newJob); jobsByGroup.put(newJobKey.getGroup(), newJobKey); } finally { try { jobsByKey.unlock(newJobKey); } catch (IllegalMonitorStateException ex) { LOG.warn("Error unlocking since it is already released.", ex); } } }
@Test public void testStoreTriggerReplacesTrigger() throws Exception { JobDetail job = buildJob("replacesTrigJob99", "replacesTrigJobGroup"); jobStore.storeJob(job, false); OperableTrigger tr = buildTrigger("stReplacesTrigger1", "stReplacesTriggerGroup", job, new Date().getTime()); tr.setCalendarName(null); jobStore.storeTrigger(tr, false); assertEquals(jobStore.retrieveTrigger(tr.getKey()), tr); try { jobStore.storeTrigger(tr, false); fail("an attempt to store duplicate trigger succeeded"); } catch (ObjectAlreadyExistsException ex) { // expected } tr.setCalendarName("QQ"); jobStore.storeTrigger(tr, true); assertEquals(jobStore.retrieveTrigger(tr.getKey()), tr); assertEquals(jobStore.retrieveTrigger(tr.getKey()).getCalendarName(), "QQ", "StoreJob doesn't replace triggers"); }
@Test public void testRemoveTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail storeJob = storeJob(buildJob("job")); OperableTrigger trigger1 = buildTrigger(storeJob); TriggerKey triggerKey = trigger1.getKey(); jobStore.storeTrigger(trigger1, false); OperableTrigger retrieveTrigger = retrieveTrigger(trigger1.getKey()); assertNotNull(retrieveTrigger); boolean removeTrigger = jobStore.removeTrigger(triggerKey); assertTrue(removeTrigger); retrieveTrigger = retrieveTrigger(trigger1.getKey()); assertNull(retrieveTrigger); removeTrigger = jobStore.removeTrigger(triggerKey); assertFalse(removeTrigger); Trigger.TriggerState triggerState = jobStore.getTriggerState(triggerKey); assertEquals(triggerState, Trigger.TriggerState.NONE); }
@Test public void testTriggerCheckExists() throws ObjectAlreadyExistsException, JobPersistenceException { OperableTrigger trigger1 = buildTrigger(); TriggerKey triggerKey = trigger1.getKey(); boolean checkExists = jobStore.checkExists(triggerKey); assertFalse(checkExists); jobStore.storeTrigger(trigger1, false); checkExists = jobStore.checkExists(triggerKey); assertTrue(checkExists); }
@Test public void testReplaceTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { OperableTrigger trigger1 = buildTrigger(); jobStore.storeTrigger(trigger1, false); OperableTrigger newTrigger = buildTrigger(); TriggerKey triggerKey = trigger1.getKey(); boolean replaceTrigger = jobStore.replaceTrigger(triggerKey, (OperableTrigger) newTrigger); assertTrue(replaceTrigger); OperableTrigger retrieveTrigger = jobStore.retrieveTrigger(triggerKey); assertEquals(retrieveTrigger, newTrigger); }
@Test public void testRemoveCalendar() throws ObjectAlreadyExistsException, JobPersistenceException { String calName = "calendar1"; storeCalendar(calName); Calendar retrieveCalendar = jobStore.retrieveCalendar(calName); assertNotNull(retrieveCalendar); boolean calendarExisted = jobStore.removeCalendar(calName); assertTrue(calendarExisted); retrieveCalendar = jobStore.retrieveCalendar(calName); assertNull(retrieveCalendar); calendarExisted = jobStore.removeCalendar(calName); assertFalse(calendarExisted); }
@Test public void testGetJobGroupNames() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail buildJob = buildJob("job40", "group1"); storeJob(buildJob); storeJob(buildJob("job41", "group2")); List<String> jobGroupNames = jobStore.getJobGroupNames(); assertEquals(jobGroupNames.size(), 2); assertTrue(jobGroupNames.contains("group1")); assertTrue(jobGroupNames.contains("group2")); jobStore.removeJob(buildJob.getKey()); jobGroupNames = jobStore.getJobGroupNames(); assertEquals(jobGroupNames.size(), 1); assertTrue(jobGroupNames.contains("group2")); }
@Test public void testResumeTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { OperableTrigger trigger = buildTrigger(); jobStore.storeTrigger(trigger, false); TriggerKey triggerKey = trigger.getKey(); Trigger.TriggerState triggerState = jobStore.getTriggerState(triggerKey); assertEquals(triggerState, Trigger.TriggerState.NORMAL); jobStore.pauseTrigger(triggerKey); triggerState = jobStore.getTriggerState(triggerKey); assertEquals(triggerState, Trigger.TriggerState.PAUSED); jobStore.resumeTrigger(triggerKey); triggerState = jobStore.getTriggerState(triggerKey); assertEquals(triggerState, Trigger.TriggerState.NORMAL); }
@Test public void testPauseJob() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail jobDetail = buildAndStoreJob(); OperableTrigger trigger = buildTrigger(jobDetail); jobStore.storeTrigger(trigger, false); Trigger.TriggerState triggerState = jobStore.getTriggerState(trigger.getKey()); assertEquals(triggerState, Trigger.TriggerState.NORMAL); jobStore.pauseJob(jobDetail.getKey()); triggerState = jobStore.getTriggerState(trigger.getKey()); assertEquals(triggerState, Trigger.TriggerState.PAUSED); }
@Test public void testResumeJob() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail jobDetail = buildAndStoreJob(); OperableTrigger trigger = buildTrigger(jobDetail); jobStore.storeTrigger(trigger, false); Trigger.TriggerState triggerState = jobStore.getTriggerState(trigger.getKey()); assertEquals(triggerState, Trigger.TriggerState.NORMAL); jobStore.pauseJob(jobDetail.getKey()); triggerState = jobStore.getTriggerState(trigger.getKey()); assertEquals(triggerState, Trigger.TriggerState.PAUSED); jobStore.resumeJob(jobDetail.getKey()); triggerState = jobStore.getTriggerState(trigger.getKey()); assertEquals(triggerState, Trigger.TriggerState.NORMAL); }
/** * Stores job in redis. * * @param newJob the new job * @param replaceExisting the replace existing * @param jedis thread-safe redis connection * @throws ObjectAlreadyExistsException */ private void storeJob(JobDetail newJob, boolean replaceExisting, Jedis jedis) throws ObjectAlreadyExistsException { String jobHashKey = createJobHashKey(newJob.getKey().getGroup(), newJob.getKey().getName()); String jobDataMapHashKey = createJobDataMapHashKey(newJob.getKey().getGroup(), newJob.getKey().getName()); String jobGroupSetKey = createJobGroupSetKey(newJob.getKey().getGroup()); if (jedis.exists(jobHashKey) && !replaceExisting) throw new ObjectAlreadyExistsException(newJob); Map<String, String> jobDetails = new HashMap<>(); jobDetails.put(DESCRIPTION, newJob.getDescription() != null ? newJob.getDescription() : ""); jobDetails.put(JOB_CLASS, newJob.getJobClass().getName()); jobDetails.put(IS_DURABLE, Boolean.toString(newJob.isDurable())); jobDetails.put(BLOCKED_BY, ""); jobDetails.put(BLOCK_TIME, ""); jedis.hmset(jobHashKey, jobDetails); if (newJob.getJobDataMap() != null && !newJob.getJobDataMap().isEmpty()) jedis.hmset(jobDataMapHashKey, getStringDataMap(newJob.getJobDataMap())); jedis.sadd(JOBS_SET, jobHashKey); jedis.sadd(JOB_GROUPS_SET, jobGroupSetKey); jedis.sadd(jobGroupSetKey, jobHashKey); }
protected void addTrigger(Trigger trigger) { try { if (UNSCHEDULED_GROUP.equals(trigger.getGroup())) { LOG.error("Triggers should not be specified for jobs in the unscheduled group - not adding trigger: " + trigger.getName()); } else { LOG.info("Adding trigger: " + trigger.getName()); try { scheduler.scheduleJob(trigger); } catch (ObjectAlreadyExistsException ex) { } } } catch (SchedulerException e) { throw new RuntimeException("Caught exception while adding trigger: " + trigger.getFullName(), e); } }
@Override public void storeJob(final JobDetail job, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { final JobDetail newJob = (JobDetail) job.clone(); final JobKey newJobKey = newJob.getKey(); if (jobsByKey.containsKey(newJobKey) && !replaceExisting) { throw new ObjectAlreadyExistsException(newJob); } jobsByKey.lock(newJobKey); try { jobsByKey.put(newJobKey, newJob); jobsByGroup.put(newJobKey.getGroup(), newJobKey); } finally { jobsByKey.unlock(newJobKey); } }
@Test public void testRemoveJob() throws ObjectAlreadyExistsException, JobPersistenceException { String jobName = "job22"; JobDetail jobDetail = buildJob(jobName); storeJob(jobDetail); JobDetail retrieveJob = retrieveJob(jobName); assertThat(retrieveJob).isNotNull(); Trigger trigger = buildTrigger(jobDetail); storeTrigger(trigger); assertThat(retrieveTrigger(trigger.getKey())).isNotNull(); boolean removeJob = this.jobStore.removeJob(jobDetail.getKey()); assertThat(removeJob).isTrue(); retrieveJob = retrieveJob(jobName); assertThat(retrieveJob).isNull(); assertThat(retrieveTrigger(trigger.getKey())).isNull(); removeJob = this.jobStore.removeJob(jobDetail.getKey()); assertThat(removeJob).isFalse(); }
@Test public void testRemoveJobs() throws ObjectAlreadyExistsException, JobPersistenceException { String jobName = "job24"; JobDetail jobDetail = buildJob(jobName); String jobName2 = "job25"; JobDetail jobDetailImpl2 = buildJob(jobName2); this.jobStore.storeJob(jobDetail, false); this.jobStore.storeJob(jobDetailImpl2, false); JobDetail retrieveJob = retrieveJob(jobName); assertThat(retrieveJob).isNotNull(); List<JobKey> jobKeyList = Lists.newArrayList(jobDetail.getKey(), jobDetailImpl2.getKey()); boolean removeJob = this.jobStore.removeJobs(jobKeyList); assertThat(removeJob).isTrue(); retrieveJob = retrieveJob(jobName); assertThat(retrieveJob).isNull(); retrieveJob = retrieveJob(jobName2); assertThat(retrieveJob).isNull(); removeJob = this.jobStore.removeJob(jobDetail.getKey()); assertThat(removeJob).isFalse(); removeJob = this.jobStore.removeJob(jobDetailImpl2.getKey()); assertThat(removeJob).isFalse(); }
@Test public void testRemoveTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail storeJob = storeJob(buildJob("job")); Trigger trigger1 = buildTrigger(storeJob); TriggerKey triggerKey = trigger1.getKey(); storeTrigger(trigger1); Trigger retrieveTrigger = retrieveTrigger(trigger1.getKey()); assertThat(retrieveTrigger).isNotNull(); boolean removeTrigger = jobStore.removeTrigger(triggerKey); assertThat(removeTrigger).isTrue(); retrieveTrigger = retrieveTrigger(trigger1.getKey()); assertThat(retrieveTrigger).isNull(); removeTrigger = jobStore.removeTrigger(triggerKey); assertThat(removeTrigger).isFalse(); TriggerState triggerState = jobStore.getTriggerState(triggerKey); assertThat(triggerState).isEqualTo(TriggerState.NONE); }
@Test public void testReplaceTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { Trigger trigger1 = buildTrigger(); storeTrigger(trigger1); Trigger newTrigger = buildTrigger(); TriggerKey triggerKey = trigger1.getKey(); boolean replaceTrigger = jobStore.replaceTrigger(triggerKey, (OperableTrigger) newTrigger); assertThat(replaceTrigger).isTrue(); Trigger retrieveTrigger = jobStore.retrieveTrigger(triggerKey); assertThat(retrieveTrigger).isEqualTo(newTrigger); }
@Test public void testRemoveCalendar() throws ObjectAlreadyExistsException, JobPersistenceException { String calName = "calendar1"; storeCalendar(calName); Calendar retrieveCalendar = jobStore.retrieveCalendar(calName); assertThat(retrieveCalendar).isNotNull(); boolean calendarExisted = jobStore.removeCalendar(calName); assertThat(calendarExisted).isTrue(); retrieveCalendar = jobStore.retrieveCalendar(calName); assertThat(retrieveCalendar).isNull(); calendarExisted = jobStore.removeCalendar(calName); assertThat(calendarExisted).isFalse(); }
@Test public void testJobKeyByGroup() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail job1group1 = buildJob("job1", "group1"); storeJob(job1group1); JobDetail job1group2 = buildJob("job1", "group2"); storeJob(job1group2); storeJob(buildJob("job2", "group2")); List<String> jobGroupNames = jobStore.getJobGroupNames(); assertThat(jobGroupNames).containsOnly("group1", "group2"); this.jobStore.removeJob(job1group1.getKey()); jobGroupNames = jobStore.getJobGroupNames(); assertThat(jobGroupNames).containsOnly("group2"); this.jobStore.removeJob(job1group2.getKey()); jobGroupNames = jobStore.getJobGroupNames(); assertThat(jobGroupNames).containsOnly("group2"); }
@Test public void testResumeTrigger() throws ObjectAlreadyExistsException, JobPersistenceException { Trigger trigger = buildTrigger(); storeTrigger(trigger); TriggerKey triggerKey = trigger.getKey(); TriggerState triggerState = jobStore.getTriggerState(triggerKey); assertThat(triggerState).isEqualTo(TriggerState.NORMAL); jobStore.pauseTrigger(triggerKey); triggerState = jobStore.getTriggerState(triggerKey); assertThat(triggerState).isEqualTo(TriggerState.PAUSED); jobStore.resumeTrigger(triggerKey); triggerState = jobStore.getTriggerState(triggerKey); assertThat(triggerState).isEqualTo(TriggerState.NORMAL); }
@Test public void testResumeTriggerWithPausedJobs() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail job1 = buildJob("job", "group3"); storeJob(job1); Trigger trigger5 = buildTrigger(job1); storeTrigger(trigger5); assertThat(jobStore.getTriggerState(trigger5.getKey())).isEqualTo( TriggerState.NORMAL); jobStore.pauseJobs(GroupMatcher.jobGroupEquals("group3")); jobStore.resumeTriggers(GroupMatcher.triggerGroupEquals(trigger5.getKey() .getGroup())); assertThat(jobStore.getTriggerState(trigger5.getKey())).isEqualTo( TriggerState.PAUSED); }
@Test public void testResumeJob() throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail jobDetail = buildAndStoreJob(); Trigger trigger = buildTrigger(jobDetail); storeTrigger(trigger); TriggerState triggerState = jobStore.getTriggerState(trigger.getKey()); assertThat(triggerState).isEqualTo(TriggerState.NORMAL); jobStore.pauseJob(jobDetail.getKey()); triggerState = jobStore.getTriggerState(trigger.getKey()); assertThat(triggerState).isEqualTo(TriggerState.PAUSED); jobStore.resumeJob(jobDetail.getKey()); triggerState = jobStore.getTriggerState(trigger.getKey()); assertThat(triggerState).isEqualTo(TriggerState.NORMAL); }
@Test public void testPauseAll() throws ObjectAlreadyExistsException, JobPersistenceException { Trigger trigger = buildAndStoreTrigger(); Trigger trigger2 = buildTrigger("trigger2", "group2", buildAndStoreJob()); storeTrigger(trigger2); assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo( TriggerState.NORMAL); jobStore.pauseAll(); assertThat(jobStore.getPausedTriggerGroups()).containsOnly( trigger.getKey().getGroup(), trigger2.getKey().getGroup()); Trigger trigger3 = buildAndStoreTrigger(); assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo( TriggerState.PAUSED); assertThat(jobStore.getTriggerState(trigger2.getKey())).isEqualTo( TriggerState.PAUSED); assertThat(jobStore.getTriggerState(trigger3.getKey())).isEqualTo( TriggerState.PAUSED); }
public void storeTrigger(CouchDbTrigger newTrigger, boolean replaceExisting) throws JobPersistenceException { CouchDbTrigger existingTrigger = getTriggerByKey(newTrigger.getKey()); if (existingTrigger == null) { db.create(newTrigger); return; } if (replaceExisting) { if (!(existingTrigger.getJobName().equals(newTrigger.getJobKey().getName()) && existingTrigger.getJobGroup().equals(newTrigger.getJobKey().getGroup()))) { throw new JobPersistenceException("New trigger is not related to the same job as the old trigger."); } newTrigger.setName(existingTrigger.getName()); newTrigger.setGroup(existingTrigger.getGroup()); newTrigger.setRevision(existingTrigger.getRevision()); if (logger.isDebugEnabled()) { logger.debug(String.format("Document ID : %s; Revision: %s", newTrigger.getId(), newTrigger.getRevision())); } db.update(newTrigger); } else { throw new ObjectAlreadyExistsException("trigger already exists " + newTrigger.getKey()); } }
/** * Add the given trigger to the Scheduler, if it doesn't already exist. * Overwrites the trigger in any case if "overwriteExistingJobs" is set. * @param trigger the trigger to add * @return {@code true} if the trigger was actually added, * {@code false} if it already existed before * @see #setOverwriteExistingJobs */ private boolean addTriggerToScheduler(Trigger trigger) throws SchedulerException { boolean triggerExists = triggerExists(trigger); if (!triggerExists || this.overwriteExistingJobs) { // Check if the Trigger is aware of an associated JobDetail. JobDetail jobDetail = findJobDetail(trigger); if (jobDetail != null) { // Automatically register the JobDetail too. if (!this.jobDetails.contains(jobDetail) && addJobToScheduler(jobDetail)) { this.jobDetails.add(jobDetail); } } if (!triggerExists) { try { getScheduler().scheduleJob(trigger); } catch (ObjectAlreadyExistsException ex) { if (logger.isDebugEnabled()) { logger.debug("Unexpectedly found existing trigger, assumably due to cluster race condition: " + ex.getMessage() + " - can safely be ignored"); } if (this.overwriteExistingJobs) { rescheduleJob(trigger); } } } else { rescheduleJob(trigger); } return true; } else { return false; } }
@Override public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers) throws ObjectAlreadyExistsException, JobPersistenceException { try { realJobStore.storeCalendar(name, calendar, replaceExisting, updateTriggers); } catch (RejoinException e) { throw new JobPersistenceException("Storing calendar failed due to client rejoin", e); } }
@Override public void storeJob(JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { try { realJobStore.storeJob(newJob, replaceExisting); } catch (RejoinException e) { throw new JobPersistenceException("Storing job failed due to client rejoin", e); } }
@Override public void storeJobAndTrigger(JobDetail newJob, OperableTrigger newTrigger) throws ObjectAlreadyExistsException, JobPersistenceException { try { realJobStore.storeJobAndTrigger(newJob, newTrigger); } catch (RejoinException e) { throw new JobPersistenceException("Storing job and trigger failed due to client rejoin", e); } }
@Override public void storeTrigger(OperableTrigger newTrigger, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { try { realJobStore.storeTrigger(newTrigger, replaceExisting); } catch (RejoinException e) { throw new JobPersistenceException("Storing trigger failed due to client rejoin", e); } }
@Override public void storeJobsAndTriggers(Map<JobDetail, Set<? extends Trigger>> arg0, boolean arg1) throws ObjectAlreadyExistsException, JobPersistenceException { try { realJobStore.storeJobsAndTriggers(arg0, arg1); } catch (RejoinException e) { throw new JobPersistenceException("Store jobs and triggers failed due to client rejoin", e); } }
/** * <p> * Store the given <code>{@link org.quartz.Job}</code>. * </p> * * @param newJob The <code>Job</code> to be stored. * @param replaceExisting If <code>true</code>, any <code>Job</code> existing in the <code>JobStore</code> with the * same name & group should be over-written. * @throws ObjectAlreadyExistsException if a <code>Job</code> with the same name/group already exists, and * replaceExisting is set to false. */ @Override public void storeJob(JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { JobDetail clone = (JobDetail) newJob.clone(); lock(); try { // wrapper construction must be done in lock since serializer is unlocked JobWrapper jw = wrapperFactory.createJobWrapper(clone); if (jobFacade.containsKey(jw.getKey())) { if (!replaceExisting) { throw new ObjectAlreadyExistsException(newJob); } } else { // get job group Set<String> grpSet = toolkitDSHolder.getOrCreateJobsGroupMap(newJob.getKey().getGroup()); // add to jobs by group grpSet.add(jw.getKey().getName()); if (!jobFacade.hasGroup(jw.getKey().getGroup())) { jobFacade.addGroup(jw.getKey().getGroup()); } } // add/update jobs FQN map jobFacade.put(jw.getKey(), jw); } finally { unlock(); } }
/** * <p> * Store the given <code>{@link org.quartz.Calendar}</code>. * </p> * * @param calendar The <code>Calendar</code> to be stored. * @param replaceExisting If <code>true</code>, any <code>Calendar</code> existing in the <code>JobStore</code> with * the same name & group should be over-written. * @param updateTriggers If <code>true</code>, any <code>Trigger</code>s existing in the <code>JobStore</code> that * reference an existing Calendar with the same name with have their next fire time re-computed with the new * <code>Calendar</code>. * @throws ObjectAlreadyExistsException if a <code>Calendar</code> with the same name already exists, and * replaceExisting is set to false. */ @Override public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers) throws ObjectAlreadyExistsException, JobPersistenceException { Calendar clone = (Calendar) calendar.clone(); lock(); try { Calendar cal = calendarsByName.get(name); if (cal != null && replaceExisting == false) { throw new ObjectAlreadyExistsException("Calendar with name '" + name + "' already exists."); } else if (cal != null) { calendarsByName.remove(name); } Calendar cw = clone; calendarsByName.putNoReturn(name, cw); if (cal != null && updateTriggers) { for (TriggerWrapper tw : triggerFacade.getTriggerWrappersForCalendar(name)) { boolean removed = timeTriggers.remove(tw); tw.updateWithNewCalendar(clone, getMisfireThreshold(), triggerFacade); if (removed) { timeTriggers.add(tw); } } } } finally { unlock(); } }