Search in sources :

Example 6 with Registry

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

Example 7 with Registry

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();
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) GenericService(com.alibaba.dubbo.rpc.service.GenericService) MockRegistry(com.alibaba.dubbo.config.spring.registry.MockRegistry) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Registry(com.alibaba.dubbo.registry.Registry) MockRegistry(com.alibaba.dubbo.config.spring.registry.MockRegistry) GenericException(com.alibaba.dubbo.rpc.service.GenericException) URL(com.alibaba.dubbo.common.URL) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) Test(org.junit.Test)

Example 8 with Registry

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

Example 9 with Registry

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

Example 10 with Registry

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);
}
Also used : Registry(com.alibaba.dubbo.registry.Registry) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

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