private CompletableFuture doAsyncGet()

in evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java [595:643]


    private <T> CompletableFuture<T> doAsyncGet(EVCacheKey evcKey, Transcoder<T> tc)  {
        CompletableFuture<T> errorFuture = new CompletableFuture<>();
        final boolean throwExc = doThrowException();
        //Building the client
        EVCacheClient client = buildEvCacheClient(throwExc, Call.COMPLETABLE_FUTURE_GET, errorFuture);
        if (errorFuture.isCompletedExceptionally() || client == null) {
            if (client == null ) {
                if (log.isDebugEnabled() && shouldLog()) log.debug("client is null");
                errorFuture.complete(null);
            }
            return errorFuture;
        }
        if (log.isDebugEnabled() && shouldLog()) log.debug("Completed Building the client");
        //Building the start event
        EVCacheEvent event = buildAndStartEvent(client,
                Collections.singletonList(evcKey),
                throwExc,
                errorFuture,
                Call.COMPLETABLE_FUTURE_GET);
        if (errorFuture.isCompletedExceptionally()) {
            if (log.isDebugEnabled() && shouldLog()) log.debug("Error while building and starting the event");
            return errorFuture;
        }

        final long start = EVCacheMetricsFactory.getInstance().getRegistry().clock().wallTime();
        StringBuilder status = new StringBuilder(EVCacheMetricsFactory.SUCCESS);
        StringBuilder cacheOperation = new StringBuilder(EVCacheMetricsFactory.YES);
        final boolean hasZF = hasZoneFallback();
        RetryCount retryCount = new RetryCount();
        boolean throwEx = !hasZF && throwExc;
        return getAsyncData(client, evcKey, tc)
                .thenCompose(data -> handleRetry(data, evcKey, tc, client, hasZF, throwExc, event, retryCount))
                .handle((data, ex) -> {
                    if (ex != null) {
                        handleMissData(event, evcKey, client, cacheOperation);
                        handleFinally(data, status, retryCount.get(), client, cacheOperation, start, Call.COMPLETABLE_FUTURE_GET);
                        handleException(ex, event);
                        if (throwEx) {
                            throw new RuntimeException(ex);
                        } else {
                            return null;
                        }
                    } else {
                        handleFinally(data, status, retryCount.get(), client, cacheOperation, start, Call.COMPLETABLE_FUTURE_GET);
                        handleData(data, event, evcKey, client, cacheOperation);
                        return data;
                    }
                });
    }