use of com.alipay.sofa.rpc.filter.FilterChain in project sofa-rpc by sofastack.
the class BoltFutureInvokeCallback method onResponse.
@Override
public void onResponse(Object result) {
if (rpcFuture == null) {
return;
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
SofaResponse response = (SofaResponse) result;
Throwable throwable = null;
try {
Thread.currentThread().setContextClassLoader(this.classLoader);
RpcInternalContext.setContext(context);
if (EventBus.isEnable(ClientAsyncReceiveEvent.class)) {
EventBus.post(new ClientAsyncReceiveEvent(consumerConfig, providerInfo, request, response, null));
}
pickupBaggage(response);
// do async filter after respond server
FilterChain chain = consumerConfig.getConsumerBootstrap().getCluster().getFilterChain();
if (chain != null) {
chain.onAsyncResponse(consumerConfig, request, response, null);
}
recordClientElapseTime();
if (EventBus.isEnable(ClientEndInvokeEvent.class)) {
EventBus.post(new ClientEndInvokeEvent(request, response, null));
}
Object appResp = response.getAppResponse();
if (response.isError()) {
// rpc层异常
SofaRpcException sofaRpcException = new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, response.getErrorMsg());
rpcFuture.setFailure(sofaRpcException);
} else if (appResp instanceof Throwable) {
// 业务层异常
throwable = (Throwable) appResp;
rpcFuture.setFailure(throwable);
} else {
rpcFuture.setSuccess(appResp);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
RpcInvokeContext.removeContext();
RpcInternalContext.removeAllContext();
}
}
use of com.alipay.sofa.rpc.filter.FilterChain in project sofa-rpc by sofastack.
the class BoltInvokerCallback method onException.
@Override
public void onException(Throwable e) {
if (callback == null) {
return;
}
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.classLoader);
RpcInternalContext.setContext(context);
if (EventBus.isEnable(ClientAsyncReceiveEvent.class)) {
EventBus.post(new ClientAsyncReceiveEvent(consumerConfig, providerInfo, request, null, e));
}
// do async filter after respond server
FilterChain chain = consumerConfig.getConsumerBootstrap().getCluster().getFilterChain();
if (chain != null) {
chain.onAsyncResponse(consumerConfig, request, null, e);
}
recordClientElapseTime();
if (EventBus.isEnable(ClientEndInvokeEvent.class)) {
EventBus.post(new ClientEndInvokeEvent(request, null, e));
}
// judge is timeout or others
SofaRpcException sofaRpcException = null;
if (e instanceof InvokeTimeoutException) {
sofaRpcException = new SofaTimeOutException(e);
} else {
sofaRpcException = new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, e.getMessage(), e);
}
callback.onSofaException(sofaRpcException, request.getMethodName(), request);
} finally {
Thread.currentThread().setContextClassLoader(cl);
RpcInvokeContext.removeContext();
RpcInternalContext.removeAllContext();
}
}
use of com.alipay.sofa.rpc.filter.FilterChain in project sofa-rpc by sofastack.
the class BoltInvokerCallback method onResponse.
@Override
public void onResponse(Object result) {
if (callback == null) {
return;
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
SofaResponse response = (SofaResponse) result;
Throwable throwable = null;
try {
Thread.currentThread().setContextClassLoader(this.classLoader);
RpcInternalContext.setContext(context);
if (EventBus.isEnable(ClientAsyncReceiveEvent.class)) {
EventBus.post(new ClientAsyncReceiveEvent(consumerConfig, providerInfo, request, response, null));
}
pickupBaggage(response);
// do async filter after respond server
FilterChain chain = consumerConfig.getConsumerBootstrap().getCluster().getFilterChain();
if (chain != null) {
chain.onAsyncResponse(consumerConfig, request, response, null);
}
recordClientElapseTime();
if (EventBus.isEnable(ClientEndInvokeEvent.class)) {
EventBus.post(new ClientEndInvokeEvent(request, response, null));
}
Object appResp = response.getAppResponse();
if (response.isError()) {
// rpc层异常
SofaRpcException sofaRpcException = new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, response.getErrorMsg());
callback.onSofaException(sofaRpcException, request.getMethodName(), request);
} else if (appResp instanceof Throwable) {
// 业务层异常
throwable = (Throwable) appResp;
callback.onAppException(throwable, request.getMethodName(), request);
} else {
callback.onAppResponse(appResp, request.getMethodName(), request);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
RpcInvokeContext.removeContext();
RpcInternalContext.removeAllContext();
}
}
Aggregations