📄 ramjobstore.java
字号:
grpMap.remove(triggerName); if (grpMap.size() == 0) triggersByGroup.remove(groupName); } // remove from triggers array Iterator tgs = triggers.iterator(); while (tgs.hasNext()) { tw = (TriggerWrapper) tgs.next(); if (key.equals(tw.key)) { tgs.remove(); break; } } timeTriggers.remove(tw); JobWrapper jw = (JobWrapper) jobsByFQN.get(JobWrapper .getJobNameKey(tw.trigger.getJobName(), tw.trigger .getJobGroup())); Trigger[] trigs = getTriggersForJob(ctxt, tw.trigger .getJobName(), tw.trigger.getJobGroup()); if ((trigs == null || trigs.length == 0) && !jw.jobDetail.isDurable()) removeJob(ctxt, tw.trigger.getJobName(), tw.trigger .getJobGroup()); } } return found; } /** * @see org.quartz.spi.JobStore#replaceTrigger(org.quartz.core.SchedulingContext, java.lang.String, java.lang.String, org.quartz.Trigger) */ public boolean replaceTrigger(SchedulingContext ctxt, String triggerName, String groupName, Trigger newTrigger) throws JobPersistenceException { String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName); boolean found = false; synchronized (triggerLock) { // remove from triggers by FQN map TriggerWrapper tw = (TriggerWrapper) triggersByFQN.remove(key); found = ( tw == null) ? false : true; if (found) { if(!tw.getTrigger().getJobName().equals(newTrigger.getJobName()) || !tw.getTrigger().getJobGroup().equals(newTrigger.getJobGroup())) throw new JobPersistenceException("New trigger is not related to the same job as the old trigger."); tw = null; // remove from triggers by group HashMap grpMap = (HashMap) triggersByGroup.get(groupName); if (grpMap != null) { grpMap.remove(triggerName); if (grpMap.size() == 0) triggersByGroup.remove(groupName); } // remove from triggers array Iterator tgs = triggers.iterator(); while (tgs.hasNext()) { tw = (TriggerWrapper) tgs.next(); if (key.equals(tw.key)) { tgs.remove(); break; } } timeTriggers.remove(tw); try { storeTrigger(ctxt, newTrigger, false); } catch(JobPersistenceException jpe) { storeTrigger(ctxt, tw.getTrigger(), false); // put previous trigger back... throw jpe; } } } return found; } /** * <p> * Retrieve the <code>{@link org.quartz.JobDetail}</code> for the given * <code>{@link org.quartz.Job}</code>. * </p> * * @param jobName * The name of the <code>Job</code> to be retrieved. * @param groupName * The group name of the <code>Job</code> to be retrieved. * @return The desired <code>Job</code>, or null if there is no match. */ public JobDetail retrieveJob(SchedulingContext ctxt, String jobName, String groupName) { JobWrapper jw = (JobWrapper) jobsByFQN.get(JobWrapper.getJobNameKey( jobName, groupName)); if (jw != null) return jw.jobDetail; return null; } /** * <p> * Retrieve the given <code>{@link org.quartz.Trigger}</code>. * </p> * * @param jobName * The name of the <code>Trigger</code> to be retrieved. * @param groupName * The group name of the <code>Trigger</code> to be retrieved. * @return The desired <code>Trigger</code>, or null if there is no * match. */ public Trigger retrieveTrigger(SchedulingContext ctxt, String triggerName, String groupName) { TriggerWrapper tw = (TriggerWrapper) triggersByFQN.get(TriggerWrapper .getTriggerNameKey(triggerName, groupName)); if (tw != null) return tw.getTrigger(); return null; } /** * <p> * Get the current state of the identified <code>{@link Trigger}</code>. * </p> * * @see Trigger#STATE_NORMAL * @see Trigger#STATE_PAUSED * @see Trigger#STATE_COMPLETE * @see Trigger#STATE_ERROR * @see Trigger#STATE_BLOCKED * @see Trigger#STATE_NONE */ public int getTriggerState(SchedulingContext ctxt, String triggerName, String groupName) throws JobPersistenceException { TriggerWrapper tw = (TriggerWrapper) triggersByFQN.get(TriggerWrapper .getTriggerNameKey(triggerName, groupName)); if (tw == null) return Trigger.STATE_NONE; if (tw.state == TriggerWrapper.STATE_COMPLETE) return Trigger.STATE_COMPLETE; if (tw.state == TriggerWrapper.STATE_PAUSED) return Trigger.STATE_PAUSED; if (tw.state == TriggerWrapper.STATE_BLOCKED) return Trigger.STATE_BLOCKED; return Trigger.STATE_NORMAL; } /** * <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. */ public void storeCalendar(SchedulingContext ctxt, String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers) throws ObjectAlreadyExistsException { Object obj = calendarsByName.get(name); if (obj != null && replaceExisting == false) throw new ObjectAlreadyExistsException( "Calendar with name '" + name + "' already exists."); else if (obj != null) calendarsByName.remove(name); calendarsByName.put(name, calendar); if(obj != null && updateTriggers) { synchronized (triggerLock) { Iterator trigs = getTriggerWrappersForCalendar(name).iterator(); while (trigs.hasNext()) { TriggerWrapper tw = (TriggerWrapper) trigs.next(); Trigger trig = tw.getTrigger(); boolean removed = timeTriggers.remove(tw); trig.updateWithNewCalendar(calendar, getMisfireThreshold()); if(removed) timeTriggers.add(tw); } } } } /** * <p> * Remove (delete) the <code>{@link org.quartz.Calendar}</code> with the * given name. * </p> * * <p> * If removal of the <code>Calendar</code> would result in * <code.Trigger</code>s pointing to non-existent calendars, then a * <code>JobPersistenceException</code> will be thrown.</p> * * * @param calName The name of the <code>Calendar</code> to be removed. * @return <code>true</code> if a <code>Calendar</code> with the given name * was found and removed from the store. */ public boolean removeCalendar(SchedulingContext ctxt, String calName) throws JobPersistenceException { int numRefs = 0; synchronized (triggerLock) { Iterator itr = triggers.iterator(); while (itr.hasNext()) { Trigger trigg = ((TriggerWrapper) itr.next()).trigger; if (trigg.getCalendarName() != null && trigg.getCalendarName().equals(calName)) numRefs++; } } if (numRefs > 0) throw new JobPersistenceException( "Calender cannot be removed if it referenced by a Trigger!"); return (calendarsByName.remove(calName) != null); } /** * <p> * Retrieve the given <code>{@link org.quartz.Trigger}</code>. * </p> * * @param calName * The name of the <code>Calendar</code> to be retrieved. * @return The desired <code>Calendar</code>, or null if there is no * match. */ public Calendar retrieveCalendar(SchedulingContext ctxt, String calName) { return (Calendar) calendarsByName.get(calName); } /** * <p> * Get the number of <code>{@link org.quartz.JobDetail}</code> s that are * stored in the <code>JobsStore</code>. * </p> */ public int getNumberOfJobs(SchedulingContext ctxt) { return jobsByFQN.size(); } /** * <p> * Get the number of <code>{@link org.quartz.Trigger}</code> s that are * stored in the <code>JobsStore</code>. * </p> */ public int getNumberOfTriggers(SchedulingContext ctxt) { return triggers.size(); } /** * <p> * Get the number of <code>{@link org.quartz.Calendar}</code> s that are * stored in the <code>JobsStore</code>. * </p> */ public int getNumberOfCalendars(SchedulingContext ctxt) { return calendarsByName.size(); } /** * <p> * Get the names of all of the <code>{@link org.quartz.Job}</code> s that * have the given group name. * </p> */ public String[] getJobNames(SchedulingContext ctxt, String groupName) { String[] outList = null; HashMap grpMap = (HashMap) jobsByGroup.get(groupName); if (grpMap != null) { synchronized (jobLock) { outList = new String[grpMap.size()]; int outListPos = 0; Iterator keys = grpMap.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); JobWrapper jw = (JobWrapper) grpMap.get(key); if (jw != null) outList[outListPos++] = jw.jobDetail.getName(); } } } else outList = new String[0]; return outList; } /** * <p> * Get the names of all of the <code>{@link org.quartz.Calendar}</code> s * in the <code>JobStore</code>. * </p> * * <p> * If there are no Calendars in the given group name, the result should be * a zero-length array (not <code>null</code>). * </p> */ public String[] getCalendarNames(SchedulingContext ctxt) { Set names = calendarsByName.keySet(); return (String[]) names.toArray(new String[names.size()]); } /** * <p> * Get the names of all of the <code>{@link org.quartz.Trigger}</code> s * that have the given group name. * </p> */ public String[] getTriggerNames(SchedulingContext ctxt, String groupName) { String[] outList = null; HashMap grpMap = (HashMap) triggersByGroup.get(groupName); if (grpMap != null) { synchronized (triggerLock) { outList = new String[grpMap.size()]; int outListPos = 0; Iterator keys = grpMap.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); TriggerWrapper tw = (TriggerWrapper) grpMap.get(key); if (tw != null) outList[outListPos++] = tw.trigger.getName(); } } } else outList = new String[0]; return outList; } /** * <p> * Get the names of all of the <code>{@link org.quartz.Job}</code> * groups. * </p> */ public String[] getJobGroupNames(SchedulingContext ctxt) { String[] outList = null; synchronized (jobLock) { outList = new String[jobsByGroup.size()]; int outListPos = 0; Iterator keys = jobsByGroup.keySet().iterator(); while (keys.hasNext()) { outList[outListPos++] = (String) keys.next(); } } return outList; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -