Java Code Examples for com.alipay.sofa.rpc.config.ConsumerConfig#getAppName()

The following examples show how to use com.alipay.sofa.rpc.config.ConsumerConfig#getAppName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsulRegistry.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public void unSubscribe(ConsumerConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isSubscribe()) {
        // 注册中心不订阅
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(config.getAppName(), LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
    }

    if (!config.isSubscribe()) {
        return;
    }
    String uniqueName = buildUniqueName(config, config.getProtocol());
    HealthServiceInformer informer = healthServiceInformers.get(uniqueName);
    if (informer == null) {
        return;
    }
    informer.removeListener(config.getProviderInfoListener());
    if (informer.getListenerSize() == 0) {
        healthServiceInformers.remove(uniqueName);
        informer.shutdown();
    }
}
 
Example 2
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public void unSubscribe(ConsumerConfig config) {
    String serviceName = SofaRegistryHelper.buildListDataId(config, config.getProtocol());
    String appName = config.getAppName();
    Subscriber subscriber = subscribers.get(serviceName);
    if (subscriber != null) {
        SofaRegistrySubscribeCallback callback = (SofaRegistrySubscribeCallback) subscriber.getDataObserver();
        callback.remove(serviceName, config);
        if (callback.getListenerNum() == 0) {
            // 已经没人订阅这个data Key了
            SofaRegistryClient.getRegistryClient(appName, registryConfig).unregister(serviceName,
                subscriber.getGroup(),
                RegistryType.SUBSCRIBER);
            subscribers.remove(serviceName);

            // 已经没人订阅这个config Key了
            SofaRegistryClient.getRegistryClient(appName, registryConfig).unregister(serviceName,
                subscriber.getGroup(),
                RegistryType.CONFIGURATOR);
            configurators.remove(serviceName);
        }
    }
}
 
Example 3
Source File: MulticastRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnSubscribe(List<ConsumerConfig> configs) {
    for (ConsumerConfig config : configs) {
        String appName = config.getAppName();
        try {
            unSubscribe(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unSubscribe", e);
        }
    }
}
 
Example 4
Source File: LocalRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnSubscribe(List<ConsumerConfig> configs) {
    // 不支持批量反注册,那就一个个来吧
    for (ConsumerConfig config : configs) {
        String appName = config.getAppName();
        try {
            unSubscribe(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unSubscribe", e);
        }
    }
}
 
Example 5
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnSubscribe(List<ConsumerConfig> configs) {
    // 不支持批量反注册,那就一个个来吧
    for (ConsumerConfig config : configs) {
        String appName = config.getAppName();
        try {
            unSubscribe(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unSubscribe", e);
        }
    }
}
 
Example 6
Source File: MeshRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnSubscribe(List<ConsumerConfig> configs) {
    // 不支持批量反注册,那就一个个来吧
    for (ConsumerConfig config : configs) {
        String appName = config.getAppName();
        try {
            unSubscribe(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unSubscribe", e);
        }
    }
}
 
Example 7
Source File: InvocationStatFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 得到调用统计器
 *
 * @param consumerConfig 接口信息
 * @param providerInfo   请求信息
 * @return 调用统计器,如果不符合统计条件则返回空
 */
public static InvocationStat getInvocationStat(ConsumerConfig consumerConfig, ProviderInfo providerInfo) {
    String appName = consumerConfig.getAppName();
    if (appName == null) {
        return null;
    }
    // 应用开启单机故障摘除功能
    if (FaultToleranceConfigManager.isRegulationEffective(appName)) {
        return getInvocationStat(new InvocationStatDimension(providerInfo, consumerConfig));
    }
    return null;
}
 
Example 8
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Override
public List<ProviderGroup> subscribe(ConsumerConfig config) {
    ProviderInfoListener providerInfoListener = config.getProviderInfoListener();
    String appName = config.getAppName();
    if (!registryConfig.isSubscribe()) {
        // 注册中心不订阅
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return null;
    }
    if (!config.isSubscribe()) {
        // 服务不订阅
        return null;
    }

    String serviceName = SofaRegistryHelper.buildListDataId(config, config.getProtocol());

    SofaRegistrySubscribeCallback callback;

    Subscriber listSubscriber = subscribers.get(serviceName);
    Configurator attrSubscriber;
    if (listSubscriber != null && providerInfoListener != null) {
        // 已经有人订阅过这个Key,那么地址已经存在了,
        callback = (SofaRegistrySubscribeCallback) listSubscriber.getDataObserver();
        callback.addProviderInfoListener(serviceName, config, providerInfoListener);
        // 使用旧数据通知下
        callback.handleDataToListener(serviceName, config, providerInfoListener);
    } else {

        callback = new SofaRegistrySubscribeCallback();

        callback.addProviderInfoListener(serviceName, config, providerInfoListener);

        // 生成订阅对象,并添加额外属性
        SubscriberRegistration subscriberRegistration = new SubscriberRegistration(serviceName, callback);
        String groupId = config.getParameter(SofaRegistryConstants.SOFA_GROUP_KEY);
        groupId = groupId == null ? SofaRegistryHelper.SUBSCRIBER_LIST_GROUP_ID : groupId;
        addAttributes(subscriberRegistration, groupId);

        ConfiguratorRegistration configRegistration = new ConfiguratorRegistration(serviceName, callback);
        addAttributes(configRegistration, SofaRegistryHelper.SUBSCRIBER_CONFIG_GROUP_ID);

        // 去配置中心订阅

        // 去注册
        listSubscriber = SofaRegistryClient.getRegistryClient(appName, registryConfig).register(
            subscriberRegistration);

        attrSubscriber = SofaRegistryClient.getRegistryClient(appName, registryConfig).register(configRegistration);

        // 放入缓存
        subscribers.put(serviceName, listSubscriber);
        configurators.put(serviceName, attrSubscriber);
    }
    // 统一走异步获取地址,所以此处返回null
    return null;
}