Search in sources :

Example 1 with ClusterSupport

use of com.weibo.api.motan.cluster.support.ClusterSupport in project motan by weibocom.

the class RefererConfig method initRef.

@SuppressWarnings({ "unchecked", "rawtypes" })
public synchronized void initRef() {
    if (initialized.get()) {
        return;
    }
    try {
        interfaceClass = (Class) Class.forName(interfaceClass.getName(), true, Thread.currentThread().getContextClassLoader());
    } catch (ClassNotFoundException e) {
        throw new MotanFrameworkException("ReferereConfig initRef Error: Class not found " + interfaceClass.getName(), e, MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
    }
    if (CollectionUtil.isEmpty(protocols)) {
        throw new MotanFrameworkException(String.format("%s RefererConfig is malformed, for protocol not set correctly!", interfaceClass.getName()));
    }
    checkInterfaceAndMethods(interfaceClass, methods);
    clusterSupports = new ArrayList<ClusterSupport<T>>(protocols.size());
    List<Cluster<T>> clusters = new ArrayList<Cluster<T>>(protocols.size());
    String proxy = null;
    ConfigHandler configHandler = ExtensionLoader.getExtensionLoader(ConfigHandler.class).getExtension(MotanConstants.DEFAULT_VALUE);
    List<URL> registryUrls = loadRegistryUrls();
    String localIp = getLocalHostAddress(registryUrls);
    for (ProtocolConfig protocol : protocols) {
        Map<String, String> params = new HashMap<String, String>();
        params.put(URLParamType.nodeType.getName(), MotanConstants.NODE_TYPE_REFERER);
        params.put(URLParamType.version.getName(), URLParamType.version.getValue());
        params.put(URLParamType.refreshTimestamp.getName(), String.valueOf(System.currentTimeMillis()));
        collectConfigParams(params, protocol, basicReferer, extConfig, this);
        collectMethodConfigParams(params, this.getMethods());
        URL refUrl = new URL(protocol.getName(), localIp, MotanConstants.DEFAULT_INT_VALUE, interfaceClass.getName(), params);
        ClusterSupport<T> clusterSupport = createClusterSupport(refUrl, configHandler, registryUrls);
        clusterSupports.add(clusterSupport);
        clusters.add(clusterSupport.getCluster());
        proxy = (proxy == null) ? refUrl.getParameter(URLParamType.proxy.getName(), URLParamType.proxy.getValue()) : proxy;
    }
    ref = configHandler.refer(interfaceClass, clusters, proxy);
    initialized.set(true);
}
Also used : ClusterSupport(com.weibo.api.motan.cluster.support.ClusterSupport) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Cluster(com.weibo.api.motan.cluster.Cluster) URL(com.weibo.api.motan.rpc.URL) ConfigHandler(com.weibo.api.motan.config.handler.ConfigHandler)

Aggregations

Cluster (com.weibo.api.motan.cluster.Cluster)1 ClusterSupport (com.weibo.api.motan.cluster.support.ClusterSupport)1 ConfigHandler (com.weibo.api.motan.config.handler.ConfigHandler)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 URL (com.weibo.api.motan.rpc.URL)1