private void recursiveStartStream()

in functions/source/amazon-chime-recordandtranscribe/src/main/java/com/amazonaws/kvstranscribestreaming/transcribe/TranscribeStreamingRetryClient.java [144:178]


    private void recursiveStartStream(final StartStreamTranscriptionRequest request,
            final Publisher<AudioStream> publisher,
            final StreamTranscriptionBehavior responseHandler,
            final CompletableFuture<Void> finalFuture,
            final int retryAttempt) {
        CompletableFuture<Void> result = client.startStreamTranscription(request, publisher,
                getResponseHandler(responseHandler));
        result.whenComplete((r, e) -> {
            if (e != null) {
                log.debug("Error occured:", e);

                if (retryAttempt <= maxRetries && isExceptionRetriable(e)) {
                    log.debug("Retriable error occurred and will be retried.");
                    log.debug("Sleeping for sometime before retrying...");
                    try {
                        Thread.sleep(sleepTime);
                    } catch (InterruptedException e1) {
                        log.debug("Unable to sleep. Failed with exception: ", e);
                        e1.printStackTrace();
                    }
                    log.debug("Making retry attempt: " + (retryAttempt + 1));
                    recursiveStartStream(request, publisher, responseHandler, finalFuture, retryAttempt + 1);
                } else {
                    metricsUtil.recordMetric("TranscribeStreamError", 1);
                    log.error("Encountered unretriable exception or ran out of retries. ");
                    responseHandler.onError(e);
                    finalFuture.completeExceptionally(e);
                }
            } else {
                metricsUtil.recordMetric("TranscribeStreamSuccess", 1);
                responseHandler.onComplete();
                finalFuture.complete(null);
            }
        });
    }