Search in sources :

Example 1 with ClientBeforeSendEvent

use of com.alipay.sofa.rpc.event.ClientBeforeSendEvent in project sofa-rpc by sofastack.

the class AbstractHttp2ClientTransport method beforeSend.

/**
 * 调用前设置一些属性
 *
 * @param context RPC上下文
 * @param request 请求对象
 */
protected void beforeSend(RpcInternalContext context, SofaRequest request) {
    currentRequests.incrementAndGet();
    context.getStopWatch().tick().read();
    context.setLocalAddress(localAddress());
    if (EventBus.isEnable(ClientBeforeSendEvent.class)) {
        EventBus.post(new ClientBeforeSendEvent(request));
    }
}
Also used : ClientBeforeSendEvent(com.alipay.sofa.rpc.event.ClientBeforeSendEvent)

Example 2 with ClientBeforeSendEvent

use of com.alipay.sofa.rpc.event.ClientBeforeSendEvent in project sofa-rpc by sofastack.

the class AbstractProxyClientTransport method syncSend.

@Override
public SofaResponse syncSend(SofaRequest request, int timeout) throws SofaRpcException {
    RpcInternalContext context = RpcInternalContext.getContext();
    SofaResponse response = null;
    SofaRpcException throwable = null;
    try {
        beforeSend(context, request);
        if (EventBus.isEnable(ClientBeforeSendEvent.class)) {
            EventBus.post(new ClientBeforeSendEvent(request));
        }
        response = doInvokeSync(request, timeout);
        return response;
    } catch (InvocationTargetException e) {
        throwable = convertToRpcException(e);
        throw throwable;
    } catch (SofaRpcException e) {
        throwable = e;
        throw e;
    } catch (Exception e) {
        throwable = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "Failed to send message to remote", e);
        throw throwable;
    } finally {
        afterSend(context, request);
        if (EventBus.isEnable(ClientSyncReceiveEvent.class)) {
            EventBus.post(new ClientSyncReceiveEvent(transportConfig.getConsumerConfig(), transportConfig.getProviderInfo(), request, response, throwable));
        }
    }
}
Also used : RpcInternalContext(com.alipay.sofa.rpc.context.RpcInternalContext) ClientBeforeSendEvent(com.alipay.sofa.rpc.event.ClientBeforeSendEvent) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) ClientSyncReceiveEvent(com.alipay.sofa.rpc.event.ClientSyncReceiveEvent) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SocketTimeoutException(java.net.SocketTimeoutException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) ConnectException(java.net.ConnectException)

Example 3 with ClientBeforeSendEvent

use of com.alipay.sofa.rpc.event.ClientBeforeSendEvent in project sofa-rpc by sofastack.

the class BoltClientTransport method beforeSend.

/**
 * 调用前设置一些属性
 *
 * @param context RPC上下文
 * @param request 请求对象
 */
protected void beforeSend(RpcInternalContext context, SofaRequest request) {
    currentRequests.incrementAndGet();
    context.setLocalAddress(localAddress());
    if (EventBus.isEnable(ClientBeforeSendEvent.class)) {
        EventBus.post(new ClientBeforeSendEvent(request));
    }
}
Also used : ClientBeforeSendEvent(com.alipay.sofa.rpc.event.ClientBeforeSendEvent)

Aggregations

ClientBeforeSendEvent (com.alipay.sofa.rpc.event.ClientBeforeSendEvent)3 RpcInternalContext (com.alipay.sofa.rpc.context.RpcInternalContext)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 SofaRpcRuntimeException (com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 ClientSyncReceiveEvent (com.alipay.sofa.rpc.event.ClientSyncReceiveEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1