Java Code Examples for com.alibaba.dubbo.common.URL#setProtocol()

The following examples show how to use com.alibaba.dubbo.common.URL#setProtocol() . 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: DubboMonitorFactroy.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 2
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param urls
 * @return null : no routers ,do nothing
 *         else :routers list
 */
private List<Router> toRouters(List<URL> urls) {
    List<Router> routers = new ArrayList<Router>();
    if(urls == null || urls.size() < 1){
        return routers ;
    }
    if (urls != null && urls.size() > 0) {
        for (URL url : urls) {
            if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
                continue;
            }
            String routerType = url.getParameter(Constants.ROUTER_KEY);
            if (routerType != null && routerType.length() > 0){
                url = url.setProtocol(routerType);
            }
            try{
                Router router = routerFactory.getRouter(url);
                if (!routers.contains(router))
                    routers.add(router);
            } catch (Throwable t) {
                logger.error("convert router url to router error, url: "+ url, t);
            }
        }
    }
    return routers;
}
 
Example 3
Source File: DubboMonitorFactroy.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 4
Source File: AbstractTracingCollectorFactory.java    From dubbo-plus with Apache License 2.0 6 votes vote down vote up
@Override
public TracingCollector getTracingCollector() {
    Collection<Registry> registries =  AbstractRegistryFactory.getRegistries();
    List<URL> urls = new ArrayList<URL>();
    for(Registry registry:registries){
        URL url = registry.getUrl();
        String protocolName = url.getProtocol();
        url=url.setProtocol(Constants.REGISTRY_PROTOCOL);
        url=url.addParameter(Constants.REGISTRY_KEY,protocolName);
        url=url.setPath(TracingCollector.class.getName());
        url=url.addParameter(Constants.INTERFACE_KEY,TracingCollector.class.getName());
        url=url.addParameter(Constants.REFERENCE_FILTER_KEY,"-dst");
        urls.add(url);
    }
    return createTracingCollector(urls);
}
 
Example 5
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param urls
 * @return null : no routers ,do nothing
 *         else :routers list
 */
private List<Router> toRouters(List<URL> urls) {
    List<Router> routers = new ArrayList<Router>();
    if(urls == null || urls.size() < 1){
        return routers ;
    }
    if (urls != null && urls.size() > 0) {
        for (URL url : urls) {
            if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
                continue;
            }
            String routerType = url.getParameter(Constants.ROUTER_KEY);
            if (routerType != null && routerType.length() > 0){
                url = url.setProtocol(routerType);
            }
            try{
                Router router = routerFactory.getRouter(url);
                if (!routers.contains(router))
                    routers.add(router);
            } catch (Throwable t) {
                logger.error("convert router url to router error, url: "+ url, t);
            }
        }
    }
    return routers;
}
 
Example 6
Source File: DubboMonitorFactroy.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 7
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param urls
 * @return null : no routers ,do nothing
 *         else :routers list
 */
private List<Router> toRouters(List<URL> urls) {
    List<Router> routers = new ArrayList<Router>();
    if(urls == null || urls.size() < 1){
        return routers ;
    }
    if (urls != null && urls.size() > 0) {
        for (URL url : urls) {
            if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
                continue;
            }
            String routerType = url.getParameter(Constants.ROUTER_KEY);
            if (routerType != null && routerType.length() > 0){
                url = url.setProtocol(routerType);
            }
            try{
                Router router = routerFactory.getRouter(url);
                if (!routers.contains(router))
                    routers.add(router);
            } catch (Throwable t) {
                logger.error("convert router url to router error, url: "+ url, t);
            }
        }
    }
    return routers;
}
 
Example 8
Source File: DubboMonitorFactory.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false),
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 9
Source File: MulticastRegistry.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
protected void unregistered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            Set<URL> urls = received.get(key);
            if (urls != null) {
                urls.remove(url);
            }
            if (urls == null || urls.isEmpty()){
                if (urls == null){
                    urls = new ConcurrentHashSet<URL>();
                }
                URL empty = url.setProtocol(Constants.EMPTY_PROTOCOL);
                urls.add(empty);
            }
            List<URL> list = toList(urls);
            for (NotifyListener listener : entry.getValue()) {
                notify(key, listener, list);
            }
        }
    }
}
 
Example 10
Source File: RegistryDirectory.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * @param urls
 * @return null : no routers ,do nothing
 * else :routers list
 */
private List<Router> toRouters(List<URL> urls) {
    List<Router> routers = new ArrayList<Router>();
    if (urls == null || urls.isEmpty()) {
        return routers;
    }
    if (urls != null && !urls.isEmpty()) {
        for (URL url : urls) {
            if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
                continue;
            }
            String routerType = url.getParameter(Constants.ROUTER_KEY);
            if (routerType != null && routerType.length() > 0) {
                url = url.setProtocol(routerType);
            }
            try {
                Router router = routerFactory.getRouter(url);
                if (!routers.contains(router))
                    routers.add(router);
            } catch (Throwable t) {
                logger.error("convert router url to router error, url: " + url, t);
            }
        }
    }
    return routers;
}
 
Example 11
Source File: InjvmProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
        .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
        .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 12
Source File: InjvmProtocolTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
        .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
        .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 13
Source File: InjvmProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
        .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
        .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 14
Source File: InjvmProtocolTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
        .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
        .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 15
Source File: InjvmProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
        .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
        .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 16
Source File: InjvmProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInjvmRefer() throws Exception {
    DemoService service = new DemoServiceImpl();
    URL url = URL.valueOf("injvm://127.0.0.1/TestService")
            .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
    Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
    exporters.add(exporter);

    url = url.setProtocol("dubbo");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));

    url = url.addParameter(Constants.GROUP_KEY, "*")
            .addParameter(Constants.VERSION_KEY, "*");
    assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
 
Example 17
Source File: AbstractInterfaceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected List<URL> loadRegistries(boolean provider) {
    checkRegistry();
    List<URL> registryList = new ArrayList<URL>();
    if (registries != null && registries.size() > 0) {
        for (RegistryConfig config : registries) {
            String address = config.getAddress();
            if (address == null || address.length() == 0) {
            	address = Constants.ANYHOST_VALUE;
            }
            String sysaddress = System.getProperty("dubbo.registry.address");
            if (sysaddress != null && sysaddress.length() > 0) {
                address = sysaddress;
            }
            if (address != null && address.length() > 0 
                    && ! RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
                Map<String, String> map = new HashMap<String, String>();
                appendParameters(map, application);
                appendParameters(map, config);
                map.put("path", RegistryService.class.getName());
                map.put("dubbo", Version.getVersion());
                map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                if (ConfigUtils.getPid() > 0) {
                    map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
                }
                if (! map.containsKey("protocol")) {
                    if (ExtensionLoader.getExtensionLoader(RegistryFactory.class).hasExtension("remote")) {
                        map.put("protocol", "remote");
                    } else {
                        map.put("protocol", "dubbo");
                    }
                }
                List<URL> urls = UrlUtils.parseURLs(address, map);
                for (URL url : urls) {
                    url = url.addParameter(Constants.REGISTRY_KEY, url.getProtocol());
                    url = url.setProtocol(Constants.REGISTRY_PROTOCOL);
                    if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
                            || (! provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
                        registryList.add(url);
                    }
                }
            }
        }
    }
    return registryList;
}
 
Example 18
Source File: AbstractInterfaceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected List<URL> loadRegistries(boolean provider) {
    checkRegistry();
    List<URL> registryList = new ArrayList<URL>();
    if (registries != null && registries.size() > 0) {
        for (RegistryConfig config : registries) {
            String address = config.getAddress();
            if (address == null || address.length() == 0) {
            	address = Constants.ANYHOST_VALUE;
            }
            String sysaddress = System.getProperty("dubbo.registry.address");
            if (sysaddress != null && sysaddress.length() > 0) {
                address = sysaddress;
            }
            if (address != null && address.length() > 0 
                    && ! RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
                Map<String, String> map = new HashMap<String, String>();
                appendParameters(map, application);
                appendParameters(map, config);
                map.put("path", RegistryService.class.getName());
                map.put("dubbo", Version.getVersion());
                map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                if (ConfigUtils.getPid() > 0) {
                    map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
                }
                if (! map.containsKey("protocol")) {
                    if (ExtensionLoader.getExtensionLoader(RegistryFactory.class).hasExtension("remote")) {
                        map.put("protocol", "remote");
                    } else {
                        map.put("protocol", "dubbo");
                    }
                }
                List<URL> urls = UrlUtils.parseURLs(address, map);
                for (URL url : urls) {
                    url = url.addParameter(Constants.REGISTRY_KEY, url.getProtocol());
                    url = url.setProtocol(Constants.REGISTRY_PROTOCOL);
                    if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
                            || (! provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
                        registryList.add(url);
                    }
                }
            }
        }
    }
    return registryList;
}
 
Example 19
Source File: AbstractInterfaceConfig.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
protected List<URL> loadRegistries(boolean provider) {
    checkRegistry();
    List<URL> registryList = new ArrayList<>();
    if (registries != null && registries.size() > 0) {
        for (RegistryConfig config : registries) {
            String address = config.getAddress();
            if (address == null || address.length() == 0) {
            	address = Constants.ANYHOST_VALUE;
            }
            String sysaddress = System.getProperty("dubbo.registry.address");
            if (sysaddress != null && sysaddress.length() > 0) {
                address = sysaddress;
            }
            if (address.length() > 0 && !RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
                Map<String, String> map = new HashMap<>();
                appendParameters(map, application);
                appendParameters(map, config);
                map.put("path", RegistryService.class.getName());
                map.put("dubbo", Version.getVersion());
                map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                if (ConfigUtils.getPid() > 0) {
                    map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
                }
                if (! map.containsKey("protocol")) {
                    if (ExtensionLoader.getExtensionLoader(RegistryFactory.class).hasExtension("remote")) {
                        map.put("protocol", "remote");
                    } else {
                        map.put("protocol", "dubbo");
                    }
                }
                List<URL> urls = UrlUtils.parseURLs(address, map);
                for (URL url : urls) {
                    url = url.addParameter(Constants.REGISTRY_KEY, url.getProtocol());
                    url = url.setProtocol(Constants.REGISTRY_PROTOCOL);
                    if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
                            || (! provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
                        registryList.add(url);
                    }
                }
            }
        }
    }
    return registryList;
}
 
Example 20
Source File: AbstractInterfaceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected List<URL> loadRegistries(boolean provider) {
    checkRegistry();
    List<URL> registryList = new ArrayList<URL>();
    if (registries != null && registries.size() > 0) {
        for (RegistryConfig config : registries) {
            String address = config.getAddress();
            if (address == null || address.length() == 0) {
            	address = Constants.ANYHOST_VALUE;
            }
            String sysaddress = System.getProperty("dubbo.registry.address");
            if (sysaddress != null && sysaddress.length() > 0) {
                address = sysaddress;
            }
            if (address != null && address.length() > 0 
                    && ! RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
                Map<String, String> map = new HashMap<String, String>();
                appendParameters(map, application);
                appendParameters(map, config);
                map.put("path", RegistryService.class.getName());
                map.put("dubbo", Version.getVersion());
                map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                if (ConfigUtils.getPid() > 0) {
                    map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
                }
                if (! map.containsKey("protocol")) {
                    if (ExtensionLoader.getExtensionLoader(RegistryFactory.class).hasExtension("remote")) {
                        map.put("protocol", "remote");
                    } else {
                        map.put("protocol", "dubbo");
                    }
                }
                List<URL> urls = UrlUtils.parseURLs(address, map);
                for (URL url : urls) {
                    url = url.addParameter(Constants.REGISTRY_KEY, url.getProtocol());
                    url = url.setProtocol(Constants.REGISTRY_PROTOCOL);
                    if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
                            || (! provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
                        registryList.add(url);
                    }
                }
            }
        }
    }
    return registryList;
}