com.alipay.sofa.runtime.api.annotation.SofaService Java Examples

The following examples show how to use com.alipay.sofa.runtime.api.annotation.SofaService. 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: RestBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public RpcBinding convert(SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation,
                          BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new RestBindingParam();
    convertServiceAnnotation(bindingParam, sofaServiceAnnotation, sofaServiceBindingAnnotation,
        bindingConverterContext);
    return new RestBinding(bindingParam, bindingConverterContext.getApplicationContext(),
        bindingConverterContext.isInBinding());
}
 
Example #2
Source File: H2cBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public RpcBinding convert(SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation,
                          BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new H2cBindingParam();
    convertServiceAnnotation(bindingParam, sofaServiceAnnotation, sofaServiceBindingAnnotation,
        bindingConverterContext);
    return new H2cBinding(bindingParam, bindingConverterContext.getApplicationContext(),
        bindingConverterContext.isInBinding());
}
 
Example #3
Source File: DubboBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public RpcBinding convert(SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation,
                          BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new DubboBindingParam();
    convertServiceAnnotation(bindingParam, sofaServiceAnnotation, sofaServiceBindingAnnotation,
        bindingConverterContext);
    return new DubboBinding(bindingParam, bindingConverterContext.getApplicationContext(),
        bindingConverterContext.isInBinding());
}
 
Example #4
Source File: BoltBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public RpcBinding convert(SofaService sofaServiceAnnotation, SofaServiceBinding sofaServiceBindingAnnotation,
                          BindingConverterContext bindingConverterContext) {
    RpcBindingParam bindingParam = new BoltBindingParam();
    convertServiceAnnotation(bindingParam, sofaServiceAnnotation, sofaServiceBindingAnnotation,
        bindingConverterContext);
    return new BoltBinding(bindingParam, bindingConverterContext.getApplicationContext(),
        bindingConverterContext.isInBinding());
}
 
Example #5
Source File: ParameterAnnotationTest.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Bean
@SofaService(
        bindings = @SofaServiceBinding(
                filters = "parameterFilter",
                bindingType = "bolt",
                parameters = {
                        @SofaParameter(key = "static_key", value = "static_value"),
                        @SofaParameter(key = "${dynamic_key}", value = "${dynamic_value}") }))
public HelloSyncService helloSyncService() {
    return new HelloSyncServiceImpl();
}
 
Example #6
Source File: ServiceTest.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Bean
@SofaService(bindings = { @SofaServiceBinding(bindingType = "bolt") })
public SampleService sampleService() {
    return new SampleService() {
        @Override
        public String echoStr(String name) {
            return "sampleService";
        }
    };
}
 
Example #7
Source File: RpcBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 4 votes vote down vote up
/**
 * convert props to RpcBindingParam
 *
 * @param bindingParam
 * @param sofaServiceAnnotation
 * @param sofaServiceBindingAnnotation
 * @param bindingConverterContext
 */
protected void convertServiceAnnotation(RpcBindingParam bindingParam, SofaService sofaServiceAnnotation,
                                        SofaServiceBinding sofaServiceBindingAnnotation,
                                        BindingConverterContext bindingConverterContext) {
    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));
    }
}
 
Example #8
Source File: RpcBindingConverter.java    From sofa-rpc-boot-projects with Apache License 2.0 2 votes vote down vote up
/**
 * transfer sofa service annotation
 *
 * @param sofaServiceAnnotation
 * @param sofaServiceBindingAnnotation
 * @param bindingConverterContext
 * @return
 */
@Override
public abstract RpcBinding convert(SofaService sofaServiceAnnotation,
                                   SofaServiceBinding sofaServiceBindingAnnotation,
                                   BindingConverterContext bindingConverterContext);