📄 jobschedulingdataprocessor.java
字号:
}
}
protected Log getLog() {
return log;
}
/**
* Returns whether to use the context class loader.
*
* @return whether to use the context class loader.
*/
public boolean getUseContextClassLoader() {
return digester.getUseContextClassLoader();
}
/**
* Sets whether to use the context class loader.
*
* @param useContextClassLoader boolean.
*/
public void setUseContextClassLoader(boolean useContextClassLoader) {
digester.setUseContextClassLoader(useContextClassLoader);
}
/**
* Returns whether to overwrite existing jobs.
*
* @return whether to overwrite existing jobs.
*/
public boolean getOverWriteExistingJobs() {
return overWriteExistingJobs;
}
/**
* Sets whether to overwrite existing jobs.
*
* @param overWriteExistingJobs boolean.
*/
public void setOverWriteExistingJobs(boolean overWriteExistingJobs) {
this.overWriteExistingJobs = overWriteExistingJobs;
}
/*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Interface.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/**
* Process the xml file in the default location (a file named
* "quartz_jobs.xml" in the current working directory).
*
*/
public void processFile() throws Exception {
processFile(QUARTZ_XML_FILE_NAME);
}
/**
* Process the xml file named <code>fileName</code>.
*
* @param fileName
* meta data file name.
*/
public void processFile(String fileName) throws Exception {
processFile(fileName, getSystemIdForFileName(fileName));
}
/**
* For the given <code>fileName</code>, attempt to expand it to its full path
* for use as a system id.
*
* @see #getURL(String)
* @see #processFile()
* @see #processFile(String)
* @see #processFileAndScheduleJobs(Scheduler, boolean)
* @see #processFileAndScheduleJobs(String, Scheduler, boolean)
*/
protected String getSystemIdForFileName(String fileName) {
InputStream fileInputStream = null;
try {
String urlPath = null;
File file = new File(fileName); // files in filesystem
if (!file.exists()) {
URL url = getURL(fileName);
if (url != null) {
// Required for jdk 1.3 compatibility
urlPath = URLDecoder.decode(url.getPath());
try {
fileInputStream = url.openStream();
} catch (IOException ignore) {
}
}
} else {
try {
fileInputStream = new FileInputStream(file);
}catch (FileNotFoundException ignore) {
}
}
if (fileInputStream == null) {
getLog().debug("Unable to resolve '" + fileName + "' to full path, so using it as is for system id.");
return fileName;
} else {
return (urlPath != null) ? urlPath : file.getAbsolutePath();
}
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException ioe) {
getLog().warn("Error closing jobs file: " + fileName, ioe);
}
}
}
/**
* Returns an <code>URL</code> from the fileName as a resource.
*
* @param fileName
* file name.
* @return an <code>URL</code> from the fileName as a resource.
*/
protected URL getURL(String fileName) {
return Thread.currentThread().getContextClassLoader().getResource(fileName);
}
/**
* Process the xmlfile named <code>fileName</code> with the given system
* ID.
*
* @param fileName
* meta data file name.
* @param systemId
* system ID.
*/
public void processFile(String fileName, String systemId)
throws ValidationException, ParserConfigurationException,
SAXException, IOException, SchedulerException,
ClassNotFoundException, ParseException {
clearValidationExceptions();
scheduledJobs.clear();
jobsToSchedule.clear();
calsToSchedule.clear();
getLog().info("Parsing XML file: " + fileName +
" with systemId: " + systemId +
" validating: " + digester.getValidating() +
" validating schema: " + digester.getSchema());
InputSource is = new InputSource(getInputStream(fileName));
is.setSystemId(systemId);
digester.push(this);
digester.parse(is);
maybeThrowValidationException();
}
/**
* Process the xmlfile named <code>fileName</code> with the given system
* ID.
*
* @param stream
* an input stream containing the xml content.
* @param systemId
* system ID.
*/
public void processStream(InputStream stream, String systemId)
throws ValidationException, ParserConfigurationException,
SAXException, IOException, SchedulerException,
ClassNotFoundException, ParseException {
clearValidationExceptions();
scheduledJobs.clear();
jobsToSchedule.clear();
calsToSchedule.clear();
getLog().info("Parsing XML from stream with systemId: " + systemId +
" validating: " + digester.getValidating() +
" validating schema: " + digester.getSchema());
InputSource is = new InputSource(stream);
is.setSystemId(systemId);
digester.push(this);
digester.parse(is);
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, getSystemIdForFileName(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 " + jobsToSchedule.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);
}
itr = listenersToSchedule.iterator();
while (itr.hasNext()) {
JobListener listener = (JobListener) itr.next();
getLog().info("adding listener "+listener.getName()+" of class "+listener.getClass().getName());
sched.addJobListener(listener);
}
getLog().info(jobBundles.size() + " scheduled jobs.");
}
/**
* 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) {
return this.classLoadHelper.getResourceAsStream(fileName);
}
/**
* 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);
}
public void addListenerToSchedule(JobListener listener) {
listenersToSchedule.add(listener);
}
/**
* 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -