use of rpc.turbo.trace.Tracer in project turbo-rpc by hank-whu.
the class KryoSerializer method readRequest.
public Request readRequest(ByteBuf byteBuf) throws IOException {
int requestId = byteBuf.readInt();
int serviceId = ByteBufUtils.readVarInt(byteBuf);
Tracer tracer = tracerSerializer.read(byteBuf);
MethodParam methodParam = null;
if (byteBuf.readBoolean()) {
Class<?> clazz = getClass(serviceId);
methodParam = (MethodParam) kryoContext().readObject(byteBuf, clazz);
}
Request request = RecycleRequest.newInstance(requestId, serviceId, tracer, methodParam);
return request;
}
use of rpc.turbo.trace.Tracer in project turbo-rpc by hank-whu.
the class KryoSerializer method readResponse.
public Response readResponse(ByteBuf byteBuf) throws IOException {
int requestId = byteBuf.readInt();
byte statusCode = byteBuf.readByte();
Tracer tracer = tracerSerializer.read(byteBuf);
Object result = kryoContext().readClassAndObject(byteBuf);
Response response = RecycleResponse.newInstance(requestId, statusCode, tracer, result);
return response;
}
use of rpc.turbo.trace.Tracer in project turbo-rpc by hank-whu.
the class ProtostuffSerializer method readRequest.
public Request readRequest(ByteBuf byteBuf) throws IOException {
int requestId = byteBuf.readInt();
int serviceId = ByteBufUtils.readVarInt(byteBuf);
Tracer tracer = tracerSerializer.read(byteBuf);
Schema<MethodParam> schema = schema(serviceId);
MethodParam methodParam = null;
if (EmptyMethodParam.class.equals(schema.typeClass())) {
methodParam = EmptyMethodParam.empty();
} else {
ByteBufInput input = getOrUpdate(INPUT_ATTACHMENT_INDEX, INPUT_SUPPLIER);
input.setByteBuf(byteBuf, true);
methodParam = schema.newMessage();
schema.mergeFrom(input, methodParam);
}
Request request = RecycleRequest.newInstance(requestId, serviceId, tracer, methodParam);
return request;
}
use of rpc.turbo.trace.Tracer in project turbo-rpc by hank-whu.
the class TracerSerializer method read.
public final Tracer read(ByteBuf buffer) {
byte flag = buffer.readByte();
if (flag == 0) {
return null;
}
Tracer tracer = new Tracer();
if ((flag & TRACE_ID_FLAG) == TRACE_ID_FLAG) {
tracer.setTraceId(new ObjectId(buffer));
}
if ((flag & SPAN_ID_FLAG) == SPAN_ID_FLAG) {
tracer.setSpanId(ByteBufUtils.readVarLong(buffer));
}
if ((flag & PARENT_ID_FLAG) == PARENT_ID_FLAG) {
tracer.setParentId(ByteBufUtils.readVarLong(buffer));
}
if ((flag & CS_FLAG) == CS_FLAG) {
tracer.setCs(ByteBufUtils.readVarLong(buffer));
}
if ((flag & CR_FLAG) == CR_FLAG) {
tracer.setCr(ByteBufUtils.readVarLong(buffer));
}
if ((flag & SS_FLAG) == SS_FLAG) {
tracer.setSs(ByteBufUtils.readVarLong(buffer));
}
if ((flag & SR_FLAG) == SR_FLAG) {
tracer.setSr(ByteBufUtils.readVarLong(buffer));
}
return tracer;
}
use of rpc.turbo.trace.Tracer in project turbo-rpc by hank-whu.
the class TracerSerializer method main.
public static void main(String[] args) {
Tracer tracer = new Tracer();
tracer.setTraceId(ObjectId.next());
tracer.setSpanId(123);
tracer.setParentId(456);
tracer.setCs(System.currentTimeMillis());
tracer.setCr(System.currentTimeMillis());
tracer.setSs(System.currentTimeMillis());
tracer.setSr(System.currentTimeMillis());
TracerSerializer serializer = new TracerSerializer();
ByteBuf buffer = io.netty.buffer.Unpooled.buffer(1024);
serializer.write(buffer, tracer);
Tracer tracer2 = serializer.read(buffer);
System.out.println("length: " + buffer.writerIndex());
System.out.println(tracer2);
}
Aggregations