Java Code Examples for com.alipay.remoting.rpc.protocol.RpcProtocol#getResponseHeaderLength()

The following examples show how to use com.alipay.remoting.rpc.protocol.RpcProtocol#getResponseHeaderLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 客户端记录响应反序列化大小和响应反序列化耗时
 *
 * @param responseCommand 响应体
 */
private void recordDeserializeResponse(RpcResponseCommand responseCommand, InvokeContext invokeContext) {
    if (!RpcInternalContext.isAttachmentEnable()) {
        return;
    }
    RpcInternalContext context = null;
    if (invokeContext != null) {
        // 客户端异步调用的情况下,上下文会放在InvokeContext中传递
        context = invokeContext.get(RemotingConstants.INVOKE_CTX_RPC_CTX);
    }
    if (context == null) {
        context = RpcInternalContext.getContext();
    }
    int cost = context.getStopWatch().tick().read();
    int respSize = RpcProtocol.getResponseHeaderLength()
        + responseCommand.getClazzLength()
        + responseCommand.getContentLength()
        + responseCommand.getHeaderLength();
    // 记录响应反序列化大小和响应反序列化耗时
    context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, respSize);
    context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_DESERIALIZE_TIME, cost);
}
 
Example 2
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 服务端记录序列化响应的大小和耗时
 *
 * @param responseCommand 响应体
 */
private void recordSerializeResponse(RpcResponseCommand responseCommand) {
    if (!RpcInternalContext.isAttachmentEnable()) {
        return;
    }
    RpcInternalContext context = RpcInternalContext.getContext();
    int cost = context.getStopWatch().tick().read();
    int respSize = RpcProtocol.getResponseHeaderLength()
        + responseCommand.getClazzLength()
        + responseCommand.getContentLength()
        + responseCommand.getHeaderLength();
    // 记录响应序列化大小和请求序列化耗时
    context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, respSize);
    context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SERIALIZE_TIME, cost);
}