Search in sources :

Example 1 with Registry

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

the class ClusterSupport method destroy.

public void destroy() {
    URL subscribeUrl = toSubscribeUrl(url);
    for (URL ru : registryUrls) {
        try {
            Registry registry = getRegistry(ru);
            registry.unsubscribe(subscribeUrl, this);
            if (!MotanConstants.NODE_TYPE_REFERER.equals(url.getParameter(URLParamType.nodeType.getName()))) {
                registry.unregister(url);
            }
        } catch (Exception e) {
            LoggerUtil.warn(String.format("Unregister or unsubscribe false for url (%s), registry= %s", url, ru.getIdentity()), e);
        }
    }
    try {
        getCluster().destroy();
    } catch (Exception e) {
        LoggerUtil.warn(String.format("Exception when destroy cluster: %s", getCluster().getUrl()));
    }
}
Also used : Registry(com.weibo.api.motan.registry.Registry) URL(com.weibo.api.motan.rpc.URL) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 2 with Registry

use of com.weibo.api.motan.registry.Registry 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());
        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)

Example 3 with Registry

use of com.weibo.api.motan.registry.Registry 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 4 with Registry

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

the class AbstractRegistryFactory method getRegistry.

@Override
public Registry getRegistry(URL url) {
    String registryUri = getRegistryUri(url);
    try {
        lock.lock();
        Registry registry = registries.get(registryUri);
        if (registry != null) {
            return registry;
        }
        registry = createRegistry(url);
        if (registry == null) {
            throw new MotanFrameworkException("Create registry false for url:" + url, MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
        }
        registries.put(registryUri, registry);
        return registry;
    } catch (Exception e) {
        throw new MotanFrameworkException("Create registry false for url:" + url, e, MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
    } finally {
        lock.unlock();
    }
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Registry(com.weibo.api.motan.registry.Registry) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 5 with Registry

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

the class ClusterSupport method init.

public void init() {
    prepareCluster();
    URL subUrl = toSubscribeUrl(url);
    for (URL ru : registryUrls) {
        String directUrlStr = ru.getParameter(URLParamType.directUrl.getName());
        // 如果有directUrl,直接使用这些directUrls进行初始化,不用到注册中心discover
        if (StringUtils.isNotBlank(directUrlStr)) {
            List<URL> directUrls = parseDirectUrls(directUrlStr);
            if (!directUrls.isEmpty()) {
                notify(ru, directUrls);
                LoggerUtil.info("Use direct urls, refUrl={}, directUrls={}", url, directUrls);
                continue;
            }
        }
        // client 注册自己,同时订阅service列表
        Registry registry = getRegistry(ru);
        registry.subscribe(subUrl, this);
    }
    boolean check = Boolean.parseBoolean(url.getParameter(URLParamType.check.getName(), URLParamType.check.getValue()));
    if (!CollectionUtil.isEmpty(cluster.getReferers()) || !check) {
        cluster.init();
        if (CollectionUtil.isEmpty(cluster.getReferers()) && !check) {
            LoggerUtil.warn(String.format("refer:%s", this.url.getPath() + "/" + this.url.getVersion()), "No services");
        }
        return;
    }
    throw new MotanFrameworkException(String.format("ClusterSupport No service urls for the refer:%s, registries:%s", this.url.getIdentity(), registryUrls), MotanErrorMsgConstant.SERVICE_UNFOUND);
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Registry(com.weibo.api.motan.registry.Registry) URL(com.weibo.api.motan.rpc.URL)

Aggregations

MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)5 Registry (com.weibo.api.motan.registry.Registry)5 RegistryFactory (com.weibo.api.motan.registry.RegistryFactory)2 URL (com.weibo.api.motan.rpc.URL)2 MotanErrorMsg (com.weibo.api.motan.exception.MotanErrorMsg)1