📄 jobschedulingdataprocessor.java
字号:
throws SchedulerException { if ((job != null) && job.isValid()) { JobDetail detail = job.getJobDetail(); JobDetail dupeJ = sched.getJobDetail(detail.getName(), detail.getGroup()); if ((dupeJ != null) && !localOverWriteExistingJobs) { getLog().info("Not overwriting existing job: " + dupeJ.getFullName()); return; } if (dupeJ != null) { getLog().info("Replacing job: " + detail.getFullName()); } else { getLog().info("Adding job: " + detail.getFullName()); } if (job.getTriggers().size() == 0 && !job.getJobDetail().isDurable()) { if (dupeJ == null) { throw new SchedulerException( "A new job defined without any triggers must be durable: " + detail.getFullName()); } if ((dupeJ.isDurable() && (sched.getTriggersOfJob( detail.getName(), detail.getGroup()).length == 0))) { throw new SchedulerException( "Can't make a durable job without triggers non-durable: " + detail.getFullName()); } } sched.addJob(detail, true); for (Iterator iter = job.getTriggers().iterator(); iter.hasNext(); ) { Trigger trigger = (Trigger)iter.next(); trigger.setJobName(detail.getName()); trigger.setJobGroup(detail.getGroup()); if(trigger.getStartTime() == null) { trigger.setStartTime(new Date()); } boolean addedTrigger = false; while (addedTrigger == false) { Trigger dupeT = sched.getTrigger(trigger.getName(), trigger.getGroup()); if (dupeT != null) { if (getLog().isDebugEnabled()) { getLog().debug( "Rescheduling job: " + detail.getFullName() + " with updated trigger: " + trigger.getFullName()); } if(!dupeT.getJobGroup().equals(trigger.getJobGroup()) || !dupeT.getJobName().equals(trigger.getJobName())) { getLog().warn("Possibly duplicately named triggers in jobs xml file!"); } sched.rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); } else { if (getLog().isDebugEnabled()) { getLog().debug( "Scheduling job: " + detail.getFullName() + " with trigger: " + trigger.getFullName()); } try { sched.scheduleJob(trigger); } catch (ObjectAlreadyExistsException e) { if (getLog().isDebugEnabled()) { getLog().debug( "Adding trigger: " + trigger.getFullName() + " for job: " + detail.getFullName() + " failed because the trigger already existed. " + "This is likely due to a race condition between multiple instances " + "in the cluster. Will try to reschedule instead."); } continue; } } addedTrigger = true; } } addScheduledJob(job); } } /** * Adds a scheduled job. * * @param job * job wrapper. */ protected void addScheduledJob(JobSchedulingBundle job) { scheduledJobs.put(job.getFullName(), job); } /** * Adds a calendar. * * @param calendarBundle calendar bundle. * @throws SchedulerException if the Calendar cannot be added to the Scheduler, or * there is an internal Scheduler error. */ public void addCalendar(Scheduler sched, CalendarBundle calendarBundle) throws SchedulerException { sched.addCalendar( calendarBundle.getCalendarName(), calendarBundle.getCalendar(), calendarBundle.getReplace(), true); } /** * EntityResolver interface. * <p/> * Allow the application to resolve external entities. * <p/> * Until <code>quartz.dtd</code> has a public ID, it must resolved as a * system ID. Here's the order of resolution (if one fails, continue to the * next). * <ol> * <li>Tries to resolve the <code>systemId</code> with <code>ClassLoader.getResourceAsStream(String)</code>. * </li> * <li>If the <code>systemId</code> starts with <code>QUARTZ_SYSTEM_ID_PREFIX</code>, * then resolve the part after <code>QUARTZ_SYSTEM_ID_PREFIX</code> with * <code>ClassLoader.getResourceAsStream(String)</code>.</li> * <li>Else try to resolve <code>systemId</code> as a URL. * <li>If <code>systemId</code> has a colon in it, create a new <code>URL</code> * </li> * <li>Else resolve <code>systemId</code> as a <code>File</code> and * then call <code>File.toURL()</code>.</li> * </li> * </ol> * <p/> * If the <code>publicId</code> does exist, resolve it as a URL. If the * <code>publicId</code> is the Quartz public ID, then resolve it locally. * * @param publicId * The public identifier of the external entity being referenced, * or null if none was supplied. * @param systemId * The system identifier of the external entity being referenced. * @return An InputSource object describing the new input source, or null * to request that the parser open a regular URI connection to the * system identifier. * @exception SAXException * Any SAX exception, possibly wrapping another exception. * @exception IOException * A Java-specific IO exception, possibly the result of * creating a new InputStream or Reader for the InputSource. */ public InputSource resolveEntity(String publicId, String systemId) { InputSource inputSource = null; InputStream is = null; URL url = null; try { if (publicId == null) { if (systemId != null) { // resolve Quartz Schema locally if (QUARTZ_SCHEMA.equals(systemId)) { is = getClass().getResourceAsStream(QUARTZ_XSD); } else { is = getInputStream(systemId); if (is == null) { int start = systemId.indexOf(QUARTZ_SYSTEM_ID_PREFIX); if (start > -1) { String fileName = systemId .substring(QUARTZ_SYSTEM_ID_PREFIX.length()); is = getInputStream(fileName); } else { if (systemId.indexOf(':') == -1) { File file = new java.io.File(systemId); url = file.toURL(); } else { url = new URL(systemId); } is = url.openStream(); } } } } } else { // resolve Quartz DTD locally if (QUARTZ_PUBLIC_ID.equals(publicId)) { is = getClass().getResourceAsStream(QUARTZ_DTD); } else { url = new URL(systemId); is = url.openStream(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (is != null) { inputSource = new InputSource(is); inputSource.setPublicId(publicId); inputSource.setSystemId(systemId); } } return inputSource; } /** * ErrorHandler interface. * * Receive notification of a warning. * * @param e * The error information encapsulated in a SAX parse exception. * @exception SAXException * Any SAX exception, possibly wrapping another exception. */ public void warning(SAXParseException e) throws SAXException { addValidationException(e); } /** * ErrorHandler interface. * * Receive notification of a recoverable error. * * @param e * The error information encapsulated in a SAX parse exception. * @exception SAXException * Any SAX exception, possibly wrapping another exception. */ public void error(SAXParseException e) throws SAXException { addValidationException(e); } /** * ErrorHandler interface. * * Receive notification of a non-recoverable error. * * @param e * The error information encapsulated in a SAX parse exception. * @exception SAXException * Any SAX exception, possibly wrapping another exception. */ public void fatalError(SAXParseException e) throws SAXException { addValidationException(e); } /** * Adds a detected validation exception. * * @param e * SAX exception. */ protected void addValidationException(SAXException e) { validationExceptions.add(e); } /** * Resets the the number of detected validation exceptions. */ protected void clearValidationExceptions() { validationExceptions.clear(); } /** * Throws a ValidationException if the number of validationExceptions * detected is greater than zero. * * @exception ValidationException * DTD validation exception. */ protected void maybeThrowValidationException() throws ValidationException { if (validationExceptions.size() > 0) { throw new ValidationException(validationExceptions); } } /** * RuleSet for common Calendar tags. * * @author <a href="mailto:bonhamcm@thirdeyeconsulting.com">Chris Bonham</a> */ public class CalendarRuleSet extends RuleSetBase { protected String prefix; protected String setNextMethodName; public CalendarRuleSet(String prefix, String setNextMethodName) { super(); this.prefix = prefix; this.setNextMethodName = setNextMethodName; } public void addRuleInstances(Digester digester) { digester.addObjectCreate(prefix, CalendarBundle.class); digester.addSetProperties(prefix, TAG_CLASS_NAME, "className"); digester.addBeanPropertySetter(prefix + "/" + TAG_NAME, "calendarName"); digester.addBeanPropertySetter(prefix + "/" + TAG_DESCRIPTION, "description"); digester.addSetNext(prefix, setNextMethodName); } } /** * RuleSet for common Trigger tags. * * @author <a href="mailto:bonhamcm@thirdeyeconsulting.com">Chris Bonham</a> */ public class TriggerRuleSet extends RuleSetBase { protected String prefix; protected Class clazz; public TriggerRuleSet(String prefix, Class clazz) { super(); this.prefix = prefix; if (!Trigger.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class must be an instance of Trigger"); } this.clazz = clazz; } public void addRuleInstances(Digester digester) { digester.addObjectCreate(prefix, clazz); digester.addBeanPropertySetter(prefix + "/" + TAG_NAME, "name"); digester.addBeanPropertySetter(prefix + "/" + TAG_GROUP, "group"); digester.addBeanPropertySetter(prefix + "/" + TAG_DESCRIPTION, "description"); digester.addBeanPropertySetter(prefix + "/" + TAG_VOLATILITY, "volatility"); digester.addRule(prefix + "/" + TAG_MISFIRE_INSTRUCTION, new MisfireInstructionRule("misfireInstruction")); digester.addBeanPropertySetter(prefix + "/" + TAG_CALENDAR_NAME, "calendarName"); digester.addObjectCreate(prefix + "/" + TAG_JOB_DATA_MAP, JobDataMap.class); digester.addCallMethod(prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY, "put", 2, new Class[] { Object.class, Object.class }); digester.addCallParam(prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_KEY, 0); digester.addCallParam(prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_VALUE, 1); digester.addSetNext(prefix + "/" + TAG_JOB_DATA_MAP, "setJobDataMap"); digester.addBeanPropertySetter(prefix + "/" + TAG_JOB_NAME, "jobName"); digester.addBeanPropertySetter(prefix + "/" + TAG_JOB_GROUP, "jobGroup"); Converter converter = new DateConverter(new String[] { XSD_DATE_FORMAT, DTD_DATE_FORMAT }); digester.addRule(prefix + "/" + TAG_START_TIME, new SimpleConverterRule("startTime", converter, Date.class)); digester.addRule(prefix + "/" + TAG_END_TIME, new SimpleConverterRule("endTime", converter, Date.class)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -