Search in sources :

Example 1 with Response

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

the class FutureHolderBenchmark method futureContainer3.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void futureContainer3() {
    int requestId = sequencer.getAndIncrement();
    CompletableFuture<Response> completableFuture = new CompletableFuture<>();
    futureContainer3.addFuture(requestId, completableFuture);
    Response response = new Response();
    response.setRequestId(requestId - 1000);
    futureContainer3.notifyResponse(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 2 with Response

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

the class FutureHolderBenchmark method futureContainer2.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void futureContainer2() {
    int requestId = sequencer.getAndIncrement();
    CompletableFuture<Response> completableFuture = new CompletableFuture<>();
    futureContainer2.addFuture(requestId, completableFuture);
    Response response = new Response();
    response.setRequestId(requestId - 1000);
    futureContainer2.notifyResponse(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 3 with Response

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

the class FutureHolderBenchmark method futureContainer1.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void futureContainer1() {
    int requestId = sequencer.getAndIncrement();
    CompletableFuture<Response> completableFuture = new CompletableFuture<>();
    futureContainer1.addFuture(requestId, completableFuture);
    Response response = new Response();
    response.setRequestId(requestId - 1000);
    futureContainer1.notifyResponse(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 4 with Response

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

the class ConnectorContext method execute.

/**
 * 远程调用
 *
 * @param serviceId
 *            远程serviceId
 * @param timeout
 *            millseconds
 * @param methodParam
 *            方法参数对象,无参类型为null
 * @param failoverInvoker
 *            失败回退
 * @return
 */
<T> CompletableFuture<T> execute(int serviceId, long timeout, MethodParam methodParam, Invoker<CompletableFuture<?>> failoverInvoker) {
    if (isClosed) {
        throw new RemoteException("已关闭的连接!");
    }
    int requestId = sequencer.next();
    for (int i = 0; i < connectCount; i++) {
        // 最多循环一遍
        if (isZombie(channelIndex(requestId))) {
            requestId = sequencer.next();
            continue;
        }
        break;
    }
    Request request = new Request();
    request.setServiceId(serviceId);
    request.setRequestId(requestId);
    if (methodParam instanceof EmptyMethodParam) {
        request.setMethodParam(null);
    } else {
        request.setMethodParam(methodParam);
    }
    if (globalTimeout > 0) {
        timeout = globalTimeout;
    }
    CompletableFuture<Response> future = new CompletableFuture<>();
    try {
        if (requestWaitSemaphore != null) {
            requestWaitSemaphore.acquire();
        }
        boolean allowSend = doRequestFilter(request);
        if (allowSend) {
            long expireTime = SystemClock.fast().mills() + timeout;
            // 
            connector.send(// 
            channelIndex(request), new RequestWithFuture(request, future, expireTime));
        } else {
            future.completeExceptionally(new RemoteException(RpcClientFilter.CLIENT_FILTER_DENY, false));
        }
    } catch (Exception e) {
        future.completeExceptionally(e);
    }
    if (failoverInvoker == null) {
        return handleResult(request, future);
    } else {
        return handleResult(request, future, failoverInvoker, methodParam);
    }
}
Also used : Response(rpc.turbo.protocol.Response) CompletableFuture(java.util.concurrent.CompletableFuture) RequestWithFuture(rpc.turbo.transport.client.future.RequestWithFuture) EmptyMethodParam(rpc.turbo.param.EmptyMethodParam) Request(rpc.turbo.protocol.Request) RemoteException(rpc.turbo.remote.RemoteException) RemoteException(rpc.turbo.remote.RemoteException) IOException(java.io.IOException)

Example 5 with Response

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

the class ResponseDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf buffer = (ByteBuf) super.decode(ctx, in);
    if (buffer != null) {
        try {
            Response response = serializer.readResponse(buffer);
            futureContainer.notifyResponse(response);
        } finally {
            buffer.release();
        }
    }
    return null;
}
Also used : Response(rpc.turbo.protocol.Response) ByteBuf(io.netty.buffer.ByteBuf)

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