private void discoverInstances()

in data-prepper-plugins/peer-forwarder/src/main/java/com/amazon/dataprepper/plugins/prepper/peerforwarder/discovery/AwsCloudMapPeerListProvider.java [146:183]


        private void discoverInstances() {
            if (isClosing()) {
                return;
            }

            final DiscoverInstancesRequest discoverInstancesRequest = DiscoverInstancesRequest
                    .builder()
                    .namespaceName(namespaceName)
                    .serviceName(serviceName)
                    .build();

            LOG.info("Discovering instances.");

            awsServiceDiscovery.discoverInstances(discoverInstancesRequest).whenComplete(
                    (discoverInstancesResponse, throwable) -> {
                        if (discoverInstancesResponse != null) {
                            try {
                                failedAttemptCount = 0;
                                updateEndpointsWithDiscoveredInstances(discoverInstancesResponse);
                            } catch (final Throwable ex) {
                                LOG.warn("Failed to update endpoints.", ex);
                            } finally {
                                scheduledDiscovery = eventLoop.schedule(this::discoverInstances,
                                        timeToRefreshSeconds, TimeUnit.SECONDS);
                            }
                        }

                        if (throwable != null) {
                            failedAttemptCount++;
                            final long delayMillis = backoff.nextDelayMillis(failedAttemptCount);
                            LOG.error("Failed to discover instances for: namespace='{}', serviceName='{}'. Will retry in {} ms.",
                                    namespaceName, serviceName, delayMillis, throwable);

                            scheduledDiscovery = eventLoop.schedule(this::discoverInstances,
                                    delayMillis, TimeUnit.MILLISECONDS);
                        }
                    });
        }