Java Code Examples for com.alipay.sofa.rpc.common.utils.StringUtils#equals()

The following examples show how to use com.alipay.sofa.rpc.common.utils.StringUtils#equals() . 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: RegistryConfigContainer.java    From sofa-rpc-boot-projects with Apache License 2.0 6 votes vote down vote up
/**
 * protocol can be meshed
 *
 * @param protocol
 * @return
 */
public boolean isMeshEnabled(String protocol) {

    String meshConfig = sofaBootRpcProperties.getEnableMesh();
    final Map<String, String> registries = sofaBootRpcProperties.getRegistries();
    if (StringUtils.isNotBlank(meshConfig) && registries != null &&
        registries.get(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_MESH) != null) {
        if (meshConfig.equalsIgnoreCase(SofaBootRpcConfigConstants.ENABLE_MESH_ALL)) {
            return true;
        } else {
            List<String> meshEnableProtocols = Arrays.asList(meshConfig.split(","));
            for (String meshProtocol : meshEnableProtocols) {
                if (StringUtils.equals(meshProtocol, protocol)) {
                    return true;
                }
            }
            return false;
        }
    } else {
        return false;
    }

}
 
Example 2
Source File: ReporterFactory.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
public static Reporter build(String digestLog, String digestRollingPolicy,
                             String digestLogReserveConfig, SpanEncoder<SofaTracerSpan> spanEncoder,
                             SofaTracerStatisticReporter statReporter) {
    Reporter reporter = null;

    if (StringUtils.equals(REPORT_TYPE, "MEMORY")) {
        //构造实例
        reporter = new MemoryReporterImpl(digestLog, digestRollingPolicy,
            digestLogReserveConfig, spanEncoder, statReporter);
    } else {
        //构造实例
        reporter = new DiskReporterImpl(digestLog, digestRollingPolicy,
            digestLogReserveConfig, spanEncoder, statReporter);
    }
    return reporter;
}
 
Example 3
Source File: MeshApiClient.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
public boolean registeApplication(ApplicationInfoRequest applicationInfoRequest) {

        final String json = applicationInfoRequest.toJson();
        String result = httpPost(MeshEndpoint.CONFIGS, json);

        if (!StringUtils.equals(result, errorMessage)) {
            final ApplicationInfoResult parse = JSON.parseObject(result,
                ApplicationInfoResult.class);
            if (parse.isSuccess()) {
                return true;
            }
            return false;
        } else {
            return false;
        }

    }
 
Example 4
Source File: MeshApiClient.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
public int unPublishService(UnPublishServiceRequest request) {

        final String json = JSON.toJSONString(request);
        String result = httpPost(MeshEndpoint.UN_PUBLISH, json);

        if (!StringUtils.equals(result, errorMessage)) {
            final UnPublishServiceResult parse = JSON.parseObject(result,
                UnPublishServiceResult.class);
            if (parse.isSuccess()) {
                return 1;
            }
            return 0;
        } else {
            return 0;
        }

    }
 
Example 5
Source File: MeshApiClient.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
public boolean unSubscribeService(UnSubscribeServiceRequest request) {
    final String json = JSON.toJSONString(request);

    String result = httpPost(MeshEndpoint.UN_SUBCRIBE, json);

    if (!StringUtils.equals(result, errorMessage)) {
        final UnSubscribeServiceResult parse = JSON.parseObject(result,
            UnSubscribeServiceResult.class);
        if (parse.isSuccess()) {
            return true;
        }
        return false;
    } else {
        return false;
    }
}
 
Example 6
Source File: AbstractCluster.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 检测服务节点的一些信息
 *
 * @param providerGroup 服务列表分组
 */
protected void checkProviderInfo(ProviderGroup providerGroup) {
    List<ProviderInfo> providerInfos = providerGroup == null ? null : providerGroup.getProviderInfos();
    if (CommonUtils.isEmpty(providerInfos)) {
        return;
    }
    Iterator<ProviderInfo> iterator = providerInfos.iterator();
    while (iterator.hasNext()) {
        ProviderInfo providerInfo = iterator.next();
        if (!StringUtils.equals(providerInfo.getProtocolType(), consumerConfig.getProtocol())) {
            if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
                LOGGER.warnWithApp(consumerConfig.getAppName(),
                    "Unmatched protocol between consumer [{}] and provider [{}].",
                    consumerConfig.getProtocol(), providerInfo.getProtocolType());
            }
        }
    }
}
 
Example 7
Source File: AbstractCluster.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * Select provider.
 *
 * @param targetIP the target ip
 * @return the provider
 */
protected ProviderInfo selectPinpointProvider(String targetIP, List<ProviderInfo> providerInfos) {
    ProviderInfo tp = convertToProviderInfo(targetIP);
    // 存在注册中心provider才会遍历
    if (CommonUtils.isNotEmpty(providerInfos)) {
        for (ProviderInfo providerInfo : providerInfos) {
            if (providerInfo.getHost().equals(tp.getHost())
                && StringUtils.equals(providerInfo.getProtocolType(), tp.getProtocolType())
                && providerInfo.getPort() == tp.getPort()) {
                return providerInfo;
            }
        }
    }
    // support direct target url
    return tp;
}
 
Example 8
Source File: ConsumerConfig.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public String getInterfaceId() {
    if (StringUtils.equals(RpcConstants.PROTOCOL_TYPE_TRIPLE, this.getProtocol())) {
        Class enclosingClass = this.getProxyClass().getEnclosingClass();
        Method sofaStub = null;
        String serviceName = interfaceId;
        try {
            sofaStub = enclosingClass.getDeclaredMethod("getServiceName");
            serviceName = (String) sofaStub.invoke(null);
        } catch (Throwable e) {
            //ignore
        }
        return serviceName;
    } else {
        return interfaceId;
    }
}
 
Example 9
Source File: SofaRegistrySubscribeCallback.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * merge url
 *
 * @param userDatas
 * @param configDatas
 * @return
 */
List<ProviderInfo> mergeProviderInfo(List<String> userDatas, List<String> configDatas) {
    // 是否自己缓存运算后的结果?? TODO
    List<ProviderInfo> providers = SofaRegistryHelper.parseProviderInfos(userDatas);
    // 交叉比较
    if (CommonUtils.isNotEmpty(providers) && CommonUtils.isNotEmpty(configDatas)) {
        List<ProviderInfo> override = SofaRegistryHelper.parseProviderInfos(configDatas);
        Iterator<ProviderInfo> iterator = providers.iterator();
        while (iterator.hasNext()) {
            ProviderInfo origin = iterator.next();
            for (ProviderInfo over : override) {
                if (PROTOCOL_TYPE_OVERRIDE.equals(over.getProtocolType()) &&
                    StringUtils.equals(origin.getHost(), over.getHost()) && origin.getPort() == over.getPort()) {
                    // host 和 port 相同 认为是一个地址
                    if (over.getWeight() != origin.getWeight()) {
                        origin.setWeight(over.getWeight());
                    }
                    if (CommonUtils.isTrue(over.getAttr(ProviderInfoAttrs.ATTR_DISABLED))) {
                        if (LOGGER.isInfoEnabled()) {
                            LOGGER.info("Provider is disabled by override. {}", origin.toUrl());
                        }
                        iterator.remove(); // 禁用 删掉
                    }
                }
            }
        }
    }
    return providers;
}
 
Example 10
Source File: MeshApiClient.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public boolean publishService(PublishServiceRequest publishServiceRequest) {

        final String json = JSON.toJSONString(publishServiceRequest);
        String result = httpPost(MeshEndpoint.PUBLISH, json);
        if (!StringUtils.equals(result, errorMessage)) {
            final PublishServiceResult parse = JSON.parseObject(result, PublishServiceResult.class);
            if (parse.isSuccess()) {
                return true;
            }
            return false;
        } else {
            return false;
        }
    }
 
Example 11
Source File: MeshApiClient.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public SubscribeServiceResult subscribeService(SubscribeServiceRequest subscribeServiceRequest) {
    final String json = JSON.toJSONString(subscribeServiceRequest);

    String result = httpPost(MeshEndpoint.SUBCRIBE, json);

    SubscribeServiceResult subscribeServiceResult;
    if (!StringUtils.equals(result, errorMessage)) {
        subscribeServiceResult = JSON.parseObject(result, SubscribeServiceResult.class);
        return subscribeServiceResult;
    } else {
        subscribeServiceResult = new SubscribeServiceResult();
        return subscribeServiceResult;
    }
}
 
Example 12
Source File: AbstractInterfaceConfig.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public S setMockMode(String mockMode) {
    this.mockMode = mockMode;
    if (StringUtils.equals(mockMode, MockMode.LOCAL) ||
        StringUtils.equals(mockMode, MockMode.REMOTE)) {
        this.setMock(true);
    }
    return castThis();
}
 
Example 13
Source File: RegistryUtils.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public static List<ProviderInfo> matchProviderInfos(ConsumerConfig consumerConfig, List<ProviderInfo> providerInfos) {
    String protocol = consumerConfig.getProtocol();
    List<ProviderInfo> result = new ArrayList<ProviderInfo>();
    for (ProviderInfo providerInfo : providerInfos) {
        if (providerInfo.getProtocolType().equalsIgnoreCase(protocol)
            && StringUtils.equals(consumerConfig.getUniqueId(),
                providerInfo.getAttr(ProviderInfoAttrs.ATTR_UNIQUEID))) {
            result.add(providerInfo);
        }
    }
    return result;
}
 
Example 14
Source File: DynamicHelper.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public static boolean isNotDefault(String value) {

        if (StringUtils.equals(value, DEFAULT_DYNAMIC_VALUE)) {
            return false;
        } else {
            return true;
        }

    }
 
Example 15
Source File: DefaultProviderBootstrap.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 否则存在method configs 字符串中
 *
 * @param methodConfigs
 * @param methodName
 * @return
 */
private boolean inMethodConfigs(String methodConfigs, String methodName) {
    String[] excludeMethodCollections = StringUtils.splitWithCommaOrSemicolon(methodConfigs);
    for (String excludeMethodName : excludeMethodCollections) {
        boolean exist = StringUtils.equals(excludeMethodName, methodName);
        if (exist) {
            return true;
        }
    }
    return false;
}
 
Example 16
Source File: LocalRegistryHelper.java    From sofa-rpc with Apache License 2.0 2 votes vote down vote up
/**
 * Check file's digest.
 *
 * @param address    the address
 * @param lastDigest the update digest
 * @return true被修改,false未被修改
 */
public static boolean checkModified(String address, String lastDigest) {
    // 检查文件是否被修改了
    String newDigest = calMD5Checksum(address);
    return !StringUtils.equals(newDigest, lastDigest);
}