Source:
public <T> CompletableFuture<T> sendRequestAndGetCompletable( CorfuMessage.RequestPayloadMsg payload, long epoch, RpcCommon.UuidMsg clusterId, CorfuMessage.PriorityLevel priority, boolean ignoreClusterId, boolean ignoreEpoch) { try { connectionFuture.get(parameters.getConnectionTimeout().toMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new UnrecoverableCorfuInterruptedError(e); } catch (TimeoutException te) { CompletableFuture<T> f = new CompletableFuture<>(); f.completeExceptionally(te); return f; } catch (ExecutionException ee) { CompletableFuture<T> f = new CompletableFuture<>(); f.completeExceptionally(ee.getCause()); return f; } final long thisRequestId = requestID.getAndIncrement(); RpcCommon.UuidMsg clientId = CorfuProtocolCommon.getUuidMsg(parameters.getClientId()); CorfuMessage.HeaderMsg header = getHeaderMsg(thisRequestId, priority, epoch, clusterId, clientId, ignoreClusterId, ignoreEpoch); CorfuMessage.RequestMsg request = getRequestMsg(header, payload); final Timer roundTripMsgTimer = CorfuRuntime.getDefaultMetrics() .timer(protoTimerNameCache.get(payload.getPayloadCase())); final Timer.Context roundTripMsgContext = MetricsUtils .getConditionalContext(roundTripMsgTimer); final CompletableFuture<T> cf = new CompletableFuture<>(); outstandingRequests.put(thisRequestId, cf); channel.writeAndFlush(request, channel.voidPromise()); log.trace("Sent request message: {}", TextFormat.shortDebugString(request.getHeader())); final CompletableFuture<T> cfBenchmarked = cf.thenApply(x -> { MetricsUtils.stopConditionalContext(roundTripMsgContext); return x; }); final CompletableFuture<T> cfTimeout = CFUtils.within(cfBenchmarked, Duration.ofMillis(timeoutResponse)); cfTimeout.exceptionally(e -> { if (e.getCause() instanceof TimeoutException) { outstandingRequests.remove(thisRequestId); log.debug( "sendRequestAndGetCompletable: Remove request to due to timeout! Request:{}", thisRequestId, node, TextFormat.shortDebugString(request.getHeader())); } return null; }); return cfTimeout; }

Target:
public <T> CompletableFuture<T> sendRequestAndGetCompletable( CorfuMessage.RequestPayloadMsg payload, long epoch, RpcCommon.UuidMsg clusterId, CorfuMessage.PriorityLevel priority, boolean ignoreClusterId, boolean ignoreEpoch) { try { connectionFuture.get(parameters.getConnectionTimeout().toMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new UnrecoverableCorfuInterruptedError(e); } catch (TimeoutException te) { CompletableFuture<T> f = new CompletableFuture<>(); f.completeExceptionally(te); return f; } catch (ExecutionException ee) { CompletableFuture<T> f = new CompletableFuture<>(); f.completeExceptionally(ee.getCause()); return f; } final long thisRequestId = requestID.getAndIncrement(); RpcCommon.UuidMsg clientId = CorfuProtocolCommon.getUuidMsg(parameters.getClientId()); CorfuMessage.HeaderMsg header = getHeaderMsg(thisRequestId, priority, epoch, clusterId, clientId, ignoreClusterId, ignoreEpoch); CorfuMessage.RequestMsg request = getRequestMsg(header, payload); final Timer roundTripMsgTimer = CorfuRuntime.getDefaultMetrics() .timer(protoTimerNameCache.get(payload.getPayloadCase())); final Timer.Context roundTripMsgContext = MetricsUtils .getConditionalContext(roundTripMsgTimer); final CompletableFuture<T> cf = new CompletableFuture<>(); outstandingRequests.put(thisRequestId, cf); channel.writeAndFlush(request, channel.voidPromise()); if (log.isTraceEnabled()) { log.trace("Sent request message: {}", TextFormat.shortDebugString(request.getHeader())); } final CompletableFuture<T> cfBenchmarked = cf.thenApply(x -> { MetricsUtils.stopConditionalContext(roundTripMsgContext); return x; }); final CompletableFuture<T> cfTimeout = CFUtils.within(cfBenchmarked, Duration.ofMillis(timeoutResponse)); cfTimeout.exceptionally(e -> { if (e.getCause() instanceof TimeoutException) { outstandingRequests.remove(thisRequestId); log.debug( "sendRequestAndGetCompletable: Remove request to due to timeout! Request:{}", thisRequestId, node, TextFormat.shortDebugString(request.getHeader())); } return null; }); return cfTimeout; }