Search in sources :

Example 1 with Tracer

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;
}
Also used : MethodParam(rpc.turbo.param.MethodParam) Tracer(rpc.turbo.trace.Tracer) Request(rpc.turbo.protocol.Request) RecycleRequest(rpc.turbo.protocol.recycle.RecycleRequest)

Example 2 with Tracer

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;
}
Also used : RecycleResponse(rpc.turbo.protocol.recycle.RecycleResponse) Response(rpc.turbo.protocol.Response) Tracer(rpc.turbo.trace.Tracer)

Example 3 with Tracer

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;
}
Also used : EmptyMethodParam(rpc.turbo.param.EmptyMethodParam) MethodParam(rpc.turbo.param.MethodParam) Tracer(rpc.turbo.trace.Tracer) RecycleRequest(rpc.turbo.protocol.recycle.RecycleRequest) Request(rpc.turbo.protocol.Request)

Example 4 with Tracer

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;
}
Also used : ObjectId(rpc.turbo.util.uuid.ObjectId) Tracer(rpc.turbo.trace.Tracer)

Example 5 with 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);
}
Also used : Tracer(rpc.turbo.trace.Tracer) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

Tracer (rpc.turbo.trace.Tracer)5 MethodParam (rpc.turbo.param.MethodParam)2 Request (rpc.turbo.protocol.Request)2 RecycleRequest (rpc.turbo.protocol.recycle.RecycleRequest)2 ByteBuf (io.netty.buffer.ByteBuf)1 EmptyMethodParam (rpc.turbo.param.EmptyMethodParam)1 Response (rpc.turbo.protocol.Response)1 RecycleResponse (rpc.turbo.protocol.recycle.RecycleResponse)1 ObjectId (rpc.turbo.util.uuid.ObjectId)1