|
|
@ -1,4 +1,4 @@ |
|
|
|
package com.inscloudtech.platform.jlog.zk; |
|
|
|
package com.inscloudtech.jlog.zk; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.inscloudtech.alog.common.utils.CollectionUtil; |
|
|
@ -12,8 +12,6 @@ import org.slf4j.LoggerFactory; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import static com.inscloudtech.platform.jlog.zk.ZkConfigurator.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @author didi |
|
|
@ -28,7 +26,7 @@ public class ZkListener implements ConfigChangeListener { |
|
|
|
|
|
|
|
public ZkListener(String path) { |
|
|
|
this.path = path; |
|
|
|
cache = new NodeCache(zkClient, path); |
|
|
|
cache = new NodeCache(ZkConfigurator.zkClient, path); |
|
|
|
try { |
|
|
|
cache.start(true); |
|
|
|
cache.getListenable().addListener(() -> onChangeEvent(null)); |
|
|
@ -41,23 +39,23 @@ public class ZkListener implements ConfigChangeListener { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onChangeEvent(ConfigChangeEvent event) { |
|
|
|
LOGGER.info("ZK数据变更-当前监听器关注的path:{} PROPERTIES:{}", path, JSON.toJSONString(PROPERTIES)); |
|
|
|
LOGGER.info("ZK数据变更-当前监听器关注的path:{} PROPERTIES:{}", path, JSON.toJSONString(ZkConfigurator.PROPERTIES)); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.putAll(PROPERTIES); |
|
|
|
props.putAll(ZkConfigurator.PROPERTIES); |
|
|
|
try { |
|
|
|
LOGGER.debug("ZK数据变更,旧Properties:{}", JSON.toJSONString(props)); |
|
|
|
loadZkData(); |
|
|
|
LOGGER.debug("ZK数据变更,新Properties:{}", JSON.toJSONString(PROPERTIES)); |
|
|
|
ZkConfigurator.loadZkData(); |
|
|
|
LOGGER.debug("ZK数据变更,新Properties:{}", JSON.toJSONString(ZkConfigurator.PROPERTIES)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
Set<String> diffKeys = CollectionUtil.diffKeys(props, PROPERTIES); |
|
|
|
Set<String> diffKeys = CollectionUtil.diffKeys(props, ZkConfigurator.PROPERTIES); |
|
|
|
if(!diffKeys.isEmpty()){ |
|
|
|
for (String diffKey : diffKeys) { |
|
|
|
LOGGER.warn("ZK {} 配置变更 key={} 变更事件:{}", path, diffKey, |
|
|
|
new ConfigChangeEvent(diffKey, |
|
|
|
String.valueOf(props.get(diffKey)), |
|
|
|
String.valueOf(PROPERTIES.get(diffKey)))); |
|
|
|
String.valueOf(ZkConfigurator.PROPERTIES.get(diffKey)))); |
|
|
|
} |
|
|
|
ClientHandlerBuilder.refresh(); |
|
|
|
} |