Search in sources :

Example 6 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryProtocol method refer.

@Override
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
    url = getRegistryUrl(url);
    Registry registry = 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(REFER_KEY));
    String group = qs.get(GROUP_KEY);
    if (group != null && group.length() > 0) {
        if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) {
            return doRefer(Cluster.getCluster(MergeableCluster.NAME), registry, type, url, qs);
        }
    }
    Cluster cluster = Cluster.getCluster(qs.get(CLUSTER_KEY));
    return doRefer(cluster, registry, type, url, qs);
}
Also used : MergeableCluster(org.apache.dubbo.rpc.cluster.support.MergeableCluster) Cluster(org.apache.dubbo.rpc.cluster.Cluster) Registry(org.apache.dubbo.registry.Registry)

Example 7 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryProtocol method doReExport.

private <T> void doReExport(final Invoker<T> originInvoker, ExporterChangeableWrapper<T> exporter, URL registryUrl, URL oldProviderUrl, URL newProviderUrl) {
    if (getProviderUrl(originInvoker).getParameter(REGISTER_KEY, true)) {
        Registry registry = null;
        try {
            registry = getRegistry(originInvoker);
        } catch (Exception e) {
            throw new SkipFailbackWrapperException(e);
        }
        LOGGER.info("Try to unregister old url: " + oldProviderUrl);
        registry.reExportUnregister(oldProviderUrl);
        LOGGER.info("Try to register new url: " + newProviderUrl);
        registry.reExportRegister(newProviderUrl);
    }
    try {
        ProviderModel.RegisterStatedURL statedUrl = getStatedUrl(registryUrl, newProviderUrl);
        statedUrl.setProviderUrl(newProviderUrl);
        exporter.setRegisterUrl(newProviderUrl);
    } catch (Exception e) {
        throw new SkipFailbackWrapperException(e);
    }
}
Also used : Registry(org.apache.dubbo.registry.Registry) RpcException(org.apache.dubbo.rpc.RpcException) SkipFailbackWrapperException(org.apache.dubbo.registry.support.SkipFailbackWrapperException) SkipFailbackWrapperException(org.apache.dubbo.registry.support.SkipFailbackWrapperException) ProviderModel(org.apache.dubbo.rpc.model.ProviderModel)

Example 8 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryStatusChecker method check.

@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());
}
Also used : Status(org.apache.dubbo.common.status.Status) Registry(org.apache.dubbo.registry.Registry)

Example 9 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class AbstractRegistryFactory method getRegistry.

@Override
public Registry getRegistry(URL url) {
    Registry defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
    if (null != defaultNopRegistry) {
        return defaultNopRegistry;
    }
    url = URLBuilder.from(url).setPath(RegistryService.class.getName()).addParameter(INTERFACE_KEY, RegistryService.class.getName()).removeParameters(EXPORT_KEY, REFER_KEY).build();
    String key = createRegistryCacheKey(url);
    // Lock the registry access process to ensure a single instance of the registry
    LOCK.lock();
    try {
        // double check
        // fix https://github.com/apache/dubbo/issues/7265.
        defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
        if (null != defaultNopRegistry) {
            return defaultNopRegistry;
        }
        Registry registry = REGISTRIES.get(key);
        if (registry != null) {
            return registry;
        }
        // create registry by spi/ioc
        registry = createRegistry(url);
        if (registry == null) {
            throw new IllegalStateException("Can not create registry " + url);
        }
        REGISTRIES.put(key, registry);
        return registry;
    } finally {
        // Release the lock
        LOCK.unlock();
    }
}
Also used : ServiceDiscoveryRegistry(org.apache.dubbo.registry.client.ServiceDiscoveryRegistry) Registry(org.apache.dubbo.registry.Registry) RegistryService(org.apache.dubbo.registry.RegistryService)

Example 10 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class AbstractRegistryFactoryTest method testDestroyAllRegistries.

@Test
public void testDestroyAllRegistries() {
    Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":8888?group=xxx"));
    Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":9999?group=yyy"));
    Registry registry3 = new AbstractRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2020?group=yyy")) {

        @Override
        public boolean isAvailable() {
            return true;
        }
    };
    Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
    Assertions.assertTrue(registries.contains(registry1));
    Assertions.assertTrue(registries.contains(registry2));
    registry3.destroy();
    registries = AbstractRegistryFactory.getRegistries();
    Assertions.assertFalse(registries.contains(registry3));
    AbstractRegistryFactory.destroyAll();
    registries = AbstractRegistryFactory.getRegistries();
    Assertions.assertFalse(registries.contains(registry1));
    Assertions.assertFalse(registries.contains(registry2));
}
Also used : Registry(org.apache.dubbo.registry.Registry) Test(org.junit.jupiter.api.Test)

Aggregations

Registry (org.apache.dubbo.registry.Registry)26 Test (org.junit.jupiter.api.Test)9 AbstractRegistry (org.apache.dubbo.registry.support.AbstractRegistry)8 URL (org.apache.dubbo.common.URL)7 ArrayList (java.util.ArrayList)3 Status (org.apache.dubbo.common.status.Status)3 ProviderModel (org.apache.dubbo.rpc.model.ProviderModel)3 RegistryStatusChecker (org.apache.dubbo.registry.status.RegistryStatusChecker)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConfigurationException (org.apache.dubbo.admin.common.exception.ConfigurationException)1 QOS_HOST (org.apache.dubbo.common.constants.QosConstants.QOS_HOST)1 QOS_PORT (org.apache.dubbo.common.constants.QosConstants.QOS_PORT)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 RegistryConfig (org.apache.dubbo.config.RegistryConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 MockRegistry (org.apache.dubbo.config.spring.registry.MockRegistry)1 NotifyListener (org.apache.dubbo.registry.NotifyListener)1