⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobschedulingdataprocessor.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        maybeThrowValidationException();    }    /**     * Process the xml file in the default location, and schedule all of the     * jobs defined within it.     *       */    public void processFileAndScheduleJobs(Scheduler sched,            boolean overWriteExistingJobs) throws SchedulerException, Exception {        processFileAndScheduleJobs(QUARTZ_XML_FILE_NAME, sched,                overWriteExistingJobs);    }    /**     * Process the xml file in the given location, and schedule all of the     * jobs defined within it.     *      * @param fileName     *          meta data file name.     */    public void processFileAndScheduleJobs(String fileName, Scheduler sched,            boolean overWriteExistingJobs) throws Exception {        processFileAndScheduleJobs(fileName, fileName, sched, overWriteExistingJobs);    }        /**     * Process the xml file in the given location, and schedule all of the     * jobs defined within it.     *      * @param fileName     *          meta data file name.     */    public void processFileAndScheduleJobs(String fileName, String systemId,            Scheduler sched, boolean overWriteExistingJobs) throws Exception {        schedLocal.set(sched);        try {            processFile(fileName, systemId);            scheduleJobs(getScheduledJobs(), sched, overWriteExistingJobs);        } finally {            schedLocal.set(null);        }    }    /**     * Add the Jobs and Triggers defined in the given map of <code>JobSchedulingBundle</code>     * s to the given scheduler.     *      * @param jobBundles     * @param sched     * @param overWriteExistingJobs     * @throws Exception     */    public void scheduleJobs(Map jobBundles, Scheduler sched,            boolean overWriteExistingJobs) throws Exception {        getLog().info("Scheduling " + jobBundles.size() + " parsed jobs.");        Iterator itr = calsToSchedule.iterator();        while (itr.hasNext()) {            CalendarBundle bndle = (CalendarBundle) itr.next();            addCalendar(sched, bndle);        }        itr = jobsToSchedule.iterator();        while (itr.hasNext()) {            JobSchedulingBundle bndle = (JobSchedulingBundle) itr.next();            scheduleJob(bndle, sched, overWriteExistingJobs);        }    }    /**     * Returns a <code>Map</code> of scheduled jobs.     * <p/>     * The key is the job name and the value is a <code>JobSchedulingBundle</code>     * containing the <code>JobDetail</code> and <code>Trigger</code>.     *      * @return a <code>Map</code> of scheduled jobs.     */    public Map getScheduledJobs() {        return Collections.unmodifiableMap(scheduledJobs);    }    /**     * Returns a <code>JobSchedulingBundle</code> for the job name.     *      * @param name     *          job name.     * @return a <code>JobSchedulingBundle</code> for the job name.     */    public JobSchedulingBundle getScheduledJob(String name) {        return (JobSchedulingBundle) getScheduledJobs().get(name);    }    /**     * Returns an <code>InputStream</code> from the fileName as a resource.     *      * @param fileName     *          file name.     * @return an <code>InputStream</code> from the fileName as a resource.     */    protected InputStream getInputStream(String fileName) {        ClassLoader cl = Thread.currentThread().getContextClassLoader();        InputStream is = cl.getResourceAsStream(fileName);        return is;    }        /**     * Schedules a given job and trigger (both wrapped by a <code>JobSchedulingBundle</code>).     *      * @param job     *          job wrapper.     * @exception SchedulerException     *              if the Job or Trigger cannot be added to the Scheduler, or     *              there is an internal Scheduler error.     */    public void scheduleJob(JobSchedulingBundle job)        throws SchedulerException {        scheduleJob(job, (Scheduler) schedLocal.get(), getOverWriteExistingJobs());    }        public void addJobToSchedule(JobSchedulingBundle job)    {        jobsToSchedule.add(job);    }    public void addCalendarToSchedule(CalendarBundle cal)    {        calsToSchedule.add(cal);    }    /**     * Schedules a given job and trigger (both wrapped by a <code>JobSchedulingBundle</code>).     *      * @param job     *          job wrapper.     * @param sched     *          job scheduler.     * @param localOverWriteExistingJobs     *          locally overwrite existing jobs.     * @exception SchedulerException     *              if the Job or Trigger cannot be added to the Scheduler, or     *              there is an internal Scheduler error.     */    public void scheduleJob(JobSchedulingBundle job, Scheduler sched, boolean localOverWriteExistingJobs)            throws SchedulerException {        if ((job != null) && job.isValid()) {            JobDetail detail = job.getJobDetail();                        JobDetail dupeJ = sched.getJobDetail(detail.getName(), detail.getGroup());            if ((dupeJ != null) && !localOverWriteExistingJobs) {                getLog().debug("Not overwriting existing job: " + dupeJ.getFullName());                return;            }                        if (dupeJ != null) {                getLog().debug("Replacing job: " + detail.getFullName());            }            else {                getLog().debug("Adding job: " + detail.getFullName());            }                        if (job.getTriggers().size() == 0 && !job.getJobDetail().isDurable()) {                throw new SchedulerException("A Job defined without any triggers must be durable");            }            sched.addJob(detail, true);                        for (Iterator iter = job.getTriggers().iterator(); iter.hasNext(); ) {                Trigger trigger = (Trigger)iter.next();                                Trigger dupeT = sched.getTrigger(trigger.getName(), trigger.getGroup());                    trigger.setJobName(detail.getName());                trigger.setJobGroup(detail.getGroup());                                if (dupeT != null) {                    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 {                    getLog().debug(                        "Scheduling job: " + detail.getFullName() + " with trigger: " + trigger.getFullName());                    sched.scheduleJob(trigger);                }            }                        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_DTD);                    }                    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 exception     *          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 exception     *          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 exception     *          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 SAXException     *          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 {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -