- 浏览: 184537 次
-
最新评论
-
adamed:
zhangwenzhuo 写道为什么this.get()会返回 ...
jQuery源码历代记5 -
zhangwenzhuo:
为什么this.get()会返回本身的呢?
jQuery源码历代记5 -
narutolby:
支持下~,哈哈~
jQuery历代记1 -
cpszy:
mark下
jQuery历代记1 -
gleams:
支持你
jQuery历代记1
Chapter 8. Using Quartz Plug-Ins
第8章 使用Quartz插件
The Quartz framework offers several ways to extend the capabilities of the platform. By using various "hooks" (commonly referred to as extension points), Quartz becomes very easy to extend and customize to suit your needs. One of the easiest methods for extending the framework is to use Quartz plug-ins. This chapter looks at how to use the plug-in mechanism to make Quartz go where no Quartz user has gone before.
<o:p> </o:p>
Quartz框架提供多种方法拓展平台能力。通过使用不同的钩子(hooks)-俗称拓展点,Quartz可以非常简单的拓展定制以满足你的需求。拓展框架最简单的方法就是使用Quartz插件。这一章看一下如何使用插件机制使Quartz达到以前Quartz用户达不到的地方(原文:make Quartz go where no Quartz user has gone before.)。(译者注:此处的意思是使Quartz整合到其他框架中)
<o:p> </o:p>
What Is a Plug-In?<o:p></o:p>
什么是插件<o:p></o:p>
If you have used other open source frameworks such as Apache Struts, you're already familiar with concept of plug-ins and their use. Quite simply, a Quartz plug-in is a Java class that implements the org.quartz.spi.SchedulerPlugin interface and is registered as a plug-in with the Scheduler. The plug-in interface contains three methods and is shown in Listing 8.1.
如果你曾经使用其他开源框架如Apache的Struts,你应该已经熟悉插件这个概念并使用过它了。非常简单的,一个Quartz插件就是一个实现了org.quartz.spi.SchedulerPlugin接口的JAVA类,它在Scheduler中注册为插件。插件的接口包含列表8.1显示的3个方法。
Listing 8.1. A Quartz Plug-In Must Implement the SchedulerPlugin Interface<o:p></o:p>
列表8.1 一个Quartz插件必须实现SchedulerPlugin接口
- public interface SchedulerPlugin {
- public void initialize(String name, Scheduler scheduler)
- throws SchedulerException;
- public void start();
- public void shutdown();
- }
The methods of the SchedulerPlugin are called during the initialization and startup of a Scheduler. The Scheduler calls these methods on every plug-in that is registered. The following sections describe when each method of the plug-in is called.
<o:p> </o:p>
SchedulerPlugin的方法在Scheduler被初始化和启动时被调用。Scheduler依次调用每个注册插件的这些方法。下一段描述了插件中的每个方法在什么时间被调用。
<o:p> </o:p>
The initialize() Method<o:p></o:p>
initialize()方法<o:p></o:p>
The initialize() method is called during the creation of the Scheduler. When the getScheduler() method is called on the StdSchedulerFactory, the factory calls the initialize() method on all the registered plug-ins.
<o:p> </o:p>
initialize()在创建Scheduler时被调用。在StdSchedulerFactory的getScheduler()方法被调用的时候,工厂调用所有注册插件的initialize()方法。
<o:p> </o:p>
Plug-Ins Don't Work with the DirectSchedulerFactory<o:p></o:p> 插件不工作在DirectSchedulerFactory模式下<o:p></o:p> Plug-ins are designed to be used only with the StdSchedulerFactory. It's a limitation within the framework. If you want to use plug-ins, then you'll need to use the StdSchedulerFactory to retrieve your Scheduler instance. <o:p> </o:p> 插件被设计为只在StdSchedulerFactory下使用。这是框架的限制。如果你使用插件那么你必须使用StdSchedulerFactory获取Scheduler的实例。 <o:p> </o:p> |
<o:p> </o:p>
Each plug-in is registered with a unique name. This given name and Scheduler instance is included in the call to the initialize() method. You should take whatever action is necessary to initialize your plug-in. For example, your plug-in might need to read and parse data from a file or database.
<o:p> </o:p>
每个注册的插件都有一个唯一的名字。这个名字与Scheduler实例会包含在调用的initialize()方法中。你应该采取任何必要的操作初始化插件。例如你的插件需要读取并解析文件或数据库中的数据。
<o:p> </o:p>
Scheduler Is Not Fully Set Up at initialize() Time<o:p></o:p> 在initialize()中Scheduler并没有全部设置<o:p></o:p> The Scheduler has not been fully initialized when this method is called, so interaction with the Scheduler should be kept to a minimum. For example, you should not attempt to schedule any jobs during the initialize() method. 当这个方法被调用的时候Scheduler并没有完全被初始化,所以与Scheduler的交互应该保持在最小。例如你不应该在initialize()方法中调度任何Job。 |
<o:p> </o:p>
If there is a problem initializing your plug-in, you should throw an org.quartz.SchedulerConfigException, which is a subclass of SchedulerException. This prevents the plug-in from being loaded and stops any further interaction with the Scheduler.
<o:p> </o:p>
如果在初始化的过程中发生了问题,程序会抛出org.quartz.SchedulerConfigException异常,他是SchedulerException的子类。它防止插件被加载并停止与Scheduler的进一步交互。
<o:p> </o:p>
The start() Method<o:p></o:p>
Start()方法<o:p></o:p>
The Scheduler instance calls the start() method to let the plug-in know that it can perform any startup actions it needs. For example, if you have jobs to schedule, this is the time to schedule them.
<o:p> </o:p>
Scheduler的实例调用start()方法让插件知道它可以完成任何它需要的启动操作。例如如果你有Job需要调度,那么就在这个时候去调度它。
<o:p> </o:p>
The shutdown() Method<o:p></o:p>
<o:p> </o:p>
Shutdown()方法<o:p></o:p>
<o:p> </o:p>
The shutdown() method is called to inform the plug-in that the Scheduler is shutting down. This is an opportunity for the plug-in to clean up any open resources that are open. For example, database connections or open files should be closed.
<o:p> </o:p>
Shutdown()方法通知插件Scheduler已经停止了。这个时候插件可以清理任何开放的资源。例如,数据库连接或关闭打开的文件。
<o:p> </o:p>
Scheduler Instance Not Passed in start() or shutdown()<o:p></o:p> 不要将Scheduler实例传递给start()或shutdown()方法<o:p></o:p> <o:p> </o:p> Notice that the Scheduler instance is not passed as an argument to the start() or shutdown() methods. If your plug-in needs access to the Scheduler during start() or shutdown(), you need to store the Scheduler in an instance variable in the plug-in. 注意,Scheduler实例不能作为参数传递给start()或shutdown()方法。如果你的插件需要在start()或shutdown()方法中访问Scheduler,你需要将Scheduler存储到插件中的实例变量中。 |
<o:p> </o:p>
Creating a Quartz Plug-In<o:p></o:p>
创建一个Quartz插件<o:p></o:p>
Creating a new plug-in is very simple. All you have to do is create a Java class (or reuse an existing one) that implements the org.quartz.spi.SchedulerPlugin interface. The Scheduler will create an instance of the plug-in during startup. The plug-in must have a no-argument constructor and obviously not be abstract.
<o:p> </o:p>
创建一个插件非常简单。你仅仅需要创建一个JAVA类(或重用已经存在的类),该类需要实现org.quartz.spi.SchedulerPlugin接口。Scheduler将会在启动时创建一个插件的实例。插件必须含有一个无参数的构造函数并且不能是虚函数。
<o:p> </o:p>
The JobInitializationPlugin<o:p></o:p>
JobInitializationPlugin插件<o:p></o:p>
The Quartz framework includes a plug-in for loading job and trigger information from an XML file. The plug-in is org.quartz.plugins.xml.JobInitializationPlugin and was discussed briefly back in Chapter 3, "Hello, Quartz." When you use this plug-in, the Quartz framework searches for a file called quartz_jobs.xml and attempts to load job and trigger information from this file.
<o:p> </o:p>
Quartz包含一个从XML文件读取Job和触发器信息的插件。这个插件就是org.quartz.plugins.xml.JobInitializationPlugin并且在第3章 Hello,Quartz中临时讨论了一下。当你使用这个插件的时候,Quartz将查找quartz_jobs.xml文件并且尝试从该文件中读取job和触发器信息。
<o:p> </o:p>
Changing the XML File That the JobInitializationPlugin Loads From<o:p></o:p> 改变JobInitializationPlugin读取的XML文件<o:p></o:p> The plug-in enables you to change the name of the jobs file that it looks for to load job and trigger information. You change it by setting a different filename in the quartz.properties file. We talk more about setting parameters for plug-ins later in this chapter. 插件允许你改变寻找job和触发器信息的文件名。你可以在quartz.properties文件中设置其他的名字。在这章中我们更多的讨论在插件中设置参数。 |
<o:p> </o:p>
As Chapter 3 explained, this plug-in is very convenient when your application requirements don't involve loading job information from a database. It's also very useful during development and testing because you can quickly configure which jobs and triggers are to be fired. That is, arguably, it's easier to modify an XML file than a set of database tables.
<o:p> </o:p>
正如第3章阐述的那样,如果你的应用程序不想从数据库读取job信息时,使用该插件就非常方便。当然,在开发和测试时候也是非常有用的,因为你可能想快速的配置那些job和触发器被执行。综上可知修改XML文件比设置数据库表要简单的多。
<o:p> </o:p>
A nice extension to this idea of loading job and trigger information from an XML file would be to have a directory where you can store job XML files, and, by using a plug-in, the Scheduler would load whatever job files were present. This would enable you to conveniently add or remove jobs at Scheduler startup by simply adding or removing them from the specified directory. In the rest of this chapter, we show you how to build this plug-in.
<o:p> </o:p>
从XML文件加载Job和触发器信息的一个比较好的拓展思想时,你可以建立一个目录存储job的XML文件。通过使用一个插件Scheduler不管job文件是否存在都可以进行加载。这种方式使你方便地通过简单地从目录中添加移除Scheduler启动时加载的Job信息。本章剩下的部分将讲解如何建立这个插件。
<o:p> </o:p>
Creating the JobLoaderPlugin<o:p></o:p>
创建JobLoaderPlugin<o:p></o:p>
<o:p> </o:p>
We call this new plug-in the JobLoaderPlugin. Listing 8.2 shows the JobLoaderPlugin class.
<o:p> </o:p>
我们调用这个新插件(JobLoaderPlugin)列表8.2显示了这个类。
<o:p> </o:p>
Listing 8.2. A Quartz SchedulerPlugin that Loads Multiple Job Files from a Directory<o:p></o:p>
列表8.2一个Quartz 的SchedulerPlugin插件从一个目录中加载多任务文件<o:p></o:p>
- package org.cavaness.quartzbook.chapter8;
- import java.io.File;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.quartz.Scheduler;
- import org.quartz.SchedulerConfigException;
- import org.quartz.SchedulerException;
- import org.quartz.spi.SchedulerPlugin;
- import org.quartz.xml.JobSchedulingDataProcessor;
- public class JobLoaderPlugin implements SchedulerPlugin {
- private static Log logger =
- LogFactory.getLog(JobLoaderPlugin.class);
- // The directory to load jobs from
- private String jobsDirectory;
- // An array of File objects
- private File[] jobFiles = null;
- private String pluginName;
- private Scheduler scheduler;
- private boolean validateXML = true;
- private boolean validateSchema = true;
- public JobLoaderPlugin() {
- }
- public File[] getJobFiles() {
- return jobFiles;
- }
- public void setJobFiles(File[] jobFiles) {
- this.jobFiles = jobFiles;
- }
- public boolean isValidateSchema() {
- return validateSchema;
- }
- public void setValidateSchema(boolean validatingSchema) {
- this.validateSchema = validatingSchema;
- }
- public void initialize(String name, final Scheduler scheduler)
- throws SchedulerException {
- this.pluginName = name;
- this.scheduler = scheduler;
- logger.debug("Registering Plugin " + pluginName);
- // Load the job definitions from the specified directory
- loadJobs();
- }
- private void loadJobs() throws SchedulerException {
- File dir = null;
- // Check directory
- if (getJobsDirectory() == null
- || !(dir =
- new File(getJobsDirectory())).exists()) {
- throw new SchedulerConfigException(
- "The jobs directory was missing "
- + jobsDirectory);
- }
- logger.info("Loading jobs from " + dir.getName());
- // Only XML files, filtering out any directories
- this.jobFiles = dir.listFiles(new XMLFileOnlyFilter());
- }
- public void start() {
- processJobs();
- }
- public void shutdown() {
- // nothing to clean up
- }
- public void processJobs() {
- // There should be at least one job
- if (getJobFiles() == null || getJobFiles().length == 0) {
- return;
- }
- JobSchedulingDataProcessor processor =
- new JobSchedulingDataProcessor(
- true, isValidateXML(), isValidateSchema());
- int size = getJobFiles().length;
- for (int i = 0; i < size; i++) {
- File jobFile = getJobFiles()[i];
- String fileName = jobFile.getAbsolutePath();
- logger.debug("Loading job file: " + fileName);
- try {
- processor.processFileAndScheduleJobs(
- fileName, scheduler, true);
- } catch (Exception ex) {
- logger.error("Error loading jobs: " + fileName);
- logger.error(ex);
- }
- }
- }
- public String getJobsDirectory() {
- return jobsDirectory;
- }
- public void setJobsDirectory(String jobsDirectory) {
- this.jobsDirectory = jobsDirectory;
- }
- public String getPluginName() {
- return pluginName;
- }
- public void setPluginName(String pluginName) {
- this.pluginName = pluginName;
- }
- public boolean isValidateXML() {
- return validateXML;
- }
- public void setValidateXML(boolean validateXML) {
- this.validateXML = validateXML;
- }
- }
The real work of the JobLoaderPlugin in Listing 8.2 is done in just two methods: initialize() and start(). Both are required by the SchedulerPlugin interface. The rest of the methods are just setXXX and getXXX methods to fulfill the JavaBean contract because private properties have been declared.
列表8.2中JobLoaderPlugin插件真正工作的只有2个方法:initialize() 和 start()。2个方法都是SchedulerPlugin接口中定义的。剩下的方法都是JavaBean的get和set方法操作私有属性。
<o:p> </o:p>
The JobLoaderPlugin initialize() Method<o:p></o:p>
JobLoaderPlugin的initialize()方法<o:p></o:p>
<o:p> </o:p>
As you can see, the initialize() method, which is called by the Scheduler, calls the private loadJobs() method. The loadJobs() method uses the jobsDirectory that was passed in from the quartz.properties file to retrieve all XML files stored in that directory. The plug-in doesn't try to schedule the jobs yet because the Scheduler isn't fully instantiated when the plug-in's initialize() method is called. The JobLoaderPlugin simply holds on to an array of File objects, waiting for the start() method to be called. We also hold on to the instance of the Scheduler so that we have access to it when the start() method is called.
<o:p> </o:p>
正如你所见Scheduler调用的initialize()方法调用了私有方法loadJobs()。loadJobs()方法使用从quartz.properties中所有来的储存在Job文件夹中的所有XML文件。暂时插件并不会试图调度job因为在插件的initialize()方法被调用的时候Scheduler还没有完全被初始化。JobLoaderPlugin简单的保存文件对象的数组,等待start()方法被调用。我们也保存了Scheduler的实例这样当start()方法被调用的时候可以访问它。
<o:p> </o:p>
The JobLoaderPlugin start() Method<o:p></o:p>
JobLoaderPlugin的start()方法<o:p></o:p>
When the Scheduler calls the start() method in the JobLoaderPlugin, the start() method calls processJobs(). The processJobs() method loops through the array of job files and loads each one into the Scheduler instance.
<o:p> </o:p>
当Sheduler在JobLoaderPlugin插件中调用start()<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-
发表评论
-
JQuery CookBook翻译连载7(第四章)
2010-06-29 18:45 1032今天超级爆发,整理出来第四章中文版翻译。 -
JQuery CookBook翻译连载6(第三章)
2010-06-29 11:31 1017放出jQuery CookBook翻译的第三章。 最近找工作 ... -
JQuery CookBook 翻译连载6(第2章发布)
2010-06-01 14:15 955jQuery Cookbook第1、2章合订版。 不知 ... -
JQuery CookBook 翻译连载5(第1章发布)
2010-05-16 16:55 934jQuery cookBook 第一章翻译打包发布。 ... -
JQuery CookBook翻译连载1
2010-05-14 11:46 8231.1 在HTML页面中添加j ... -
JQuery CookBook翻译连载2
2010-05-14 11:45 8111.2 在页面DOM加载结束后、整个页面加载结束前执行jQue ... -
JQuery CookBook翻译连载3
2010-05-14 11:34 7091.3 使用选择器及jQuery函 ... -
JQuery CookBook翻译连载4
2010-05-14 11:09 6891.4 在特定的上下文 中查找元素 问 ... -
Quartz Job Scheduling Framework第11章翻译初稿
2007-10-27 15:21 1070内容在附件中 -
Quartz Job Scheduling Framework第7章翻译初稿
2007-10-27 15:18 1146内容在附件中 -
Quartz Job Scheduling Framework第5章翻译初稿
2007-10-27 15:18 976在附件中 -
Quartz Job Scheduling Framework第2章翻译初稿
2007-10-27 15:17 1155在附件中 -
Quartz Job Scheduling Framework第8章翻译初稿 续
2007-09-27 19:46 2188You can have as many properti ... -
Quartz Job Scheduling Framework翻译初稿奉上
2007-09-26 21:55 1609由于时间与水平限制。这本经典书籍翻译的可能并不尽如人意,在此先 ... -
Quartz Job Scheduling Framework第10章翻译初稿 续
2007-09-26 21:53 2025In the example in Listing 10. ... -
Quartz Job Scheduling Framework第10章翻译初稿
2007-09-26 21:40 2625Chapter 10. Using Quartz with J ...
相关推荐
Quartz Job Scheduling Framework是一个强大的、开放源代码的作业调度框架,它使应用程序能够在指定的时间执行任务,无需人工干预。这个框架广泛应用于Java应用程序中,用于实现定时任务和工作流管理。在第11章中,...
在阅读《Quartz Job Scheduling Framework》第5章时,你会了解到如何创建和配置Cron Triggers,如何结合SimpleTrigger和CalendarIntervalTrigger实现不同类型的定时任务,以及如何优化Quartz的配置以适应大规模的...
Quartz Job Scheduling Framework第2章翻译初稿 博文链接:https://adamed.iteye.com/blog/135880
Quartz Job Scheduling Framework是一个强大的、开源的作业调度框架,用于在Java应用程序中安排任务执行。这个框架允许开发者创建和管理作业,以及定义作业的触发时间。第7章的主题聚焦于实现Quartz监听器,这是一个...
qtz40塔式起重机总体及塔身有限元分析法设计().zip
Elasticsearch是一个基于Lucene的搜索服务器
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
美国纽约HVAC(暖通空调)数据示例,谷歌地图数据包括:时间戳、名称、类别、地址、描述、开放网站、电话号码、开放时间、更新开放时间、评论计数、评级、主图像、评论、url、纬度、经度、地点id、国家等。 在地理位置服务(LBS)中,谷歌地图数据采集尤其受到关注,因为它提供了关于各种商业实体的详尽信息,这对于消费者和企业都有极大的价值。本篇文章将详细介绍美国纽约地区的HVAC(暖通空调)系统相关数据示例,此示例数据是通过谷歌地图抓取得到的,展示了此技术在商业和消费者领域的应用潜力。 无需外网,无需任何软件抓取谷歌地图数据:wmhuoke.com
2023-04-06-项目笔记-第四百五十五阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.453局变量的作用域_453- 2025-04-01
1_实验三 扰码、卷积编码及交织.ppt
北京交通大学901软件工程导论必备知识点.pdf
内容概要:本文档总结了 MyBatis 的常见面试题,涵盖了 MyBatis 的基本概念、优缺点、适用场合、SQL 语句编写技巧、分页机制、主键生成、参数传递方式、动态 SQL、缓存机制、关联查询及接口绑定等内容。通过对这些问题的解答,帮助开发者深入理解 MyBatis 的工作原理及其在实际项目中的应用。文档不仅介绍了 MyBatis 的核心功能,还详细解释了其在不同场景下的具体实现方法,如通过 XML 或注解配置 SQL 语句、处理复杂查询、优化性能等。 适合人群:具备一定 Java 开发经验,尤其是对 MyBatis 有初步了解的研发人员,以及希望深入了解 MyBatis 框架原理和最佳实践的开发人员。 使用场景及目标:①理解 MyBatis 的核心概念和工作原理,如 SQL 映射、参数传递、结果映射等;②掌握 MyBatis 在实际项目中的应用技巧,包括 SQL 编写、分页、主键生成、关联查询等;③学习如何通过 XML 和注解配置 SQL 语句,优化 MyBatis 性能,解决实际开发中的问题。 其他说明:文档内容详尽,涵盖面广,适合用于面试准备和技术学习。建议读者在学习过程中结合实际项目进行练习,以更好地掌握 MyBatis 的使用方法和技巧。此外,文档还提供了丰富的示例代码和配置细节,帮助读者加深理解和应用。
《基于YOLOv8的智能电网设备锈蚀评估系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计
插头模具 CAD图纸.zip
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
《基于YOLOv8的智慧农业水肥一体化控制系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计
python爬虫;智能切换策略,反爬检测机制
台区终端电科院送检文档
e235d-main.zip
丁祖昱:疫情对中国房地产市场影响分析及未来展望