use of com.baidu.brpc.protocol.Response in project skywalking-java by apache.
the class ServerInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
Response response = (Response) allArguments[1];
if (response != null && response.getException() != null) {
AbstractSpan span = ContextManager.activeSpan();
span.log(response.getException());
}
ContextManager.stopSpan();
return ret;
}
use of com.baidu.brpc.protocol.Response in project brpc-java by baidu.
the class DefaultServerPushProtocol method getResponse.
@Override
public Response getResponse() {
// tcp protocol implementation, http protocols should override this method
Response response = RpcResponse.getRpcResponse();
response.reset();
return response;
}
use of com.baidu.brpc.protocol.Response in project brpc-java by baidu.
the class HttpRpcProtocol method getResponse.
@Override
public Response getResponse() {
Response response = HttpResponse.getHttpResponse();
response.reset();
return response;
}
use of com.baidu.brpc.protocol.Response in project brpc-java by baidu.
the class ClientWorkTask method handlePushRequest.
/**
* 收到push请求的处理方法
*/
private void handlePushRequest() {
Request request = null;
Response response = protocol.createResponse();
try {
request = protocol.decodeRequest(packet);
} catch (Exception ex) {
// throw request
log.warn("decode request failed:", ex);
response.setException(ex);
} finally {
if (request != null && request.getException() != null) {
response.setException(request.getException());
}
}
RpcContext rpcContext = null;
request.setChannel(ctx.channel());
if (request.getBinaryAttachment() != null || request.getKvAttachment() != null) {
rpcContext = RpcContext.getContext();
if (request.getBinaryAttachment() != null) {
rpcContext.setRequestBinaryAttachment(request.getBinaryAttachment());
}
if (request.getKvAttachment() != null) {
rpcContext.setRequestKvAttachment(request.getKvAttachment());
}
rpcContext.setRemoteAddress(ctx.channel().remoteAddress());
}
response.setLogId(request.getLogId());
response.setCorrelationId(request.getCorrelationId());
response.setCompressType(request.getCompressType());
response.setException(request.getException());
response.setRpcMethodInfo(request.getRpcMethodInfo());
String serviceName = request.getServiceName();
String methodName = request.getMethodName();
RpcMethodInfo service = ServiceManager.getInstance().getService(serviceName, methodName);
Method targetMethod = request.getTargetMethod();
Object t = service.getTarget();
Object result = null;
try {
result = targetMethod.invoke(t, request.getArgs());
} catch (Exception e) {
log.error("exception :", e);
}
response.setResult(result);
try {
ByteBuf byteBuf = protocol.encodeResponse(request, response);
ChannelFuture channelFuture = ctx.channel().writeAndFlush(byteBuf);
protocol.afterResponseSent(request, response, channelFuture);
} catch (Exception ex) {
log.warn("send response failed:", ex);
}
if (rpcContext != null) {
rpcContext.reset();
}
}
use of com.baidu.brpc.protocol.Response in project brpc-java by baidu.
the class BrpcProxy method executeWithRetry.
public Response executeWithRetry(Request request) {
Response response = null;
RpcException exception = null;
int currentTryTimes = 0;
int maxTryTimes = rpcClient.getRpcClientOptions().getMaxTryTimes();
while (currentTryTimes < maxTryTimes) {
try {
// therefore, it need LoadBalanceStrategy to judge if selectInstances is null.
if (currentTryTimes > 0) {
if (request.getChannel() != null) {
if (request.getSelectedInstances() == null) {
request.setSelectedInstances(new HashSet<CommunicationClient>(maxTryTimes - 1));
}
request.getSelectedInstances().add(request.getCommunicationClient());
}
}
response = rpcClient.execute(request, rpcClient.getCommunicationOptions());
break;
} catch (RpcException ex) {
exception = ex;
if (exception.getCode() == RpcException.INTERCEPT_EXCEPTION) {
break;
}
} finally {
currentTryTimes++;
}
}
if (response == null || (response.getResult() == null && response.getRpcFuture() == null)) {
if (exception == null) {
exception = new RpcException(RpcException.UNKNOWN_EXCEPTION, "unknown error");
}
throw exception;
}
return response;
}
Aggregations