From 7bc11fcbc46a6b575141750121a22c513eb2a81d Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sat, 26 Aug 2017 12:59:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BC=98=E5=8C=96=EF=BC=8C=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E9=94=80=E6=AF=81=E6=97=B6=E4=B8=BB=E5=8A=A8=E6=91=98=E9=99=A4?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=9C=BA=E5=99=A8=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 1 + .../xxl/job/admin/dao/XxlJobRegistryDao.java | 4 ++++ .../job/admin/service/impl/AdminBizImpl.java | 6 ++++++ .../mybatis-mapper/XxlJobRegistryMapper.xml | 7 +++++++ .../com/xxl/job/dao/impl/AdminBizTest.java | 7 +++++++ .../java/com/xxl/job/core/biz/AdminBiz.java | 8 +++++++ .../core/thread/ExecutorRegistryThread.java | 21 +++++++++++++++++++ 7 files changed, 54 insertions(+) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 8dd9c976..4e463b3d 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -987,6 +987,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 4、执行器手动设置IP时将会绑定Host; - 5、项目主页搭建,提供中英文文档; - 6、执行器回调线程优化,线程销毁前批量回调队列中所有数据; +- 7、执行器注册线程优化,线程销毁时主动摘除注册机器; ### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java index a963e0ff..b4ce0bc4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java @@ -22,4 +22,8 @@ public interface XxlJobRegistryDao { @Param("registryKey") String registryKey, @Param("registryValue") String registryValue); + public int registryDelete(@Param("registryGroup") String registGroup, + @Param("registryKey") String registryKey, + @Param("registryValue") String registryValue); + } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java index 4c446a31..f185264d 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java @@ -118,4 +118,10 @@ public class AdminBizImpl implements AdminBiz { return ReturnT.SUCCESS; } + @Override + public ReturnT registryRemove(RegistryParam registryParam) { + xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); + return ReturnT.SUCCESS; + } + } diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobRegistryMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobRegistryMapper.xml index 13443980..33aa3169 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobRegistryMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobRegistryMapper.xml @@ -43,4 +43,11 @@ VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW()) + + DELETE FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY + WHERE registry_group = #{registryGroup} + AND registry_key = #{registryKey} + AND registry_value = #{registryValue} + + \ No newline at end of file diff --git a/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java b/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java index 017dcdb1..dba585cf 100644 --- a/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java +++ b/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java @@ -27,6 +27,13 @@ public class AdminBizTest { ReturnT returnT = adminBiz.registry(registryParam); Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE); + + + // test executor registry remove + registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); + returnT = adminBiz.registryRemove(registryParam); + Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE); + } } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java index fcb4f101..8c403519 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java @@ -29,4 +29,12 @@ public interface AdminBiz { */ public ReturnT registry(RegistryParam registryParam); + /** + * registry remove + * + * @param registryParam + * @return + */ + public ReturnT registryRemove(RegistryParam registryParam); + } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java index 52c070d3..1a5adc65 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java @@ -47,6 +47,8 @@ public class ExecutorRegistryThread extends Thread { registryThread = new Thread(new Runnable() { @Override public void run() { + + // registry while (!toStop) { try { RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress); @@ -77,7 +79,26 @@ public class ExecutorRegistryThread extends Thread { } // registry remove + try { + RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress); + for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) { + try { + ReturnT registryResult = adminBiz.registryRemove(registryParam); + if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) { + registryResult = ReturnT.SUCCESS; + logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult}); + break; + } else { + logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult}); + } + } catch (Exception e) { + logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e); + } + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } } });