From 664f07eaac79143382398544da6c95a20da960ee Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Thu, 23 Nov 2017 23:28:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=B3=A8=E8=A7=A3=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=BA=20=E2=80=9C@JobHandler=E2=80=9D=EF=BC=8C?= =?UTF-8?q?=E4=B8=8E=E4=BB=BB=E5=8A=A1=E6=B3=A8=E8=A7=A3=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB-English-Documentation.md | 12 ++++++------ doc/XXL-JOB官方文档.md | 15 ++++++++------- .../com/xxl/job/core/executor/XxlJobExecutor.java | 6 +++--- .../{JobHander.java => JobHandler.java} | 2 +- .../service/jobhandler/DemoJobHandler.java | 6 +++--- .../service/jobhandler/ShardingJobHandler.java | 4 ++-- .../service/jobhandler/DemoJobHandler.java | 6 +++--- .../service/jobhandler/ShardingJobHandler.java | 4 ++-- 8 files changed, 28 insertions(+), 27 deletions(-) rename xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/{JobHander.java => JobHandler.java} (93%) diff --git a/doc/XXL-JOB-English-Documentation.md b/doc/XXL-JOB-English-Documentation.md index cee39f8a..b03b1b29 100644 --- a/doc/XXL-JOB-English-Documentation.md +++ b/doc/XXL-JOB-English-Documentation.md @@ -347,7 +347,7 @@ On the log console,you can view task execution log on the executor immediately a GLUE模式(Java):task source code is maintened in the schedule center,it must implement IJobHandler and explain by "groovy" in the executor instance,inject other bean instace by annotation @Resource/@Autowire. GLUE模式(Shell):it’s source code is a shell script and maintained in the schedule center. GLUE模式(Python):it’s source code is a python script and maintained in the schedule center. - - JobHandler:it’s used in "BEAN模式",it’s instance is defined by annotation @JobHander on the JobHandler class name. + - JobHandler:it’s used in "BEAN模式",it’s instance is defined by annotation @JobHandler on the JobHandler class name. - 子任务Key:every task has a unique key (task Key can acquire from task list),when main task is done successfully it’s child task stand for by this key will be scheduled. - 阻塞处理策略:the stategy handle the task when this task is scheduled too frequently and the task is block to wait for cpu time. 单机串行(默认):task schedule request go into the FIFO queue and execute serially. @@ -366,7 +366,7 @@ The task logic exist in the executor project as JobHandler,the develop steps as #### Step 1:develp obHandler in the executor project - 1, create new java class implent com.xxl.job.core.handler.IJobHandler; - 2, if you add @Component annotation on the top of the class name it’s will be managed as a bean instance by spring container; - - 3, add “@JobHander(value=" customize jobhandler name")” annotation,the value stand for JobHandler name,it will be used as JobHandler property when create a new task in the schedule center. + - 3, add “@JobHandler(value=" customize jobhandler name")” annotation,the value stand for JobHandler name,it will be used as JobHandler property when create a new task in the schedule center. (go and see DemoJobHandler in the xxl-job-executor-example project, as shown below) ![输入图片说明](https://static.oschina.net/uploads/img/201607/23232347_oLlM.png "在这里输入图片标题") @@ -682,7 +682,7 @@ On the task log page ,you can see matched child task and triggered child task’ ### 5.5 Task "run mode" analysis #### 5.5.1 "Bean模式" task Development steps:go and see "chapter 3" . -principle: every Bean mode task is a Spring Bean instance and it is maintained in executor project’s Spring container. task class nedd to add “@JobHander(value="name")” annotation, because executor identify task bean instance in spring container through annotation. Task class nedd to implements interface IJobHandler, task logic code in method execute(), the task logic in execute() method will be executed when executor received a schedule request from schedule center. +principle: every Bean mode task is a Spring Bean instance and it is maintained in executor project’s Spring container. task class nedd to add “@JobHandler(value="name")” annotation, because executor identify task bean instance in spring container through annotation. Task class nedd to implements interface IJobHandler, task logic code in method execute(), the task logic in execute() method will be executed when executor received a schedule request from schedule center. #### 5.5.2 "GLUE模式(Java)" task Development steps:go and see "chapter 3" . @@ -703,7 +703,7 @@ Executor is actually an embedded Jetty server with default port 9999, as shown b ![输入图片说明](https://static.oschina.net/uploads/img/201703/10174923_TgNO.png "在这里输入图片标题") -Executor will identify Bean mode task in spring container through @JobHander When project start, it will be managed use the value of annotation as key. +Executor will identify Bean mode task in spring container through @JobHandler When project start, it will be managed use the value of annotation as key. When executor received schedule request from schedule center, if task type is “Bean模式” it will match bean mode task in Spring container and call it’s execute() method and execute task logic. if task type is “GLUE模式”, it will load Glue code, instantiate a Java object and inject other spring service(notice: the spring service injected in Glue code must exist in the same executor project), then call execute() method and execute task logic. @@ -810,13 +810,13 @@ The scheduling center API service requests reference code:com.xxl.job.dao.impl - stability; ### 6.3 version V1.3.0,New features [2016-05-19] -- 1、discard local task module, remote task was recommended, easy to decouple system, the JobHander of task was called executor. +- 1、discard local task module, remote task was recommended, easy to decouple system, the JobHandler of task was called executor. - 2、dicard underlying communication type servlet, JETTY was recommended, schedule and callback bidirectional communication, rebuild the communication logic; - 3、UI interactive optimization:optimize left menu expansion and menu item selected status , task list opens the table with compression optimization; - 4、【important】executor is subdivided into two develop mode:BEAN、GLUE: Introduction to the executor mode: - - BEAN mode executor:every executor is a Spring Bean instance,it was recognized and scheduled by XXL-JOB through @JobHander annotation; + - BEAN mode executor:every executor is a Spring Bean instance,it was recognized and scheduled by XXL-JOB through @JobHandler annotation; -GLUE mode executor:every executor corresponds to a piece of code,edited and maintained online by Web, Dynamic compile and takes effect in real time, executor is responsible for loading GLUE code and executing; ### 6.4 version V1.3.1,New features [2016-05-23] diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 8ee9f0ae..4b9ccd82 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -359,7 +359,7 @@ XXL-JOB是一个轻量级分布式任务调度框架,其核心设计目标是 GLUE模式(Shell):任务以源码方式维护在调度中心;该模式的任务实际上是一段 "shell" 脚本; GLUE模式(Python):任务以源码方式维护在调度中心;该模式的任务实际上是一段 "python" 脚本; GLUE模式(NodeJS):任务以源码方式维护在调度中心;该模式的任务实际上是一段 "nodejs" 脚本; - - JobHandler:运行模式为 "BEAN模式" 时生效,对应执行器中新开发的JobHandler类“@JobHander”注解自定义的value值; + - JobHandler:运行模式为 "BEAN模式" 时生效,对应执行器中新开发的JobHandler类“@JobHandler”注解自定义的value值; - 子任务Key:每个任务都拥有一个唯一的任务Key(任务Key可以从任务列表获取),当本任务执行结束并且执行成功时,将会触发子任务Key所对应的任务的一次主动调度。 - 阻塞处理策略:调度过于密集执行器来不及处理时的处理策略; 单机串行(默认):调度请求进入单机执行器后,调度请求进入FIFO队列并以串行方式运行; @@ -378,13 +378,13 @@ XXL-JOB是一个轻量级分布式任务调度框架,其核心设计目标是 #### 步骤一:执行器项目中,开发JobHandler: - 1、 新建一个继承com.xxl.job.core.handler.IJobHandler的Java类; - 2、 该类被Spring容器扫描为Bean实例,如加“@Component”注解; - - 3、 添加 “@JobHander(value="自定义jobhandler名称")”注解,注解的value值为自定义的JobHandler名称,该名称对应的是调度中心新建任务的JobHandler属性的值。 + - 3、 添加 “@JobHandler(value="自定义jobhandler名称")”注解,注解的value值为自定义的JobHandler名称,该名称对应的是调度中心新建任务的JobHandler属性的值。 (可参考Sample示例执行器中的DemoJobHandler,见下图) ![输入图片说明](https://static.oschina.net/uploads/img/201607/23232347_oLlM.png "在这里输入图片标题") #### 步骤二:调度中心,新建调度任务 -参考上文“配置属性详细说明”对新建的任务进行参数配置,运行模式选中 "BEAN模式",JobHandler属性填写任务注解@JobHander中定义的值; +参考上文“配置属性详细说明”对新建的任务进行参数配置,运行模式选中 "BEAN模式",JobHandler属性填写任务注解“@JobHandler”中定义的值; ![输入图片说明](https://static.oschina.net/uploads/img/201704/27225124_yrcO.png "在这里输入图片标题") @@ -715,7 +715,7 @@ xxl-job-admin#com.xxl.job.admin.controller.JobApiController.callback ### 5.5 任务 "运行模式" 剖析 #### 5.5.1 "Bean模式" 任务 开发步骤:可参考 "章节三" ; -原理:每个Bean模式任务都是一个Spring的Bean类实例,它被维护在“执行器”项目的Spring容器中。任务类需要加“@JobHander(value="名称")”注解,因为“执行器”会根据该注解识别Spring容器中的任务。任务类需要继承统一接口“IJobHandler”,任务逻辑在execute方法中开发,因为“执行器”在接收到调度中心的调度请求时,将会调用“IJobHandler”的execute方法,执行任务逻辑。 +原理:每个Bean模式任务都是一个Spring的Bean类实例,它被维护在“执行器”项目的Spring容器中。任务类需要加“@JobHandler(value="名称")”注解,因为“执行器”会根据该注解识别Spring容器中的任务。任务类需要继承统一接口“IJobHandler”,任务逻辑在execute方法中开发,因为“执行器”在接收到调度中心的调度请求时,将会调用“IJobHandler”的execute方法,执行任务逻辑。 #### 5.5.2 "GLUE模式(Java)" 任务 开发步骤:可参考 "章节三" ; @@ -737,7 +737,7 @@ xxl-job-admin#com.xxl.job.admin.controller.JobApiController.callback ![输入图片说明](https://static.oschina.net/uploads/img/201703/10174923_TgNO.png "在这里输入图片标题") -在项目启动时,执行器会通过“@JobHander”识别Spring容器中“Bean模式任务”,以注解的value属性为key管理起来。 +在项目启动时,执行器会通过“@JobHandler”识别Spring容器中“Bean模式任务”,以注解的value属性为key管理起来。 “执行器”接收到“调度中心”的调度请求时,如果任务类型为“Bean模式”,将会匹配Spring容器中的“Bean模式任务”,然后调用其execute方法,执行任务逻辑。如果任务类型为“GLUE模式”,将会加载GLue代码,实例化Java对象,注入依赖的Spring服务(注意:Glue代码中注入的Spring服务,必须存在与该“执行器”项目的Spring容器中),然后调用execute方法,执行任务逻辑。 @@ -860,13 +860,13 @@ XXL-JOB会为每次调度请求生成一个单独的日志文件,需要通过 - 稳定性; ### 6.3 版本 V1.3.0,新特性[2016-05-19] -- 1、遗弃“本地任务”模式,推荐使用“远程任务”,易于系统解耦,任务对应的JobHander统称为“执行器”; +- 1、遗弃“本地任务”模式,推荐使用“远程任务”,易于系统解耦,任务对应的JobHandler统称为“执行器”; - 2、遗弃“servlet”方式底层系统通讯,推荐使用JETTY方式,调度+回调双向通讯,重构通讯逻辑; - 3、UI交互优化:左侧菜单展开状态优化,菜单项选中状态优化,任务列表打开表格有压缩优化; - 4、【重要】“执行器”细分为:BEAN、GLUE两种开发模式,简介见下文: “执行器” 模式简介: - - BEAN模式执行器:每个执行器都是Spring的一个Bean实例,XXL-JOB通过注解@JobHander识别和调度执行器; + - BEAN模式执行器:每个执行器都是Spring的一个Bean实例,XXL-JOB通过注解@JobHandler识别和调度执行器; -GLUE模式执行器:每个执行器对应一段代码,在线Web编辑和维护,动态编译生效,执行器负责加载GLUE代码和执行; ### 6.4 版本 V1.3.1,新特性[2016-05-23] @@ -1052,6 +1052,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 6、执行器动态代理对象,拦截非业务方法的执行; - 7、底层系统日志级别规范调整,清理遗留代码; - 8、修改JobThread捕获Error错误不更新JobLog的问题; +- 9、任务注解调整为 “@JobHandler”,与任务注解统一; ### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java index 5e17a932..d35dbe9c 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java @@ -4,7 +4,7 @@ import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.impl.ExecutorBizImpl; import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.handler.annotation.JobHander; +import com.xxl.job.core.handler.annotation.JobHandler; import com.xxl.job.core.log.XxlJobFileAppender; import com.xxl.job.core.rpc.netcom.NetComClientProxy; import com.xxl.job.core.rpc.netcom.NetComServerFactory; @@ -141,12 +141,12 @@ public class XxlJobExecutor implements ApplicationContextAware { } private static void initJobHandlerRepository(ApplicationContext applicationContext){ // init job handler action - Map serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHander.class); + Map serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class); if (serviceBeanMap!=null && serviceBeanMap.size()>0) { for (Object serviceBean : serviceBeanMap.values()) { if (serviceBean instanceof IJobHandler){ - String name = serviceBean.getClass().getAnnotation(JobHander.class).value(); + String name = serviceBean.getClass().getAnnotation(JobHandler.class).value(); IJobHandler handler = (IJobHandler) serviceBean; if (loadJobHandler(name) != null) { throw new RuntimeException("xxl-job jobhandler naming conflicts."); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java b/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHandler.java similarity index 93% rename from xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java rename to xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHandler.java index 0172f5f6..253026a4 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHander.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/handler/annotation/JobHandler.java @@ -13,7 +13,7 @@ import java.lang.annotation.Target; @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited -public @interface JobHander { +public @interface JobHandler { String value() default ""; diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java index 905a0b7b..b0fb6c01 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java @@ -2,7 +2,7 @@ package com.xxl.job.executor.service.jobhandler; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.handler.annotation.JobHander; +import com.xxl.job.core.handler.annotation.JobHandler; import com.xxl.job.core.log.XxlJobLogger; import org.springframework.stereotype.Component; @@ -15,12 +15,12 @@ import java.util.concurrent.TimeUnit; * 开发步骤: * 1、新建一个继承com.xxl.job.core.handler.IJobHandler的Java类; * 2、该类被Spring容器扫描为Bean实例,如加“@Component”注解; - * 3、添加 “@JobHander(value="自定义jobhandler名称")”注解,注解的value值为自定义的JobHandler名称,该名称对应的是调度中心新建任务的JobHandler属性的值。 + * 3、添加 “@JobHandler(value="自定义jobhandler名称")”注解,注解的value值为自定义的JobHandler名称,该名称对应的是调度中心新建任务的JobHandler属性的值。 * 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; * * @author xuxueli 2015-12-19 19:43:36 */ -@JobHander(value="demoJobHandler") +@JobHandler(value="demoJobHandler") @Component public class DemoJobHandler extends IJobHandler { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java index 66560353..4c0b5c80 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java @@ -2,7 +2,7 @@ package com.xxl.job.executor.service.jobhandler; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.handler.annotation.JobHander; +import com.xxl.job.core.handler.annotation.JobHandler; import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.util.ShardingUtil; import org.springframework.stereotype.Service; @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service; * * @author xuxueli 2017-07-25 20:56:50 */ -@JobHander(value="shardingJobHandler") +@JobHandler(value="shardingJobHandler") @Service public class ShardingJobHandler extends IJobHandler { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java index bf22239f..5a9bce0a 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java @@ -2,7 +2,7 @@ package com.xxl.job.executor.service.jobhandler; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.handler.annotation.JobHander; +import com.xxl.job.core.handler.annotation.JobHandler; import com.xxl.job.core.log.XxlJobLogger; import org.springframework.stereotype.Service; @@ -15,12 +15,12 @@ import java.util.concurrent.TimeUnit; * 开发步骤: * 1、继承 “IJobHandler” ; * 2、装配到Spring,例如加 “@Service” 注解; - * 3、加 “@JobHander” 注解,注解value值为新增任务生成的JobKey的值;多个JobKey用逗号分割; + * 3、加 “@JobHandler” 注解,注解value值为新增任务生成的JobKey的值;多个JobKey用逗号分割; * 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志; * * @author xuxueli 2015-12-19 19:43:36 */ -@JobHander(value="demoJobHandler") +@JobHandler(value="demoJobHandler") @Service public class DemoJobHandler extends IJobHandler { diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java index c8b15602..80cf1177 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/ShardingJobHandler.java @@ -2,7 +2,7 @@ package com.xxl.job.executor.service.jobhandler; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; -import com.xxl.job.core.handler.annotation.JobHander; +import com.xxl.job.core.handler.annotation.JobHandler; import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.util.ShardingUtil; import org.springframework.stereotype.Service; @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service; * * @author xuxueli 2017-07-25 20:56:50 */ -@JobHander(value="shardingJobHandler") +@JobHandler(value="shardingJobHandler") @Service public class ShardingJobHandler extends IJobHandler {