Java Code Examples for com.alibaba.dubbo.common.URL#getPath()
The following examples show how to use
com.alibaba.dubbo.common.URL#getPath() .
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: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
public Router getRouter(URL url) { try { // File URL 转换成 其它Route URL,然后Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content> String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议 String type = null; // 使用文件后缀做为类型 String path = url.getPath(); if (path != null) { int i = path.lastIndexOf('.'); if (i > 0) { type = path.substring(i + 1); } } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example 3
Source File: DubboMonitorFactroy.java From dubbox with Apache License 2.0 | 6 votes |
@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: 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: DubboMonitorFactroy.java From dubbox with Apache License 2.0 | 6 votes |
@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 6
Source File: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
public Router getRouter(URL url) { try { // File URL 转换成 其它Route URL,然后Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content> String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议 String type = null; // 使用文件后缀做为类型 String path = url.getPath(); if (path != null) { int i = path.lastIndexOf('.'); if (i > 0) { type = path.substring(i + 1); } } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example 7
Source File: DubboMonitorFactroy.java From dubbo3 with Apache License 2.0 | 6 votes |
@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 8
Source File: FileRouterFactory.java From dubbo3 with Apache License 2.0 | 6 votes |
public Router getRouter(URL url) { try { // File URL 转换成 其它Route URL,然后Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content> String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议 String type = null; // 使用文件后缀做为类型 String path = url.getPath(); if (path != null) { int i = path.lastIndexOf('.'); if (i > 0) { type = path.substring(i + 1); } } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example 9
Source File: DubboMonitorFactroy.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@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 10
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 11
Source File: DubboMonitorFactroy.java From dubbox with Apache License 2.0 | 6 votes |
@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 12
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 13
Source File: FileRouterFactory.java From dubbox with Apache License 2.0 | 6 votes |
public Router getRouter(URL url) { try { // File URL 转换成 其它Route URL,然后Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content> String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // 将原类型转为协议 String type = null; // 使用文件后缀做为类型 String path = url.getPath(); if (path != null) { int i = path.lastIndexOf('.'); if (i > 0) { type = path.substring(i + 1); } } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example 14
Source File: DubboMonitorFactory.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@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 15
Source File: FileRouterFactory.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Router getRouter(URL url) { try { // Transform File URL into Script Route URL, and Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content> String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // Replace original protocol (maybe 'file') with 'script' String type = null; // Use file suffix to config script type, e.g., js, groovy ... String path = url.getPath(); if (path != null) { int i = path.lastIndexOf('.'); if (i > 0) { type = path.substring(i + 1); } } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false); URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameter(Constants.RUNTIME_KEY, runtime).addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example 16
Source File: RegistryDirectory.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
/** * 合并url参数 顺序为override > -D >Consumer > Provider * @param providerUrl * @param overrides * @return */ private URL mergeUrl(URL providerUrl){ providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数 List<Configurator> localConfigurators = this.configurators; // local reference if (localConfigurators != null && localConfigurators.size() > 0) { for (Configurator configurator : localConfigurators) { providerUrl = configurator.configure(providerUrl); } } providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker! //directoryUrl 与 override 合并是在notify的最后,这里不能够处理 this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数 if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0 //fix by tony.chenl DUBBO-44 String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { path = path.substring(i + 1); } i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(0, i); } providerUrl = providerUrl.setPath(path); } } return providerUrl; }
Example 17
Source File: RegistryDirectory.java From dubbox with Apache License 2.0 | 5 votes |
/** * 合并url参数 顺序为override > -D >Consumer > Provider * @param providerUrl * @param overrides * @return */ private URL mergeUrl(URL providerUrl){ providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数 List<Configurator> localConfigurators = this.configurators; // local reference if (localConfigurators != null && localConfigurators.size() > 0) { for (Configurator configurator : localConfigurators) { providerUrl = configurator.configure(providerUrl); } } providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker! //directoryUrl 与 override 合并是在notify的最后,这里不能够处理 this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数 if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0 //fix by tony.chenl DUBBO-44 String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { path = path.substring(i + 1); } i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(0, i); } providerUrl = providerUrl.setPath(path); } } return providerUrl; }
Example 18
Source File: RegistryDirectory.java From dubbo3 with Apache License 2.0 | 5 votes |
/** * 合并url参数 顺序为override > -D >Consumer > Provider * * @param providerUrl provider url * @return URL */ private URL mergeUrl(URL providerUrl) { providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数 List<Configurator> localConfigurators = this.configurators; // local reference if (localConfigurators != null && localConfigurators.size() > 0) { for (Configurator configurator : localConfigurators) { providerUrl = configurator.configure(providerUrl); } } providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker! //directoryUrl 与 override 合并是在notify的最后,这里不能够处理 this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数 if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0 //fix by tony.chenl DUBBO-44 String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { path = path.substring(i + 1); } i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(0, i); } providerUrl = providerUrl.setPath(path); } } return providerUrl; }
Example 19
Source File: RegistryDirectory.java From dubbox with Apache License 2.0 | 5 votes |
/** * 合并url参数 顺序为override > -D >Consumer > Provider * @param providerUrl * @param overrides * @return */ private URL mergeUrl(URL providerUrl){ providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数 List<Configurator> localConfigurators = this.configurators; // local reference if (localConfigurators != null && localConfigurators.size() > 0) { for (Configurator configurator : localConfigurators) { providerUrl = configurator.configure(providerUrl); } } providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker! //directoryUrl 与 override 合并是在notify的最后,这里不能够处理 this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数 if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0 //fix by tony.chenl DUBBO-44 String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { path = path.substring(i + 1); } i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(0, i); } providerUrl = providerUrl.setPath(path); } } return providerUrl; }
Example 20
Source File: RegistryDirectory.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
/** * Merge url parameters. the order is: override > -D >Consumer > Provider 合并url参数。顺序是:覆盖> -D >使用者>提供者 * * @param providerUrl * @return */ private URL mergeUrl(URL providerUrl) { providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // Merge the consumer side parameters List<Configurator> localConfigurators = this.configurators; // local reference if (localConfigurators != null && !localConfigurators.isEmpty()) { for (Configurator configurator : localConfigurators) { providerUrl = configurator.configure(providerUrl); } } providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker! 不要检查连接是否成功,请始终创建调用程序! // The combination of directoryUrl and override is at the end of notify, which can't be handled here directoryUrl和override的组合在notify的末尾,这里无法处理 this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // Merge the provider side parameters if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // Compatible version 1.0 //fix by tony.chenl DUBBO-44 String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { path = path.substring(i + 1); } i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(0, i); } providerUrl = providerUrl.setPath(path); } } return providerUrl; }