调度中心,自动注册

This commit is contained in:
xueli.xue 2016-10-02 20:18:07 +08:00
parent 295200dbfc
commit 50cfecfc56
4 changed files with 48 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.xxl.job.admin.core.thread;
import com.xxl.job.admin.core.callback.XxlJobLogCallbackServer;
import com.xxl.job.admin.core.model.XxlJobRegistry;
import com.xxl.job.admin.core.util.DynamicSchedulerUtil;
import com.xxl.job.core.registry.RegistHelper;
@ -28,8 +29,14 @@ public class JobRegistryHelper {
int timeout = 15;
while (true) {
try {
// registry admin
int ret = DynamicSchedulerUtil.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobLogCallbackServer.getTrigger_log_address());
if (ret < 1) {
DynamicSchedulerUtil.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobLogCallbackServer.getTrigger_log_address());
}
// fresh registry map
ConcurrentHashMap<String, List<String>> temp = new ConcurrentHashMap<String, List<String>>();
// do biz
DynamicSchedulerUtil.xxlJobRegistryDao.removeDead(RegistHelper.TIMEOUT*2);
List<XxlJobRegistry> list = DynamicSchedulerUtil.xxlJobRegistryDao.findAll(RegistHelper.TIMEOUT*2);
if (list != null) {
@ -43,9 +50,7 @@ public class JobRegistryHelper {
temp.put(groupKey, dataSet);
}
}
// gresh registry
registMap = temp;
logger.error("job registry :{}", list);
} catch (Exception e) {
logger.error("job registry helper error:{}", e);
}

View File

@ -11,4 +11,9 @@ public interface IXxlJobRegistryDao {
public int removeDead(int timeout);
public List<XxlJobRegistry> findAll(int timeout);
public int registryUpdate(String registryGroup, String registryKey, String registryValue);
public int registrySave(String registryGroup, String registryKey, String registryValue);
}

View File

@ -6,7 +6,9 @@ import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by xuxueli on 16/9/30.
@ -27,4 +29,24 @@ public class XxlJobRegistryDaoImpl implements IXxlJobRegistryDao {
return sqlSessionTemplate.selectList("XxlJobRegistryMapper.findAll", timeout);
}
@Override
public int registryUpdate(String registryGroup, String registryKey, String registryValue) {
Map<String, Object> params = new HashMap();
params.put("registryGroup", registryGroup);
params.put("registryKey", registryKey);
params.put("registryValue", registryValue);
return sqlSessionTemplate.update("XxlJobRegistryMapper.registryUpdate", params);
}
@Override
public int registrySave(String registryGroup, String registryKey, String registryValue) {
Map<String, Object> params = new HashMap();
params.put("registryGroup", registryGroup);
params.put("registryKey", registryKey);
params.put("registryValue", registryValue);
return sqlSessionTemplate.update("XxlJobRegistryMapper.registrySave", params);
}
}

View File

@ -30,4 +30,17 @@
WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(NOW(),INTERVAL -#{timeout} SECOND)
</select>
<update id="registryUpdate" parameterType="java.util.Map" >
UPDATE XXL_JOB_QRTZ_TRIGGER_REGISTRY
SET `update_time` = NOW()
WHERE `registry_group` = #{registryGroup}
AND `registry_key` = #{registryKey}
AND `registry_value` = #{registryValue}
</update>
<insert id="registrySave" parameterType="java.util.Map" >
INSERT INTO XXL_JOB_QRTZ_TRIGGER_REGISTRY( `registry_group` , `registry_key` , `registry_value`, `update_time`)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW())
</insert>
</mapper>