Dubbo-Registry

Registry

@see

http://dubbo.io/User+Guide-zh.htm#UserGuide-zh-Multicast%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83

https://my.oschina.net/pingpangkuangmo/blog/515673

http://www.cnblogs.com/ghj1976/p/5328376.html

http://blog.csdn.net/quhongwei_zhanqiu/article/details/41683143

AbstractRegistry

registered -> 注册的URL

private final Set registered = new ConcurrentHashSet();

subscribed -> 订阅的URL,当订阅成功时一般都需要通知订阅方,所以这里存储的是 订阅URL - 订阅监听

private final ConcurrentMap> subscribed = new ConcurrentHashMap>();

notified -> 已通知的订阅,订阅URL-

private final ConcurrentMap>> notified = new ConcurrentHashMap();

以上这些URL指的都是当前服务端/客服端,并不是整个注册中心

public void register(URL url) {

    // ...

    registered.add(url);

}

public void subscribe(URL url, NotifyListener listener) { 

 // ... 

 Set listeners = subscribed.get(url); if (listeners == null) { 

 subscribed.putIfAbsent(url, new ConcurrentHashSet());

        listeners = subscribed.get(url);

    }

    listeners.add(listener);

}


MulticastRegistry

@see

http://dubbo.io/User+Guide-zh.htm#UserGuide-zh-Multicast%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83

http://www.cnblogs.com/ghj1976/p/5328376.html

http://www.cnblogs.com/ghj1976/p/5276452.html

1、提供方启动时广播自己的地址。

2、消费方启动时广播订阅请求。

3、提供方收到订阅请求时,单播自己的地址给订阅者,如果设置了unicast=false,则广播给订阅者。

4、消费方收到提供方地址时,连接该地址进行RPC调用。

//已接收的订阅:key:订阅url - value:提供服务的url集合

private final ConcurrentMap> received = new ConcurrentHashMap>();


//注册完成后置操作//遍历已订阅的urls,判断刚注册完成的url是否匹配,若匹配则说明订阅的url已到达,添加至received,并且获取订阅监听,通知监听完成相关后续操作//当注册成功时触发,有两处: 

 1、当前端(服务端或客户端)注册完成 时  

2、其他端注册完成,并发送广/单播通知到当前端,通过DubboMutilcastRegistryReceiver的receive方法接收到时

protected void registered(URL url) { for (Map.Entry> entry : getSubscribed().entrySet()) { URL key = entry.getKey(); if (UrlUtils.isMatch(key, url)) { Seturls = received.get(key); if (urls == null) { received.putIfAbsent(key, new ConcurrentHashSet()); urls = received.get(key); } urls.add(url); List list = toList(urls);

            for (NotifyListener listener : entry.getValue()) {

                notify(key, listener, list);

                synchronized (listener) {

                    listener.notify();

                }

            }

        }

    }

}

你可能感兴趣的:(Dubbo-Registry)