Search in sources :

Example 6 with Response

use of rpc.turbo.protocol.Response in project turbo-rpc by hank-whu.

the class FutureHolderBenchmark method _completableFuture.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void _completableFuture() {
    int requestId = sequencer.getAndIncrement();
    CompletableFuture<Response> completableFuture = new CompletableFuture<>();
    Response response = new Response();
    response.setRequestId(requestId - 1000);
    completableFuture.complete(response);
}
Also used : Response(rpc.turbo.protocol.Response) CompletableFuture(java.util.concurrent.CompletableFuture) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 7 with Response

use of rpc.turbo.protocol.Response in project turbo-rpc by hank-whu.

the class ProtostuffSerializer method readResponse.

public Response readResponse(ByteBuf byteBuf) throws IOException {
    // System.out.println("response content: " + new
    // String(ByteBufUtil.getBytes(byteBuf.duplicate())));
    // System.out.println("response length: " + byteBuf.readableBytes());
    ByteBufInput input = getOrUpdate(INPUT_ATTACHMENT_INDEX, INPUT_SUPPLIER);
    input.setByteBuf(byteBuf, true);
    Response response = RecycleResponse.newInstance(0, (byte) 0, null, null);
    responseSchema.mergeFrom(input, response);
    return response;
}
Also used : Response(rpc.turbo.protocol.Response) RecycleResponse(rpc.turbo.protocol.recycle.RecycleResponse) ByteBufInput(io.protostuff.ByteBufInput)

Example 8 with Response

use of rpc.turbo.protocol.Response in project turbo-rpc by hank-whu.

the class KryoSerializer method readResponse.

public Response readResponse(ByteBuf byteBuf) throws IOException {
    // System.out.println("response content: " + new
    // String(ByteBufUtil.getBytes(byteBuf.duplicate())));
    // System.out.println("response length: " + byteBuf.readableBytes());
    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 9 with Response

use of rpc.turbo.protocol.Response in project turbo-rpc by hank-whu.

the class ProtostuffSerializerTest method main.

public static void main(String[] args) throws IOException {
    ProtostuffSerializer serializer = new ProtostuffSerializer();
    UserService userService = new UserServiceServerImpl();
    ByteBufAllocator allocator = new UnpooledByteBufAllocator(true);
    ByteBuf byteBuf = allocator.directBuffer(16, 1024 * 1024 * 8);
    Request request = new Request();
    request.setRequestId(123);
    request.setServiceId(8);
    // request.setParams(new Object[] { Integer.valueOf(1), LocalDate.now(), userService.getUser(999).join() });
    serializer.writeRequest(byteBuf, request);
    byteBuf.readerIndex(4);
    System.out.println(serializer.readRequest(byteBuf));
    byteBuf.clear();
    Response response = new Response();
    response.setRequestId(321);
    response.setStatusCode((byte) 1);
    response.setResult(userService.listUser(0).join());
    serializer.writeResponse(byteBuf, response);
    byteBuf.readerIndex(4);
    System.out.println(serializer.readResponse(byteBuf));
}
Also used : Response(rpc.turbo.protocol.Response) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) UserService(rpc.turbo.benchmark.service.UserService) Request(rpc.turbo.protocol.Request) ByteBuf(io.netty.buffer.ByteBuf) ProtostuffSerializer(rpc.turbo.serialization.protostuff.ProtostuffSerializer)

Aggregations

Response (rpc.turbo.protocol.Response)9 CompletableFuture (java.util.concurrent.CompletableFuture)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)4 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)4 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)4 ByteBuf (io.netty.buffer.ByteBuf)2 Request (rpc.turbo.protocol.Request)2 RecycleResponse (rpc.turbo.protocol.recycle.RecycleResponse)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 ByteBufInput (io.protostuff.ByteBufInput)1 IOException (java.io.IOException)1 UserService (rpc.turbo.benchmark.service.UserService)1 UserServiceServerImpl (rpc.turbo.benchmark.service.UserServiceServerImpl)1 EmptyMethodParam (rpc.turbo.param.EmptyMethodParam)1 RemoteException (rpc.turbo.remote.RemoteException)1 ProtostuffSerializer (rpc.turbo.serialization.protostuff.ProtostuffSerializer)1 Tracer (rpc.turbo.trace.Tracer)1 RequestWithFuture (rpc.turbo.transport.client.future.RequestWithFuture)1