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);
}
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;
}
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;
}
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));
}
Aggregations