use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by sofastack.
the class ConsumerConfigHelper 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();
Integer retries = info.getRetries();
String type = info.getType();
Object callbackHandler = info.getCallbackHandler();
MethodConfig methodConfig = new MethodConfig();
methodConfig.setName(name);
if (timeout != null) {
methodConfig.setTimeout(timeout);
}
if (retries != null) {
methodConfig.setRetries(retries);
}
if (StringUtils.hasText(type)) {
methodConfig.setInvokeType(type);
}
if (callbackHandler != null) {
if (callbackHandler instanceof SofaResponseCallback) {
methodConfig.setOnReturn((SofaResponseCallback) callbackHandler);
} else {
throw new SofaBootRpcRuntimeException("callback handler must implement SofaResponseCallback [" + callbackHandler + "]");
}
}
methodConfigs.add(methodConfig);
}
}
return methodConfigs;
}
use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by sofastack.
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);
}
use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by sofastack.
the class RpcBindingConverter method setCallback.
protected void setCallback(RpcBindingParam bindingParam, BindingConverterContext bindingConverterContext) {
// global
if (bindingParam.getCallbackHandler() == null) {
Object globalCallbackHandler = SofaBootRpcSpringUtil.getSpringBean(bindingParam.getCallbackRef(), bindingParam.getCallbackClass(), bindingConverterContext.getApplicationContext(), bindingConverterContext.getAppClassLoader(), bindingConverterContext.getAppName());
if (globalCallbackHandler != null) {
bindingParam.setCallbackHandler(globalCallbackHandler);
}
}
// method
if (!CollectionUtils.isEmpty(bindingParam.getMethodInfos())) {
for (RpcBindingMethodInfo methodInfo : bindingParam.getMethodInfos()) {
Object methodCallbackHandler = methodInfo.getCallbackHandler();
if (methodCallbackHandler == null) {
methodCallbackHandler = SofaBootRpcSpringUtil.getSpringBean(methodInfo.getCallbackRef(), methodInfo.getCallbackClass(), bindingConverterContext.getApplicationContext(), bindingConverterContext.getAppClassLoader(), bindingConverterContext.getAppName());
methodInfo.setCallbackHandler(methodCallbackHandler);
}
}
}
}
use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.
the class ConsumerConfigHelper 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();
Integer retries = info.getRetries();
String type = info.getType();
Object callbackHandler = info.getCallbackHandler();
MethodConfig methodConfig = new MethodConfig();
methodConfig.setName(name);
if (timeout != null) {
methodConfig.setTimeout(timeout);
}
if (retries != null) {
methodConfig.setRetries(retries);
}
if (StringUtils.hasText(type)) {
methodConfig.setInvokeType(type);
}
if (callbackHandler != null) {
if (callbackHandler instanceof SofaResponseCallback) {
methodConfig.setOnReturn((SofaResponseCallback) callbackHandler);
} else {
throw new SofaBootRpcRuntimeException("callback handler must implement SofaResponseCallback [" + callbackHandler + "]");
}
}
methodConfigs.add(methodConfig);
}
}
return methodConfigs;
}
use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo in project sofa-boot by alipay.
the class RpcBindingConverter method setCallback.
protected void setCallback(RpcBindingParam bindingParam, BindingConverterContext bindingConverterContext) {
// global
if (bindingParam.getCallbackHandler() == null) {
Object globalCallbackHandler = SofaBootRpcSpringUtil.getSpringBean(bindingParam.getCallbackRef(), bindingParam.getCallbackClass(), bindingConverterContext.getApplicationContext(), bindingConverterContext.getAppClassLoader(), bindingConverterContext.getAppName());
if (globalCallbackHandler != null) {
bindingParam.setCallbackHandler(globalCallbackHandler);
}
}
// method
if (!CollectionUtils.isEmpty(bindingParam.getMethodInfos())) {
for (RpcBindingMethodInfo methodInfo : bindingParam.getMethodInfos()) {
Object methodCallbackHandler = methodInfo.getCallbackHandler();
if (methodCallbackHandler == null) {
methodCallbackHandler = SofaBootRpcSpringUtil.getSpringBean(methodInfo.getCallbackRef(), methodInfo.getCallbackClass(), bindingConverterContext.getApplicationContext(), bindingConverterContext.getAppClassLoader(), bindingConverterContext.getAppName());
methodInfo.setCallbackHandler(methodCallbackHandler);
}
}
}
}
Aggregations