use of com.weibo.api.motan.exception.MotanServiceException in project motan by weibocom.
the class SwitcherFilter method mockDefaultResponse.
/**
* 返回的reponse需要设置exception,这样invocationhandler会在throwException为false时,构建默认值返回
*
* @param request
* @return
*/
private Response mockDefaultResponse(Request request) {
DefaultResponse response = new DefaultResponse(null, request.getRequestId());
response.setException(new MotanServiceException("Request false for switcher is on"));
return response;
}
use of com.weibo.api.motan.exception.MotanServiceException in project motan by weibocom.
the class ProviderProtectedMessageRouter method reject.
private Response reject(String method, int requestCounter, int totalCounter, int maxThread) {
DefaultResponse response = new DefaultResponse();
MotanServiceException exception = new MotanServiceException("ThreadProtectedRequestRouter reject request: request_counter=" + requestCounter + " total_counter=" + totalCounter + " max_thread=" + maxThread, MotanErrorMsgConstant.SERVICE_REJECT);
exception.setStackTrace(new StackTraceElement[0]);
response.setException(exception);
LoggerUtil.error("ThreadProtectedRequestRouter reject request: request_method=" + method + " request_counter=" + requestCounter + " =" + totalCounter + " max_thread=" + maxThread);
return response;
}
use of com.weibo.api.motan.exception.MotanServiceException in project motan by weibocom.
the class FailoverHaStrategy method call.
@Override
public Response call(Request request, LoadBalance<T> loadBalance) {
List<Referer<T>> referers = selectReferers(request, loadBalance);
if (referers.isEmpty()) {
throw new MotanServiceException(String.format("FailoverHaStrategy No referers for request:%s, loadbalance:%s", request, loadBalance));
}
URL refUrl = referers.get(0).getUrl();
// 先使用method的配置
int tryCount = refUrl.getMethodParameter(request.getMethodName(), request.getParamtersDesc(), URLParamType.retries.getName(), URLParamType.retries.getIntValue());
// 如果有问题,则设置为不重试
if (tryCount < 0) {
tryCount = 0;
}
for (int i = 0; i <= tryCount; i++) {
Referer<T> refer = referers.get(i % referers.size());
try {
request.setRetries(i);
return refer.call(request);
} catch (RuntimeException e) {
// 对于业务异常,直接抛出
if (ExceptionUtil.isBizException(e)) {
throw e;
} else if (i >= tryCount) {
throw e;
}
LoggerUtil.warn(String.format("FailoverHaStrategy Call false for request:%s error=%s", request, e.getMessage()));
}
}
throw new MotanFrameworkException("FailoverHaStrategy.call should not come here!");
}
use of com.weibo.api.motan.exception.MotanServiceException in project motan by weibocom.
the class YarMessageRouter method handle.
@Override
public Object handle(Channel channel, Object message) {
YarRequest yarRequest = (YarRequest) message;
String packagerName = yarRequest.getPackagerName();
Provider<?> provider = providerMap.get(yarRequest.getRequestPath());
if (provider == null) {
throw new MotanServiceException("can not find service provider. request path:" + yarRequest.getRequestPath());
}
Class<?> clazz = provider.getInterface();
Request request = YarProtocolUtil.convert(yarRequest, clazz);
Response response = call(request, provider);
YarResponse yarResponse = YarProtocolUtil.convert(response, packagerName);
return yarResponse;
}
use of com.weibo.api.motan.exception.MotanServiceException in project motan by weibocom.
the class YarProtocolUtil method addArguments.
/**
* add arguments
*
* @param interfaceClass
* @param methodName
* @param arguments
* @return
*/
private static void addArguments(DefaultRequest request, Class<?> interfaceClass, String methodName, Object[] arguments) {
Method targetMethod = null;
Method[] methods = interfaceClass.getDeclaredMethods();
for (Method m : methods) {
// size of parameters with same method name to avoid.
if (m.getName().equalsIgnoreCase(methodName) && m.getParameterTypes().length == arguments.length) {
targetMethod = m;
break;
}
}
if (targetMethod == null) {
throw new MotanServiceException("cann't find request method. method name " + methodName);
}
request.setParamtersDesc(ReflectUtil.getMethodParamDesc(targetMethod));
if (arguments != null && arguments.length > 0) {
Class<?>[] argumentClazz = targetMethod.getParameterTypes();
request.setArguments(adaptParams(targetMethod, arguments, argumentClazz));
}
}
Aggregations