use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.
the class RegistryStatusChecker method check.
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());
}
use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.
the class ConfigTest method testGenericServiceConfig.
@Test
public void testGenericServiceConfig() throws Exception {
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
service.setApplication(new ApplicationConfig("test"));
service.setRegistry(new RegistryConfig("mock://localhost"));
service.setInterface(DemoService.class.getName());
service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
service.setRef(new GenericService() {
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
return null;
}
});
try {
service.export();
Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
MockRegistry registry = (MockRegistry) collection.iterator().next();
URL url = registry.getRegistered().get(0);
Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
} finally {
MockRegistryFactory.cleanCachedRegistry();
service.unexport();
}
}
use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.
the class AbstractRegistryFactory method getRegistry.
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();
}
}
use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.
the class AbstractRegistryFactoryTest method testRegistryFactoryIpCache.
@Test
public void testRegistryFactoryIpCache() throws Exception {
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233"));
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"));
Assert.assertEquals(registry1, registry2);
}
use of com.alibaba.dubbo.registry.Registry in project dubbo by alibaba.
the class AbstractRegistryFactoryTest method testRegistryFactoryCache.
@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);
}
Aggregations