Java Code Examples for com.alibaba.dubbo.common.URL#getHost()
The following examples show how to use
com.alibaba.dubbo.common.URL#getHost() .
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: FileExchangeGroup.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
public FileExchangeGroup(URL url) { super(url); String path = url.getHost() + "/" + url.getPath(); file = new File(path); if (!file.exists()) { throw new IllegalStateException("The group file not exists. file: " + path); } checkModifiedFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { @Override public void run() { // check the file change try { check(); } catch (Throwable t) { // Defensive fault tolerance logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } } }, 2000, 2000, TimeUnit.MILLISECONDS); }
Example 2
Source File: AbstractConfigurator.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } // If override url has port, means it is a provider address. We want to control a specific provider with this override url, it may take effect on the specific provider instance or on consumers holding this provider instance. // 如果覆盖url有端口,则意味着它是提供者地址。我们希望使用此覆盖url控制特定的提供者,它可能对特定的提供者实例或持有此提供者实例的使用者生效。 if (configuratorUrl.getPort() != 0) { if (url.getPort() == configuratorUrl.getPort()) { return configureIfMatch(url.getHost(), url); } } else {// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0 // 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore; // 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider // 覆盖url没有端口,意味着ip覆盖url指定为消费者地址或0.0.0.0 // / / 1。如果它是一个消费者ip地址,意图是控制一个特定的消费者实例,它必须在消费者端生效,任何接收到这个覆盖url的提供商都应该忽略; /// / 2。如果ip是0.0.0.0,则此覆盖url可用于使用者,也可用于提供者 if (url.getParameter(Constants.SIDE_KEY, Constants.PROVIDER).equals(Constants.CONSUMER)) { return configureIfMatch(NetUtils.getLocalHost(), url);// NetUtils.getLocalHost is the ip address consumer registered to registry. } else if (url.getParameter(Constants.SIDE_KEY, Constants.CONSUMER).equals(Constants.PROVIDER)) { return configureIfMatch(Constants.ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch } } return url; }
Example 3
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
public FileExchangeGroup(URL url){ super(url); String path = url.getHost() + "/" + url.getPath(); file = new File(path); if (! file.exists()) { throw new IllegalStateException("The group file not exists. file: " + path); } checkModifiedFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { public void run() { // 检测文件变更 try { check(); } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } } }, 2000, 2000, TimeUnit.MILLISECONDS); }
Example 4
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
public FileExchangeGroup(URL url){ super(url); String path = url.getHost() + "/" + url.getPath(); file = new File(path); if (! file.exists()) { throw new IllegalStateException("The group file not exists. file: " + path); } checkModifiedFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { public void run() { // 检测文件变更 try { check(); } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } } }, 2000, 2000, TimeUnit.MILLISECONDS); }
Example 5
Source File: FileExchangeGroup.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public FileExchangeGroup(URL url){ super(url); String path = url.getHost() + "/" + url.getPath(); file = new File(path); if (! file.exists()) { throw new IllegalStateException("The group file not exists. file: " + path); } checkModifiedFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { public void run() { // 检测文件变更 try { check(); } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } } }, 2000, 2000, TimeUnit.MILLISECONDS); }
Example 6
Source File: AvroProtocol.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected <T> T doRefer(Class<T> type, URL url) throws RpcException { logger.info("type => " + type.getName()); logger.info("url => " + url); try { NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(url.getHost(), url.getPort())); T ref = ReflectRequestor.getClient(type, client); logger.info("Create Avro Client"); return ref; } catch (Exception e) { logger.error(e.getMessage(), e); throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e); } }
Example 7
Source File: AvroProtocol.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException { logger.info("impl => " + impl.getClass()); logger.info("type => " + type.getName()); logger.info("url => " + url); final Server server = new NettyServer(new ReflectResponder(type, impl), new InetSocketAddress(url.getHost(), url.getPort())); server.start(); return new Runnable() { public void run() { try { logger.info("Close Avro Server"); server.close(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
Example 8
Source File: FileExchangeGroup.java From dubbox with Apache License 2.0 | 6 votes |
public FileExchangeGroup(URL url){ super(url); String path = url.getHost() + "/" + url.getPath(); file = new File(path); if (! file.exists()) { throw new IllegalStateException("The group file not exists. file: " + path); } checkModifiedFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { public void run() { // 检测文件变更 try { check(); } catch (Throwable t) { // 防御性容错 logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } } }, 2000, 2000, TimeUnit.MILLISECONDS); }
Example 9
Source File: SyncUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if(!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
Example 10
Source File: AbstractConfigurator.java From dubbox with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 11
Source File: SyncUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if(!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
Example 12
Source File: AbstractConfigurator.java From dubbox with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 13
Source File: ConsulRegistry.java From dubbo3 with Apache License 2.0 | 5 votes |
public ConsulRegistry(URL url) { super(url); if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } consulClient = new ConsulClient(url.getHost(), url.getPort()); }
Example 14
Source File: SyncUtils.java From dubbo3 with Apache License 2.0 | 5 votes |
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if(!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
Example 15
Source File: AbstractConfigurator.java From dubbo3 with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 16
Source File: SyncUtils.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if(!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
Example 17
Source File: AbstractConfigurator.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 18
Source File: SyncUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if(!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
Example 19
Source File: AbstractConfigurator.java From dubbox with Apache License 2.0 | 5 votes |
public URL configure(URL url) { if (configuratorUrl == null || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || url.getHost().equals(configuratorUrl.getHost())) { String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername()); String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) { Set<String> condtionKeys = new HashSet<String>(); condtionKeys.add(Constants.CATEGORY_KEY); condtionKeys.add(Constants.CHECK_KEY); condtionKeys.add(Constants.DYNAMIC_KEY); condtionKeys.add(Constants.ENABLED_KEY); for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { condtionKeys.add(key); if (value != null && ! Constants.ANY_VALUE.equals(value) && ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } } } return doConfigure(url, configuratorUrl.removeParameters(condtionKeys)); } } } return url; }
Example 20
Source File: SyncUtils.java From open-capacity-platform with Apache License 2.0 | 5 votes |
public static Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; Override o = new Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if (!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }