com.alibaba.dubbo.rpc.cluster.support.AvailableCluster Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.cluster.support.AvailableCluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultTracingCollectorFactory.java    From dubbo-plus with Apache License 2.0 6 votes vote down vote up
@Override
protected TracingCollector createTracingCollector(List<URL> urls) {

    Invoker<TracingCollector> invoker;
    if(urls.size()==1){
        invoker = protocol.refer(TracingCollector.class,urls.get(0));
    }else{
        List<Invoker<TracingCollector>> invokers = new ArrayList<Invoker<TracingCollector>>();
        URL registryURL = null;
        for (URL url : urls) {
            invokers.add(protocol.refer(TracingCollector.class, url));
            if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) {
                registryURL = url; // 用了最后一个registry url
            }
        }
        if (registryURL != null) { // 有 注册中心协议的URL
            // 对有注册中心的Cluster 只用 AvailableCluster
            URL u = registryURL.addParameter(Constants.CLUSTER_KEY, AvailableCluster.NAME);
            invoker = cluster.join(new StaticDirectory(u, invokers));
        }  else { // 不是 注册中心的URL
            invoker = cluster.join(new StaticDirectory(invokers));
        }
    }
    TracingCollector tracingCollector = proxyFactory.getProxy(invoker);
    return tracingCollector;
}