Search in sources :

Example 1 with RegistryFactory

use of com.weibo.api.motan.registry.RegistryFactory in project motan by weibocom.

the class SimpleConfigHandler method unRegister.

private void unRegister(Collection<URL> registryUrls, URL serviceUrl) {
    for (URL url : registryUrls) {
        // 不管check的设置如何,做完所有unregistry,做好清理工作
        try {
            RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension(url.getProtocol());
            Registry registry = registryFactory.getRegistry(url);
            registry.unregister(serviceUrl);
        } catch (Exception e) {
            LoggerUtil.warn(String.format("unregister url false:%s", url), e);
        }
    }
}
Also used : RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) Registry(com.weibo.api.motan.registry.Registry) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 2 with RegistryFactory

use of com.weibo.api.motan.registry.RegistryFactory in project motan by weibocom.

the class SimpleConfigHandler method unRegister.

private void unRegister(Collection<URL> registryUrls) {
    for (URL url : registryUrls) {
        // 不管check的设置如何,做完所有unregistry,做好清理工作
        try {
            String serviceStr = StringTools.urlDecode(url.getParameter(URLParamType.embed.getName()));
            URL serviceUrl = URL.valueOf(serviceStr);
            RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension(url.getProtocol());
            Registry registry = registryFactory.getRegistry(url);
            registry.unregister(serviceUrl);
        } catch (Exception e) {
            LoggerUtil.warn(String.format("unregister url false:%s", url), e);
        }
    }
}
Also used : RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) Registry(com.weibo.api.motan.registry.Registry) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 3 with RegistryFactory

use of com.weibo.api.motan.registry.RegistryFactory in project motan by weibocom.

the class MeshRegistry method initProxyRegistry.

protected void initProxyRegistry() {
    String proxyRegistryString = getUrl().getParameter(URLParamType.proxyRegistryUrlString.getName());
    if (StringUtils.isNotBlank(proxyRegistryString)) {
        List<URL> urls = UrlUtils.stringToURLs(proxyRegistryString);
        if (!CollectionUtil.isEmpty(urls)) {
            // 仅支持对单注册中心的代理。如果有多注册中心的强需求在考虑扩展
            URL proxyUrl = urls.get(0);
            RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension(proxyUrl.getProtocol(), false);
            if (registryFactory == null) {
                LoggerUtil.warn("mesh registry can not find proxy registry. proxy registry url:" + proxyUrl.toSimpleString());
                return;
            }
            Registry registry = registryFactory.getRegistry(proxyUrl);
            if (registry != null) {
                this.proxyRegistry = registry;
                canBackup = true;
                LoggerUtil.info("mesh registry add proxy registry. url:" + getUrl().toFullStr());
            }
        }
    }
}
Also used : RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) AbstractRegistry(com.weibo.api.motan.registry.support.AbstractRegistry) Registry(com.weibo.api.motan.registry.Registry) URL(com.weibo.api.motan.rpc.URL)

Example 4 with RegistryFactory

use of com.weibo.api.motan.registry.RegistryFactory in project motan by weibocom.

the class BaseTest method before.

@Before
public void before() {
    mockery = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    final Server mockServer = mockery.mock(Server.class);
    final Client mockClient = mockery.mock(Client.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockClient).open();
            will(returnValue(true));
            allowing(mockClient).close();
            will(returnValue(null));
            allowing(mockClient).isAvailable();
            will(returnValue(true));
            allowing(mockServer).open();
            will(returnValue(true));
            allowing(mockServer).close();
            will(returnValue(null));
            allowing(mockServer).isAvailable();
            will(returnValue(true));
        }
    });
    ExtensionLoader loader = ExtensionLoader.getExtensionLoader(EndpointFactory.class);
    endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint", false);
    if (endpointFactory == null) {
        loader.addExtensionClass(MockEndpointFactory.class);
        endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint");
    }
    loader = ExtensionLoader.getExtensionLoader(RegistryFactory.class);
    MockRegistryFactory registryFactory = (MockRegistryFactory) loader.getExtension("mockRegistry", false);
    if (registryFactory == null) {
        loader.addExtensionClass(MockRegistryFactory.class);
    }
    endpointFactory.setClient(mockClient);
    endpointFactory.setServer(mockServer);
    cp = new ClassPathXmlApplicationContext("classpath:schemaTestContext.xml");
}
Also used : Expectations(org.jmock.Expectations) RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Server(com.weibo.api.motan.transport.Server) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Client(com.weibo.api.motan.transport.Client) ExtensionLoader(com.weibo.api.motan.core.extension.ExtensionLoader) Before(org.junit.Before)

Example 5 with RegistryFactory

use of com.weibo.api.motan.registry.RegistryFactory in project motan by weibocom.

the class SimpleConfigHandler method register.

private void register(List<URL> registryUrls, URL serviceUrl) {
    for (URL url : registryUrls) {
        // 根据check参数的设置,register失败可能会抛异常,上层应该知晓
        RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension(url.getProtocol(), false);
        if (registryFactory == null) {
            throw new MotanFrameworkException(new MotanErrorMsg(500, MotanErrorMsgConstant.FRAMEWORK_REGISTER_ERROR_CODE, "register error! Could not find extension for registry protocol:" + url.getProtocol() + ", make sure registry module for " + url.getProtocol() + " is in classpath!"));
        }
        Registry registry = registryFactory.getRegistry(url);
        registry.register(serviceUrl);
    }
}
Also used : RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) MotanErrorMsg(com.weibo.api.motan.exception.MotanErrorMsg) Registry(com.weibo.api.motan.registry.Registry)

Aggregations

RegistryFactory (com.weibo.api.motan.registry.RegistryFactory)5 Registry (com.weibo.api.motan.registry.Registry)4 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 ExtensionLoader (com.weibo.api.motan.core.extension.ExtensionLoader)1 MotanErrorMsg (com.weibo.api.motan.exception.MotanErrorMsg)1 AbstractRegistry (com.weibo.api.motan.registry.support.AbstractRegistry)1 URL (com.weibo.api.motan.rpc.URL)1 Client (com.weibo.api.motan.transport.Client)1 Server (com.weibo.api.motan.transport.Server)1 Expectations (org.jmock.Expectations)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 Before (org.junit.Before)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1