com.alibaba.dubbo.registry.Registry Java Examples
The following examples show how to use
com.alibaba.dubbo.registry.Registry.
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: AbstractTracingCollectorFactory.java From dubbo-plus with Apache License 2.0 | 6 votes |
@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 #2
Source File: RegistryProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { // 获取registry属性值,默认是dubbo协议 url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY); // 查询注册器=》 Registry registry = registryFactory.getRegistry(url); if (RegistryService.class.equals(type)) { return proxyFactory.getInvoker((T) registry, type, url); } // group="a,b" or group="*" Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); String group = qs.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { if ((Constants.COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) { // 查询dubbo服务执行器=》 return doRefer(getMergeableCluster(), registry, type, url); } } // =》ZookeeperRegistry return doRefer(cluster, registry, type, url); }
Example #3
Source File: AbstractRegistryFactory.java From dubbox with Apache License 2.0 | 6 votes |
/** * 关闭所有已创建注册中心 */ public static void destroyAll() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Close all registries " + getRegistries()); } // 锁定注册中心关闭过程 LOCK.lock(); try { for (Registry registry : getRegistries()) { try { registry.destroy(); } catch (Throwable e) { LOGGER.error(e.getMessage(), e); } } REGISTRIES.clear(); } finally { // 释放锁 LOCK.unlock(); } }
Example #4
Source File: RegistryStatusChecker.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Status check() { Collection<Registry> registries = AbstractRegistryFactory.getRegistries(); if (registries.isEmpty()) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (Registry registry : registries) { if (buf.length() > 0) { buf.append(","); } buf.append(registry.getUrl().getAddress()); if (!registry.isAvailable()) { level = Status.Level.ERROR; buf.append("(disconnected)"); } else { buf.append("(connected)"); } } return new Status(level, buf.toString()); }
Example #5
Source File: RegistryStatusChecker.java From dubbo3 with Apache License 2.0 | 6 votes |
public Status check() { Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries(); if (regsitries == null || regsitries.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (Registry registry : regsitries) { if (buf.length() > 0) { buf.append(","); } buf.append(registry.getUrl().getAddress()); if (! registry.isAvailable()) { level = Status.Level.ERROR; buf.append("(disconnected)"); } else { buf.append("(connected)"); } } return new Status(level, buf.toString()); }
Example #6
Source File: AbstractRegistryFactory.java From dubbo3 with Apache License 2.0 | 6 votes |
public Registry getRegistry(URL url) { url = url.setPath(RegistryService.class.getName()) .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY); String key = url.toServiceString(); // 锁定注册中心获取过程,保证注册中心单一实例 LOCK.lock(); try { Registry registry = REGISTRIES.get(key); if (registry != null) { return registry; } registry = createRegistry(url); if (registry == null) { throw new IllegalStateException("Can not create registry " + url); } REGISTRIES.put(key, registry); return registry; } finally { // 释放锁 LOCK.unlock(); } }
Example #7
Source File: ZookeeperRegistryTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Ignore @Test /* This UT is unstable, consider remove it later. @see https://github.com/apache/incubator-dubbo/issues/1787 */ public void testStatusChecker() { RegistryStatusChecker registryStatusChecker = new RegistryStatusChecker(); Status status = registryStatusChecker.check(); assertThat(status.getLevel(), is(Status.Level.UNKNOWN)); Registry registry = zookeeperRegistryFactory.getRegistry(registryUrl); assertThat(registry, not(nullValue())); status = registryStatusChecker.check(); assertThat(status.getLevel(), is(Status.Level.ERROR)); registry.register(serviceUrl); status = registryStatusChecker.check(); assertThat(status.getLevel(), is(Status.Level.OK)); }
Example #8
Source File: RegistryProtocol.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY); Registry registry = registryFactory.getRegistry(url); if (RegistryService.class.equals(type)) { return proxyFactory.getInvoker((T) registry, type, url); } // group="a,b" or group="*" Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); String group = qs.get(Constants.GROUP_KEY); if (group != null && group.length() > 0 ) { if ( ( Constants.COMMA_SPLIT_PATTERN.split( group ) ).length > 1 || "*".equals( group ) ) { return doRefer( getMergeableCluster(), registry, type, url ); } } return doRefer(cluster, registry, type, url); }
Example #9
Source File: DubboRegistryFactory.java From dubbox with Apache License 2.0 | 6 votes |
public Registry createRegistry(URL url) { url = getRegistryURL(url); List<URL> urls = new ArrayList<URL>(); urls.add(url.removeParameter(Constants.BACKUP_KEY)); String backup = url.getParameter(Constants.BACKUP_KEY); if (backup != null && backup.length() > 0) { String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup); for (String address : addresses) { urls.add(url.setAddress(address)); } } RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString())); Invoker<RegistryService> registryInvoker = cluster.join(directory); RegistryService registryService = proxyFactory.getProxy(registryInvoker); DubboRegistry registry = new DubboRegistry(registryInvoker, registryService); directory.setRegistry(registry); directory.setProtocol(protocol); directory.notify(urls); directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters())); return registry; }
Example #10
Source File: RegistryProtocol.java From dubbo3 with Apache License 2.0 | 6 votes |
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) { RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url); directory.setRegistry(registry); directory.setProtocol(protocol); URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters()); if (! Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY, Constants.CHECK_KEY, String.valueOf(false))); } directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY + "," + Constants.CONFIGURATORS_CATEGORY + "," + Constants.ROUTERS_CATEGORY)); return cluster.join(directory); }
Example #11
Source File: RegistryStatusChecker.java From dubbox with Apache License 2.0 | 6 votes |
public Status check() { Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries(); if (regsitries == null || regsitries.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (Registry registry : regsitries) { if (buf.length() > 0) { buf.append(","); } buf.append(registry.getUrl().getAddress()); if (! registry.isAvailable()) { level = Status.Level.ERROR; buf.append("(disconnected)"); } else { buf.append("(connected)"); } } return new Status(level, buf.toString()); }
Example #12
Source File: RegistryProtocol.java From dubbox with Apache License 2.0 | 6 votes |
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) { RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url); directory.setRegistry(registry); directory.setProtocol(protocol); URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters()); if (! Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY, Constants.CHECK_KEY, String.valueOf(false))); } directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY + "," + Constants.CONFIGURATORS_CATEGORY + "," + Constants.ROUTERS_CATEGORY)); return cluster.join(directory); }
Example #13
Source File: RegistryStatusChecker.java From dubbox with Apache License 2.0 | 6 votes |
public Status check() { Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries(); if (regsitries == null || regsitries.size() == 0) { return new Status(Status.Level.UNKNOWN); } Status.Level level = Status.Level.OK; StringBuilder buf = new StringBuilder(); for (Registry registry : regsitries) { if (buf.length() > 0) { buf.append(","); } buf.append(registry.getUrl().getAddress()); if (! registry.isAvailable()) { level = Status.Level.ERROR; buf.append("(disconnected)"); } else { buf.append("(connected)"); } } return new Status(level, buf.toString()); }
Example #14
Source File: AbstractRegistryFactory.java From dubbox with Apache License 2.0 | 6 votes |
/** * 关闭所有已创建注册中心 */ public static void destroyAll() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Close all registries " + getRegistries()); } // 锁定注册中心关闭过程 LOCK.lock(); try { for (Registry registry : getRegistries()) { try { registry.destroy(); } catch (Throwable e) { LOGGER.error(e.getMessage(), e); } } REGISTRIES.clear(); } finally { // 释放锁 LOCK.unlock(); } }
Example #15
Source File: AbstractRegistryFactory.java From dubbox with Apache License 2.0 | 6 votes |
public Registry getRegistry(URL url) { url = url.setPath(RegistryService.class.getName()) .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY); String key = url.toServiceString(); // 锁定注册中心获取过程,保证注册中心单一实例 LOCK.lock(); try { Registry registry = REGISTRIES.get(key); if (registry != null) { return registry; } registry = createRegistry(url); if (registry == null) { throw new IllegalStateException("Can not create registry " + url); } REGISTRIES.put(key, registry); return registry; } finally { // 释放锁 LOCK.unlock(); } }
Example #16
Source File: DubboRegistryStatusHealthCheck.java From watcher with Apache License 2.0 | 6 votes |
@Override protected Result check() throws Exception { Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries(); if (regsitries.size() == 0) { return Result.healthy("no registry found"); } boolean isOK = true; StringBuilder buf = new StringBuilder(); for (Registry registry : regsitries) { if (buf.length() > 0) { buf.append(","); } buf.append(registry.getUrl().getAddress()); if (!registry.isAvailable()) { isOK = false; buf.append("(disconnected)"); } else { buf.append("(connected)"); } } if (isOK) { return Result.healthy(); } else { return Result.unhealthy(buf.toString()); } }
Example #17
Source File: RegistryProtocol.java From dubbo3 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY); Registry registry = registryFactory.getRegistry(url); if (RegistryService.class.equals(type)) { return proxyFactory.getInvoker((T) registry, type, url); } // group="a,b" or group="*" Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); String group = qs.get(Constants.GROUP_KEY); if (group != null && group.length() > 0 ) { if ( ( Constants.COMMA_SPLIT_PATTERN.split( group ) ).length > 1 || "*".equals( group ) ) { return doRefer( getMergeableCluster(), registry, type, url ); } } return doRefer(cluster, registry, type, url); }
Example #18
Source File: AbstractRegistryFactory.java From dubbox with Apache License 2.0 | 6 votes |
/** * 关闭所有已创建注册中心 */ public static void destroyAll() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Close all registries " + getRegistries()); } // 锁定注册中心关闭过程 LOCK.lock(); try { for (Registry registry : getRegistries()) { try { registry.destroy(); } catch (Throwable e) { LOGGER.error(e.getMessage(), e); } } REGISTRIES.clear(); } finally { // 释放锁 LOCK.unlock(); } }
Example #19
Source File: AbstractRegistryFactoryTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testRegistryFactoryCache() throws Exception { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"); Registry registry1 = registryFactory.getRegistry(url); Registry registry2 = registryFactory.getRegistry(url); Assert.assertEquals(registry1, registry2); }
Example #20
Source File: AbstractRegistryFactoryTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testRegistryFactoryCache() throws Exception { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"); Registry registry1 = registryFactory.getRegistry(url); Registry registry2 = registryFactory.getRegistry(url); Assert.assertEquals(registry1, registry2); }
Example #21
Source File: RegistriesController.java From dubbox with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/subscribed", method = RequestMethod.GET) public String subscribed(@RequestParam String registry, Model model) { Collection<Registry> registries = AbstractRegistryFactory.getRegistries(); Registry reg = null; if (registries.size() > 0) { for (Registry r : registries) { String sp = r.getUrl().getAddress(); if (((registry == null || registry.length() == 0) && reg == null) || sp.equals(registry)) { reg = r; } } } List<String> rows = new ArrayList<String>(); if (reg instanceof AbstractRegistry) { Set<URL> services = ((AbstractRegistry) reg).getSubscribed().keySet(); if (services.size() > 0) { for (URL u : services) { rows.add(u.toFullString()); } } } model.addAttribute("registry", registry); model.addAttribute("rows", rows); return "registry/subscribed"; }
Example #22
Source File: Offline.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public String execute(CommandContext commandContext, String[] args) { logger.info("receive offline command"); String servicePattern = ".*"; if (args != null && args.length > 0) { servicePattern = args[0]; } boolean hasService = false; List<ProviderModel> providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { if (providerModel.getServiceName().matches(servicePattern)) { hasService = true; Set<ProviderInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (!providerInvokerWrapper.isReg()) { continue; } Registry registry = registryFactory.getRegistry(providerInvokerWrapper.getRegistryUrl()); registry.unregister(providerInvokerWrapper.getProviderUrl()); providerInvokerWrapper.setReg(false); } } } if (hasService) { return "OK"; } else { return "service not found"; } }
Example #23
Source File: RegistriesController.java From dubbox with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/registered", method = RequestMethod.GET) public String registered(@RequestParam String registry, Model model) { Collection<Registry> registries = AbstractRegistryFactory.getRegistries(); Registry reg = null; if (registries.size() > 0) { for (Registry r : registries) { String sp = r.getUrl().getAddress(); if (((registry == null || registry.length() == 0) && reg == null) || sp.equals(registry)) { reg = r; } } } List<String> rows = new ArrayList<String>(); if (reg instanceof AbstractRegistry) { Set<URL> services = ((AbstractRegistry) reg).getRegistered(); if (services != null && services.size() > 0) { for (URL u : services) { rows.add(u.toFullString()); } } } model.addAttribute("registry", registry); model.addAttribute("rows", rows); return "registry/registered"; }
Example #24
Source File: AbstractRegistryFactoryTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testRegistryFactoryCache() throws Exception { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"); Registry registry1 = registryFactory.getRegistry(url); Registry registry2 = registryFactory.getRegistry(url); Assert.assertEquals(registry1, registry2); }
Example #25
Source File: RedisRegistryTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testAvailableWithBackup() { URL url = URL.valueOf("redis://redisOne:8880").addParameter(BACKUP_KEY, "redisTwo:8881"); Registry registry = new RedisRegistryFactory().createRegistry(url); assertThat(registry.isAvailable(), is(false)); url = URL.valueOf(this.registryUrl.toFullString()).addParameter(BACKUP_KEY, "redisTwo:8881"); registry = new RedisRegistryFactory().createRegistry(url); assertThat(registry.isAvailable(), is(true)); }
Example #26
Source File: RegistriesPageHandler.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Page handle(URL url) { List<List<String>> rows = new ArrayList<List<String>>(); Collection<Registry> registries = AbstractRegistryFactory.getRegistries(); int registeredCount = 0; int subscribedCount = 0; if (registries != null && registries.size() > 0) { for (Registry registry : registries) { String server = registry.getUrl().getAddress(); List<String> row = new ArrayList<String>(); row.add(NetUtils.getHostName(server) + "/" + server); if (registry.isAvailable()) { row.add("<font color=\"green\">Connected</font>"); } else { row.add("<font color=\"red\">Disconnected</font>"); } int registeredSize = 0; int subscribedSize = 0; if (registry instanceof AbstractRegistry) { registeredSize = ((AbstractRegistry) registry).getRegistered().size(); registeredCount += registeredSize; subscribedSize = ((AbstractRegistry) registry).getSubscribed().size(); subscribedCount += subscribedSize; } row.add("<a href=\"registered.html?registry=" + server + "\">Registered(" + registeredSize + ")</a>"); row.add("<a href=\"subscribed.html?registry=" + server + "\">Subscribed(" + subscribedSize + ")</a>"); rows.add(row); } } return new Page("Registries", "Registries (" + rows.size() + ")", new String[] { "Registry Address:", "Status", "Registered(" + registeredCount + ")", "Subscribed(" + subscribedCount + ")" }, rows); }
Example #27
Source File: RegistryProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
/** * Get an instance of registry based on the address of invoker 根据调用程序的地址获取注册表实例 * * @param originInvoker * @return */ private Registry getRegistry(final Invoker<?> originInvoker) { // 查询注册的url=》 URL registryUrl = getRegistryUrl(originInvoker); // 这里是工厂模式 return registryFactory.getRegistry(registryUrl); }
Example #28
Source File: RegistryProtocol.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
/** * 根据invoker的地址获取registry实例 * @param originInvoker * @return */ private Registry getRegistry(final Invoker<?> originInvoker){ URL registryUrl = originInvoker.getUrl(); if (Constants.REGISTRY_PROTOCOL.equals(registryUrl.getProtocol())) { String protocol = registryUrl.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_DIRECTORY); registryUrl = registryUrl.setProtocol(protocol).removeParameter(Constants.REGISTRY_KEY); } return registryFactory.getRegistry(registryUrl); }
Example #29
Source File: RegisteredPageHandler.java From dubbo3 with Apache License 2.0 | 4 votes |
public Page handle(URL url) { String registryAddress = url.getParameter("registry", ""); List<List<String>> rows = new ArrayList<List<String>>(); Collection<Registry> registries = AbstractRegistryFactory.getRegistries(); StringBuilder select = new StringBuilder(); Registry registry = null; if (registries != null && registries.size() > 0) { if (registries.size() == 1) { registry = registries.iterator().next(); select.append(" > " + registry.getUrl().getAddress()); } else { select.append(" > <select onchange=\"window.location.href='registered.html?registry=' + this.value;\">"); for (Registry r : registries) { String sp = r.getUrl().getAddress(); select.append("<option value=\">"); select.append(sp); if (((registryAddress == null || registryAddress.length() == 0) && registry == null) || registryAddress.equals(sp)) { registry = r; select.append("\" selected=\"selected"); } select.append("\">"); select.append(sp); select.append("</option>"); } select.append("</select>"); } } if (registry instanceof AbstractRegistry) { Set<URL> services = ((AbstractRegistry) registry).getRegistered(); if (services != null && services.size() > 0) { for (URL u : services) { List<String> row = new ArrayList<String>(); row.add(u.toFullString().replace("<", "<").replace(">", ">")); rows.add(row); } } } return new Page("<a href=\"registries.html\">Registries</a>" + select.toString() + " > Registered | <a href=\"subscribed.html?registry=" + registryAddress + "\">Subscribed</a>", "Registered (" + rows.size() + ")", new String[] { "Provider URL:" }, rows); }
Example #30
Source File: RegistryDirectory.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public void setRegistry(Registry registry) { this.registry = registry; }