Search in sources :

Example 1 with SofaParameter

use of com.alipay.sofa.runtime.api.annotation.SofaParameter in project sofa-boot by sofastack.

the class RpcBindingConverter method convertReferenceAnnotation.

/**
 * convert props to RpcBindingParam
 *
 * @param bindingParam
 * @param sofaReferenceBindingAnnotation
 * @param bindingConverterContext
 */
protected void convertReferenceAnnotation(RpcBindingParam bindingParam, SofaReferenceBinding sofaReferenceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    if (sofaReferenceBindingAnnotation.addressWaitTime() != 0) {
        bindingParam.setAddressWaitTime(sofaReferenceBindingAnnotation.addressWaitTime());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.directUrl())) {
        bindingParam.setTargetUrl(sofaReferenceBindingAnnotation.directUrl());
    }
    if (sofaReferenceBindingAnnotation.timeout() != 0) {
        bindingParam.setTimeout(sofaReferenceBindingAnnotation.timeout());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.serializeType())) {
        bindingParam.setSerialization(sofaReferenceBindingAnnotation.serializeType());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.loadBalancer())) {
        bindingParam.setLoadBalancer(sofaReferenceBindingAnnotation.loadBalancer());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.mockMode())) {
        bindingParam.setMockMode(sofaReferenceBindingAnnotation.mockMode());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.mockBean())) {
        bindingParam.setMockBean(sofaReferenceBindingAnnotation.mockBean());
    }
    bindingParam.setType(sofaReferenceBindingAnnotation.invokeType());
    ApplicationContext applicationContext = bindingConverterContext.getApplicationContext();
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(applicationContext));
    String[] filterNames = sofaReferenceBindingAnnotation.filters();
    if (filterNames.length > 0) {
        for (String filterName : filterNames) {
            Object filter = applicationContext.getBean(filterName);
            if (filter instanceof Filter) {
                filters.add((Filter) filter);
            } else {
                throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
            }
        }
    }
    if (!CollectionUtils.isEmpty(filters)) {
        bindingParam.setFilters(filters);
    }
    bindingParam.setRetries(sofaReferenceBindingAnnotation.retries());
    String callbackRef = sofaReferenceBindingAnnotation.callbackHandler();
    if (StringUtils.hasText(callbackRef)) {
        bindingParam.setCallbackHandler(applicationContext.getBean(callbackRef));
    }
    bindingParam.setLazy(sofaReferenceBindingAnnotation.lazy());
    String registryAlias = sofaReferenceBindingAnnotation.registry();
    if (StringUtils.hasText(registryAlias)) {
        String[] registrys = registryAlias.split(",");
        bindingParam.setRegistrys(Arrays.asList(registrys));
    }
    SofaParameter[] parameters = sofaReferenceBindingAnnotation.parameters();
    if (parameters.length > 0) {
        bindingParam.setParameters(parseSofaParameters(parameters));
    }
    SofaMethod[] sofaMethods = sofaReferenceBindingAnnotation.methodInfos();
    if (sofaMethods.length > 0) {
        bindingParam.setMethodInfos(parseSofaMethods(sofaMethods));
    }
}
Also used : SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ApplicationContext(org.springframework.context.ApplicationContext) SofaMethod(com.alipay.sofa.runtime.api.annotation.SofaMethod) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) SofaParameter(com.alipay.sofa.runtime.api.annotation.SofaParameter) ArrayList(java.util.ArrayList)

Example 2 with SofaParameter

use of com.alipay.sofa.runtime.api.annotation.SofaParameter in project sofa-boot by alipay.

the class RpcBindingConverter method convertReferenceAnnotation.

/**
 * convert props to RpcBindingParam
 *
 * @param bindingParam
 * @param sofaReferenceBindingAnnotation
 * @param bindingConverterContext
 */
protected void convertReferenceAnnotation(RpcBindingParam bindingParam, SofaReferenceBinding sofaReferenceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    if (sofaReferenceBindingAnnotation.addressWaitTime() != 0) {
        bindingParam.setAddressWaitTime(sofaReferenceBindingAnnotation.addressWaitTime());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.directUrl())) {
        bindingParam.setTargetUrl(sofaReferenceBindingAnnotation.directUrl());
    }
    if (sofaReferenceBindingAnnotation.timeout() != 0) {
        bindingParam.setTimeout(sofaReferenceBindingAnnotation.timeout());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.serializeType())) {
        bindingParam.setSerialization(sofaReferenceBindingAnnotation.serializeType());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.loadBalancer())) {
        bindingParam.setLoadBalancer(sofaReferenceBindingAnnotation.loadBalancer());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.mockMode())) {
        bindingParam.setMockMode(sofaReferenceBindingAnnotation.mockMode());
    }
    if (StringUtils.hasText(sofaReferenceBindingAnnotation.mockBean())) {
        bindingParam.setMockBean(sofaReferenceBindingAnnotation.mockBean());
    }
    bindingParam.setType(sofaReferenceBindingAnnotation.invokeType());
    ApplicationContext applicationContext = bindingConverterContext.getApplicationContext();
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(applicationContext));
    String[] filterNames = sofaReferenceBindingAnnotation.filters();
    if (filterNames.length > 0) {
        for (String filterName : filterNames) {
            Object filter = applicationContext.getBean(filterName);
            if (filter instanceof Filter) {
                filters.add((Filter) filter);
            } else {
                throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
            }
        }
    }
    if (!CollectionUtils.isEmpty(filters)) {
        bindingParam.setFilters(filters);
    }
    bindingParam.setRetries(sofaReferenceBindingAnnotation.retries());
    String callbackRef = sofaReferenceBindingAnnotation.callbackHandler();
    if (StringUtils.hasText(callbackRef)) {
        bindingParam.setCallbackHandler(applicationContext.getBean(callbackRef));
    }
    bindingParam.setLazy(sofaReferenceBindingAnnotation.lazy());
    String registryAlias = sofaReferenceBindingAnnotation.registry();
    if (StringUtils.hasText(registryAlias)) {
        String[] registrys = registryAlias.split(",");
        bindingParam.setRegistrys(Arrays.asList(registrys));
    }
    SofaParameter[] parameters = sofaReferenceBindingAnnotation.parameters();
    if (parameters.length > 0) {
        bindingParam.setParameters(parseSofaParameters(parameters));
    }
    SofaMethod[] sofaMethods = sofaReferenceBindingAnnotation.methodInfos();
    if (sofaMethods.length > 0) {
        bindingParam.setMethodInfos(parseSofaMethods(sofaMethods));
    }
}
Also used : SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ApplicationContext(org.springframework.context.ApplicationContext) SofaMethod(com.alipay.sofa.runtime.api.annotation.SofaMethod) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) SofaParameter(com.alipay.sofa.runtime.api.annotation.SofaParameter) ArrayList(java.util.ArrayList)

Example 3 with SofaParameter

use of com.alipay.sofa.runtime.api.annotation.SofaParameter in project sofa-boot by alipay.

the class RpcBindingConverter method convertServiceAnnotation.

/**
 * convert props to RpcBindingParam
 *
 * @param bindingParam
 * @param sofaServiceAnnotation
 * @param sofaServiceBindingAnnotation
 * @param bindingConverterContext
 */
protected void convertServiceAnnotation(RpcBindingParam bindingParam, SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    if (sofaServiceBindingAnnotation.timeout() != 0) {
        bindingParam.setTimeout(sofaServiceBindingAnnotation.timeout());
    }
    // TODO need a magic number
    if (sofaServiceBindingAnnotation.weight() != 0) {
        bindingParam.setWeight(sofaServiceBindingAnnotation.weight());
    }
    if (sofaServiceBindingAnnotation.warmUpTime() != 0) {
        bindingParam.setWarmUpTime(sofaServiceBindingAnnotation.warmUpTime());
    }
    if (sofaServiceBindingAnnotation.warmUpWeight() != 0) {
        bindingParam.setWarmUpWeight(sofaServiceBindingAnnotation.warmUpWeight());
    }
    if (StringUtils.hasText(sofaServiceBindingAnnotation.serializeType())) {
        bindingParam.setSerialization(sofaServiceBindingAnnotation.serializeType());
    }
    ApplicationContext applicationContext = bindingConverterContext.getApplicationContext();
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(applicationContext));
    String[] filterNames = sofaServiceBindingAnnotation.filters();
    if (filterNames.length > 0) {
        for (String filterName : filterNames) {
            Object filter = applicationContext.getBean(filterName);
            if (filter instanceof Filter) {
                filters.add((Filter) filter);
            } else {
                throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
            }
        }
    }
    if (!CollectionUtils.isEmpty(filters)) {
        bindingParam.setFilters(filters);
    }
    String threadPool = sofaServiceBindingAnnotation.userThreadPool();
    if (StringUtils.hasText(threadPool)) {
        UserThreadPool threadPoolObj = (UserThreadPool) applicationContext.getBean(threadPool);
        String interfaceName = sofaServiceAnnotation.interfaceType().getCanonicalName();
        String uniqId = sofaServiceAnnotation.uniqueId();
        String uniqueName = interfaceName + ":1.0" + (StringUtils.isEmpty(uniqId) ? "" : ":" + uniqId);
        UserThreadPoolManager.registerUserThread(uniqueName, threadPoolObj);
    }
    String registryAlias = sofaServiceBindingAnnotation.registry();
    if (StringUtils.hasText(registryAlias)) {
        String[] registrys = registryAlias.split(",");
        bindingParam.setRegistrys(Arrays.asList(registrys));
    }
    SofaParameter[] parameters = sofaServiceBindingAnnotation.parameters();
    if (parameters.length > 0) {
        bindingParam.setParameters(parseSofaParameters(parameters));
    }
    SofaMethod[] sofaMethods = sofaServiceBindingAnnotation.methodInfos();
    if (sofaMethods.length > 0) {
        bindingParam.setMethodInfos(parseSofaMethods(sofaMethods));
    }
}
Also used : SofaMethod(com.alipay.sofa.runtime.api.annotation.SofaMethod) ArrayList(java.util.ArrayList) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ApplicationContext(org.springframework.context.ApplicationContext) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) SofaParameter(com.alipay.sofa.runtime.api.annotation.SofaParameter)

Example 4 with SofaParameter

use of com.alipay.sofa.runtime.api.annotation.SofaParameter in project sofa-boot by sofastack.

the class RpcBindingConverter method convertServiceAnnotation.

/**
 * convert props to RpcBindingParam
 *
 * @param bindingParam
 * @param sofaServiceAnnotation
 * @param sofaServiceBindingAnnotation
 * @param bindingConverterContext
 */
protected void convertServiceAnnotation(RpcBindingParam bindingParam, SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation, BindingConverterContext bindingConverterContext) {
    if (sofaServiceBindingAnnotation.timeout() != 0) {
        bindingParam.setTimeout(sofaServiceBindingAnnotation.timeout());
    }
    // TODO need a magic number
    if (sofaServiceBindingAnnotation.weight() != 0) {
        bindingParam.setWeight(sofaServiceBindingAnnotation.weight());
    }
    if (sofaServiceBindingAnnotation.warmUpTime() != 0) {
        bindingParam.setWarmUpTime(sofaServiceBindingAnnotation.warmUpTime());
    }
    if (sofaServiceBindingAnnotation.warmUpWeight() != 0) {
        bindingParam.setWarmUpWeight(sofaServiceBindingAnnotation.warmUpWeight());
    }
    if (StringUtils.hasText(sofaServiceBindingAnnotation.serializeType())) {
        bindingParam.setSerialization(sofaServiceBindingAnnotation.serializeType());
    }
    ApplicationContext applicationContext = bindingConverterContext.getApplicationContext();
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(applicationContext));
    String[] filterNames = sofaServiceBindingAnnotation.filters();
    if (filterNames.length > 0) {
        for (String filterName : filterNames) {
            Object filter = applicationContext.getBean(filterName);
            if (filter instanceof Filter) {
                filters.add((Filter) filter);
            } else {
                throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
            }
        }
    }
    if (!CollectionUtils.isEmpty(filters)) {
        bindingParam.setFilters(filters);
    }
    String threadPool = sofaServiceBindingAnnotation.userThreadPool();
    if (StringUtils.hasText(threadPool)) {
        UserThreadPool threadPoolObj = (UserThreadPool) applicationContext.getBean(threadPool);
        String interfaceName = sofaServiceAnnotation.interfaceType().getCanonicalName();
        String uniqId = sofaServiceAnnotation.uniqueId();
        String uniqueName = interfaceName + ":1.0" + (StringUtils.isEmpty(uniqId) ? "" : ":" + uniqId);
        UserThreadPoolManager.registerUserThread(uniqueName, threadPoolObj);
    }
    String registryAlias = sofaServiceBindingAnnotation.registry();
    if (StringUtils.hasText(registryAlias)) {
        String[] registrys = registryAlias.split(",");
        bindingParam.setRegistrys(Arrays.asList(registrys));
    }
    SofaParameter[] parameters = sofaServiceBindingAnnotation.parameters();
    if (parameters.length > 0) {
        bindingParam.setParameters(parseSofaParameters(parameters));
    }
    SofaMethod[] sofaMethods = sofaServiceBindingAnnotation.methodInfos();
    if (sofaMethods.length > 0) {
        bindingParam.setMethodInfos(parseSofaMethods(sofaMethods));
    }
}
Also used : SofaMethod(com.alipay.sofa.runtime.api.annotation.SofaMethod) ArrayList(java.util.ArrayList) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ApplicationContext(org.springframework.context.ApplicationContext) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) SofaParameter(com.alipay.sofa.runtime.api.annotation.SofaParameter)

Aggregations

SofaBootRpcRuntimeException (com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException)4 ExcludeFilter (com.alipay.sofa.rpc.filter.ExcludeFilter)4 Filter (com.alipay.sofa.rpc.filter.Filter)4 SofaMethod (com.alipay.sofa.runtime.api.annotation.SofaMethod)4 SofaParameter (com.alipay.sofa.runtime.api.annotation.SofaParameter)4 ArrayList (java.util.ArrayList)4 ApplicationContext (org.springframework.context.ApplicationContext)4 UserThreadPool (com.alipay.sofa.rpc.server.UserThreadPool)2