Search in sources :

Example 1 with Registry

use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryProtocol method refer.

@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);
}
Also used : Registry(com.alibaba.dubbo.registry.Registry)

Example 2 with Registry

use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryProtocol method export.

public <T> Exporter<T> export(final Invoker<T> originInvoker) throws RpcException {
    //export invoker
    final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker);
    //registry provider
    final Registry registry = getRegistry(originInvoker);
    final URL registedProviderUrl = getRegistedProviderUrl(originInvoker);
    registry.register(registedProviderUrl);
    // 订阅override数据
    // FIXME 提供者订阅时,会影响同一JVM即暴露服务,又引用同一服务的的场景,因为subscribed以服务名为缓存的key,导致订阅信息覆盖。
    final URL overrideSubscribeUrl = getSubscribedOverrideUrl(registedProviderUrl);
    final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl);
    overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
    registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
    //保证每次export都返回一个新的exporter实例
    return new Exporter<T>() {

        public Invoker<T> getInvoker() {
            return exporter.getInvoker();
        }

        public void unexport() {
            try {
                exporter.unexport();
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
            try {
                registry.unregister(registedProviderUrl);
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
            try {
                overrideListeners.remove(overrideSubscribeUrl);
                registry.unsubscribe(overrideSubscribeUrl, overrideSubscribeListener);
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    };
}
Also used : Registry(com.alibaba.dubbo.registry.Registry) Exporter(com.alibaba.dubbo.rpc.Exporter) URL(com.alibaba.dubbo.common.URL)

Example 3 with Registry

use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.

the class SubscribedPageHandler method handle.

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(" &gt; " + registry.getUrl().getAddress());
        } else {
            select.append(" &gt; <select onchange=\"window.location.href='subscribed.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).getSubscribed().keySet();
        if (services != null && services.size() > 0) {
            for (URL u : services) {
                List<String> row = new ArrayList<String>();
                row.add(u.toFullString().replace("<", "&lt;").replace(">", "&gt;"));
                rows.add(row);
            }
        }
    }
    return new Page("<a href=\"registries.html\">Registries</a>" + select.toString() + " &gt; <a href=\"registered.html?registry=" + registryAddress + "\">Registered</a> | Subscribed", "Subscribed (" + rows.size() + ")", new String[] { "Consumer URL:" }, rows);
}
Also used : AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Page(com.alibaba.dubbo.container.page.Page) AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) Registry(com.alibaba.dubbo.registry.Registry) URL(com.alibaba.dubbo.common.URL)

Example 4 with Registry

use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.

the class RegisteredPageHandler method handle.

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(" &gt; " + registry.getUrl().getAddress());
        } else {
            select.append(" &gt; <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("<", "&lt;").replace(">", "&gt;"));
                rows.add(row);
            }
        }
    }
    return new Page("<a href=\"registries.html\">Registries</a>" + select.toString() + " &gt; Registered | <a href=\"subscribed.html?registry=" + registryAddress + "\">Subscribed</a>", "Registered (" + rows.size() + ")", new String[] { "Provider URL:" }, rows);
}
Also used : AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Page(com.alibaba.dubbo.container.page.Page) AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) Registry(com.alibaba.dubbo.registry.Registry) URL(com.alibaba.dubbo.common.URL)

Example 5 with Registry

use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistriesPageHandler method handle.

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);
}
Also used : AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Page(com.alibaba.dubbo.container.page.Page) AbstractRegistry(com.alibaba.dubbo.registry.support.AbstractRegistry) Registry(com.alibaba.dubbo.registry.Registry)

Aggregations

Registry (com.alibaba.dubbo.registry.Registry)11 URL (com.alibaba.dubbo.common.URL)5 Test (org.junit.Test)4 Page (com.alibaba.dubbo.container.page.Page)3 AbstractRegistry (com.alibaba.dubbo.registry.support.AbstractRegistry)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Status (com.alibaba.dubbo.common.status.Status)1 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)1 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)1 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)1 MockRegistry (com.alibaba.dubbo.config.spring.registry.MockRegistry)1 RegistryService (com.alibaba.dubbo.registry.RegistryService)1 Exporter (com.alibaba.dubbo.rpc.Exporter)1 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1 GenericService (com.alibaba.dubbo.rpc.service.GenericService)1 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1