Search in sources :

Example 6 with RpcBindingMethodInfo

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.

the class RpcBindingConverter method parseSofaMethods.

public List<RpcBindingMethodInfo> parseSofaMethods(SofaMethod[] sofaMethods) {
    List<RpcBindingMethodInfo> rpcBindingMethodInfos = new ArrayList<RpcBindingMethodInfo>();
    for (SofaMethod sofaMethod : sofaMethods) {
        RpcBindingMethodInfo rpcBindingMethodInfo = new RpcBindingMethodInfo();
        rpcBindingMethodInfo.setName(sofaMethod.name());
        rpcBindingMethodInfo.setType(sofaMethod.invokeType());
        rpcBindingMethodInfo.setTimeout(sofaMethod.timeout());
        rpcBindingMethodInfo.setRetries(sofaMethod.retries());
        rpcBindingMethodInfo.setCallbackClass(sofaMethod.callbackClass());
        rpcBindingMethodInfo.setCallbackRef(sofaMethod.callbackRef());
        rpcBindingMethodInfos.add(rpcBindingMethodInfo);
    }
    return rpcBindingMethodInfos;
}
Also used : SofaMethod(com.alipay.sofa.runtime.api.annotation.SofaMethod) ArrayList(java.util.ArrayList) RpcBindingMethodInfo(com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo)

Example 7 with RpcBindingMethodInfo

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.

the class RpcBindingConverterTest method parseSofaMethods.

@Test
public void parseSofaMethods() {
    RpcBindingConverter rpcBindingConverter = new BoltBindingConverter();
    SofaReference reference = null;
    try {
        reference = RpcBindingConverterTest.class.getDeclaredField("testAnnotation").getAnnotation(SofaReference.class);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    List<RpcBindingMethodInfo> result = rpcBindingConverter.parseSofaMethods(reference.binding().methodInfos());
    Assert.assertEquals(1, result.size());
    final RpcBindingMethodInfo rpcBindingMethodInfo = result.get(0);
    Assert.assertEquals("test", rpcBindingMethodInfo.getName());
    Assert.assertEquals(1, rpcBindingMethodInfo.getRetries().intValue());
    Assert.assertEquals("callback", rpcBindingMethodInfo.getType());
    Assert.assertEquals("class", rpcBindingMethodInfo.getCallbackClass());
    Assert.assertEquals("ref", rpcBindingMethodInfo.getCallbackRef());
    Assert.assertEquals(2000, rpcBindingMethodInfo.getTimeout().intValue());
}
Also used : RpcBindingConverter(com.alipay.sofa.rpc.boot.runtime.converter.RpcBindingConverter) SofaReference(com.alipay.sofa.runtime.api.annotation.SofaReference) BoltBindingConverter(com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter) RpcBindingMethodInfo(com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo) Test(org.junit.Test)

Example 8 with RpcBindingMethodInfo

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.

the class ProviderConfigHelper method convertToMethodConfig.

private List<MethodConfig> convertToMethodConfig(List<RpcBindingMethodInfo> methodInfos) {
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    if (!CollectionUtils.isEmpty(methodInfos)) {
        for (RpcBindingMethodInfo info : methodInfos) {
            String name = info.getName();
            Integer timeout = info.getTimeout();
            MethodConfig methodConfig = new MethodConfig();
            methodConfig.setName(name);
            if (timeout != null) {
                methodConfig.setTimeout(timeout);
            }
            methodConfigs.add(methodConfig);
        }
    }
    return methodConfigs;
}
Also used : MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ArrayList(java.util.ArrayList) RpcBindingMethodInfo(com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo)

Example 9 with RpcBindingMethodInfo

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.

the class RpcBindingConverter method parseMethod.

protected void parseMethod(List<Element> elements, RpcBindingParam param) {
    if (CollectionUtils.isEmpty(elements)) {
        return;
    }
    List<RpcBindingMethodInfo> boltBindingMethodInfos = new ArrayList<RpcBindingMethodInfo>();
    for (Element element : elements) {
        if (element.getNodeType() == Node.ELEMENT_NODE && element.getLocalName().equals(RpcBindingXmlConstants.TAG_METHOD)) {
            String name = element.getAttribute(RpcBindingXmlConstants.TAG_NAME);
            Integer timeout = SofaBootRpcParserUtil.parseInteger(element.getAttribute(RpcBindingXmlConstants.TAG_TIMEOUT));
            Integer retries = SofaBootRpcParserUtil.parseInteger(element.getAttribute(RpcBindingXmlConstants.TAG_RETRIES));
            String type = element.getAttribute(RpcBindingXmlConstants.TAG_TYPE);
            RpcBindingMethodInfo boltBindingMethodInfo = new RpcBindingMethodInfo();
            if (StringUtils.hasText(name)) {
                boltBindingMethodInfo.setName(name);
            }
            if (timeout != null) {
                boltBindingMethodInfo.setTimeout(timeout);
            }
            if (retries != null) {
                boltBindingMethodInfo.setRetries(retries);
            }
            if (StringUtils.hasText(type)) {
                boltBindingMethodInfo.setType(type);
            }
            if (type.equalsIgnoreCase(RpcBindingXmlConstants.TYPE_CALLBACK)) {
                String callbackRef = element.getAttribute(RpcBindingXmlConstants.TAG_CALLBACK_REF);
                String callbackClass = element.getAttribute(RpcBindingXmlConstants.TAG_CALLBACK_CLASS);
                boltBindingMethodInfo.setCallbackRef(callbackRef);
                boltBindingMethodInfo.setCallbackClass(callbackClass);
            }
            boltBindingMethodInfos.add(boltBindingMethodInfo);
        }
    }
    param.setMethodInfos(boltBindingMethodInfos);
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) RpcBindingMethodInfo(com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo)

Example 10 with RpcBindingMethodInfo

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by sofastack.

the class ProviderConfigHelper method convertToMethodConfig.

private List<MethodConfig> convertToMethodConfig(List<RpcBindingMethodInfo> methodInfos) {
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    if (!CollectionUtils.isEmpty(methodInfos)) {
        for (RpcBindingMethodInfo info : methodInfos) {
            String name = info.getName();
            Integer timeout = info.getTimeout();
            MethodConfig methodConfig = new MethodConfig();
            methodConfig.setName(name);
            if (timeout != null) {
                methodConfig.setTimeout(timeout);
            }
            methodConfigs.add(methodConfig);
        }
    }
    return methodConfigs;
}
Also used : MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ArrayList(java.util.ArrayList) RpcBindingMethodInfo(com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo)

Aggregations

RpcBindingMethodInfo (com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo)12 ArrayList (java.util.ArrayList)8 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)4 SofaBootRpcRuntimeException (com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException)2 BoltBindingConverter (com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter)2 RpcBindingConverter (com.alipay.sofa.rpc.boot.runtime.converter.RpcBindingConverter)2 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)2 SofaMethod (com.alipay.sofa.runtime.api.annotation.SofaMethod)2 SofaReference (com.alipay.sofa.runtime.api.annotation.SofaReference)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2