use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-rpc by sofastack.
the class SofaRpcSerialization method deserializeHeader.
@Override
public <Request extends RequestCommand> boolean deserializeHeader(Request request) throws DeserializationException {
if (request instanceof RpcRequestCommand) {
RpcInternalContext.getContext().getStopWatch().tick();
RpcRequestCommand requestCommand = (RpcRequestCommand) request;
if (requestCommand.getRequestHeader() != null) {
// 代表已经提前解析过了,例如使用自定义业务线程池的时候,bolt会提前解析变长Header的数据
return true;
}
byte[] header = requestCommand.getHeader();
// 解析头部
Map<String, String> headerMap = mapSerializer.decode(header);
requestCommand.setRequestHeader(headerMap);
RpcInvokeContext.getContext().put(RpcConstants.SOFA_REQUEST_HEADER_KEY, Collections.unmodifiableMap(headerMap));
return true;
}
return false;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project sofa-rpc by sofastack.
the class SofaRpcSerialization method serializeContent.
@Override
public <Request extends RequestCommand> boolean serializeContent(Request request, InvokeContext invokeContext) throws SerializationException {
if (request instanceof RpcRequestCommand) {
RpcRequestCommand requestCommand = (RpcRequestCommand) request;
Object requestObject = requestCommand.getRequestObject();
byte serializerCode = requestCommand.getSerializer();
long serializeStartTime = System.nanoTime();
try {
Map<String, String> header = (Map<String, String>) requestCommand.getRequestHeader();
if (header == null) {
header = new HashMap<String, String>();
}
putKV(header, RemotingConstants.HEAD_GENERIC_TYPE, (String) invokeContext.get(RemotingConstants.HEAD_GENERIC_TYPE));
Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory.getSerializer(serializerCode);
AbstractByteBuf byteBuf = rpcSerializer.encode(requestObject, header);
request.setContent(byteBuf.array());
return true;
} catch (Exception ex) {
throw new SerializationException(ex.getMessage(), ex);
} finally {
// R5:record request serialization time
recordSerializeRequest(requestCommand, invokeContext, serializeStartTime);
}
}
return false;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project dingo by dingodb.
the class ProtobufSerializer method serializeHeader.
@Override
public <T extends RequestCommand> boolean serializeHeader(T request, InvokeContext invokeContext) throws SerializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final Message msg = (Message) cmd.getRequestObject();
if (msg instanceof RpcRequests.AppendEntriesRequest) {
final RpcRequests.AppendEntriesRequest req = (RpcRequests.AppendEntriesRequest) msg;
final RpcRequests.AppendEntriesRequestHeader.Builder hb = RpcRequests.AppendEntriesRequestHeader.newBuilder().setGroupId(//
req.getGroupId()).setPeerId(//
req.getPeerId()).setServerId(req.getServerId());
cmd.setHeader(hb.build().toByteArray());
return true;
}
return false;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project dingo by dingodb.
the class ProtobufSerializer method deserializeContent.
@Override
public <T extends RequestCommand> boolean deserializeContent(T request) throws DeserializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final String className = cmd.getRequestClass();
cmd.setRequestObject(ProtobufMsgFactory.newMessageByJavaClassName(className, request.getContent()));
return true;
}
use of com.alipay.remoting.rpc.protocol.RpcRequestCommand in project dingo by dingodb.
the class ProtobufSerializer method serializeContent.
@Override
public <T extends RequestCommand> boolean serializeContent(T request, InvokeContext invokeContext) throws SerializationException {
final RpcRequestCommand cmd = (RpcRequestCommand) request;
final Message msg = (Message) cmd.getRequestObject();
cmd.setContent(msg.toByteArray());
return true;
}
Aggregations