Skip to content

Commit

Permalink
Merge pull request ltsopensource#353 from zhaoyuguang/bugfix_redis_re…
Browse files Browse the repository at this point in the history
…gistry-re-subscribe

bugfix:redis作为注册中心,强制刷新后,lts_node表无数据.
  • Loading branch information
qq254963746 authored May 22, 2017
2 parents 2b18df0 + affec40 commit ed4b4b4
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected void doSubscribe(Node node, NotifyListener listener) {
try {
Jedis jedis = jedisPool.getResource();
try {
doNotify(jedis, Collections.singletonList(listenNodePath), Collections.singletonList(listener));
doNotify(jedis, Collections.singletonList(listenNodePath), Collections.singletonList(listener), true);
success = true;
break; // 只需读一个服务器的数据

Expand Down Expand Up @@ -289,7 +289,7 @@ public void destroy() {

private ConcurrentHashMap<String/*key*/, List<String>> cachedNodeMap = new ConcurrentHashMap<String, List<String>>();

private void doNotify(Jedis jedis, Collection<String> keys, Collection<NotifyListener> listeners) {
private void doNotify(Jedis jedis, Collection<String> keys, Collection<NotifyListener> listeners, boolean reload) {
if (CollectionUtils.isEmpty(keys)
&& CollectionUtils.isEmpty(listeners)) {
return;
Expand All @@ -299,7 +299,7 @@ private void doNotify(Jedis jedis, Collection<String> keys, Collection<NotifyLis

Map<String, String> values = jedis.hgetAll(key);
List<String> currentChildren = values == null ? new ArrayList<String>(0) : new ArrayList<String>(values.keySet());
List<String> oldChildren = cachedNodeMap.get(key);
List<String> oldChildren = reload ? null : cachedNodeMap.get(key);

// 1. 找出增加的 节点
List<String> addChildren = CollectionUtils.getLeftDiff(currentChildren, oldChildren);
Expand Down Expand Up @@ -332,7 +332,7 @@ private void doNotify(Jedis jedis, Collection<String> keys, Collection<NotifyLis

private void doNotify(Jedis jedis, String key) {
for (Map.Entry<Node, Set<NotifyListener>> entry : new HashMap<Node, Set<NotifyListener>>(getSubscribed()).entrySet()) {
doNotify(jedis, Collections.singletonList(key), new HashSet<NotifyListener>(entry.getValue()));
doNotify(jedis, Collections.singletonList(key), new HashSet<NotifyListener>(entry.getValue()), false);
}
}

Expand Down

0 comments on commit ed4b4b4

Please sign in to comment.