提交 7bc11fcb authored 作者: xuxueli's avatar xuxueli

执行器注册线程优化,线程销毁时主动摘除注册机器;

上级 0b4849bb
...@@ -987,6 +987,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 ...@@ -987,6 +987,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 4、执行器手动设置IP时将会绑定Host; - 4、执行器手动设置IP时将会绑定Host;
- 5、项目主页搭建,提供中英文文档; - 5、项目主页搭建,提供中英文文档;
- 6、执行器回调线程优化,线程销毁前批量回调队列中所有数据; - 6、执行器回调线程优化,线程销毁前批量回调队列中所有数据;
- 7、执行器注册线程优化,线程销毁时主动摘除注册机器;
### TODO LIST ### TODO LIST
- 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;
......
...@@ -22,4 +22,8 @@ public interface XxlJobRegistryDao { ...@@ -22,4 +22,8 @@ public interface XxlJobRegistryDao {
@Param("registryKey") String registryKey, @Param("registryKey") String registryKey,
@Param("registryValue") String registryValue); @Param("registryValue") String registryValue);
public int registryDelete(@Param("registryGroup") String registGroup,
@Param("registryKey") String registryKey,
@Param("registryValue") String registryValue);
} }
...@@ -118,4 +118,10 @@ public class AdminBizImpl implements AdminBiz { ...@@ -118,4 +118,10 @@ public class AdminBizImpl implements AdminBiz {
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
@Override
public ReturnT<String> registryRemove(RegistryParam registryParam) {
xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue());
return ReturnT.SUCCESS;
}
} }
...@@ -43,4 +43,11 @@ ...@@ -43,4 +43,11 @@
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW()) VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW())
</insert> </insert>
<delete id="registryDelete" >
DELETE FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY
WHERE registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -27,6 +27,13 @@ public class AdminBizTest { ...@@ -27,6 +27,13 @@ public class AdminBizTest {
ReturnT<String> returnT = adminBiz.registry(registryParam); ReturnT<String> returnT = adminBiz.registry(registryParam);
Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE); 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);
} }
} }
...@@ -29,4 +29,12 @@ public interface AdminBiz { ...@@ -29,4 +29,12 @@ public interface AdminBiz {
*/ */
public ReturnT<String> registry(RegistryParam registryParam); public ReturnT<String> registry(RegistryParam registryParam);
/**
* registry remove
*
* @param registryParam
* @return
*/
public ReturnT<String> registryRemove(RegistryParam registryParam);
} }
...@@ -47,6 +47,8 @@ public class ExecutorRegistryThread extends Thread { ...@@ -47,6 +47,8 @@ public class ExecutorRegistryThread extends Thread {
registryThread = new Thread(new Runnable() { registryThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
// registry
while (!toStop) { while (!toStop) {
try { try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress); RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
...@@ -77,7 +79,26 @@ public class ExecutorRegistryThread extends Thread { ...@@ -77,7 +79,26 @@ public class ExecutorRegistryThread extends Thread {
} }
// registry remove // registry remove
try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try {
ReturnT<String> 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);
}
} }
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论