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);
}
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);
}
}
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());
}
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();
}
}
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));
}
Aggregations