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