diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 4d8f17f7..70d43b7c 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -75,7 +75,6 @@ public void start() { RetryerBuilder.newBuilder() .retryIfResult(r -> null == r || !r) .retryIfException() - .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS)) .build() .call(serviceRegistry::isRefreshed); } diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java index 9af57172..17398a2b 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java @@ -86,7 +86,8 @@ public ServiceFinderHub( ServiceFinderFactory finderFactory ) { this(serviceDataSource, finderFactory, - HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of()); + HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, 5_000, + Set.of()); } public ServiceFinderHub( @@ -94,15 +95,21 @@ public ServiceFinderHub( ServiceFinderFactory finderFactory, long serviceRefreshTimeoutMs, long hubStartTimeoutMs, + long refreshTimeIntervalMs, final Set excludedServices) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs == 0 ? HubConstants.SERVICE_REFRESH_TIMEOUT_MS : serviceRefreshTimeoutMs; this.hubStartTimeoutMs = hubStartTimeoutMs == 0 ? HubConstants.HUB_START_TIMEOUT_MS : hubStartTimeoutMs; - this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", - () -> null, - Collections.emptyList(), - 10_000)); + final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-updater", + () -> null, + Collections.emptyList(), + refreshTimeIntervalMs); + this.refreshSignals.add(refreshSignal); + this.getStartSignal() + .registerConsumer(x -> refreshSignal.start()); + this.getStopSignal() + .registerConsumer(x -> refreshSignal.stop()); this.refresherPool = createRefresherPool(); this.excludedServices = Objects.requireNonNullElseGet(excludedServices, Set::of); } diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 6f85c4c1..bd7519b9 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -93,21 +93,14 @@ public ServiceFinderHub build() { Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshTimeoutMs, - hubStartTimeoutMs, excludedServices); - final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", - () -> null, - Collections.emptyList(), - refreshFrequencyMs); - hub.registerUpdateSignal(refreshSignal); + hubStartTimeoutMs, refreshFrequencyMs, excludedServices); extraRefreshSignals.forEach(hub::registerUpdateSignal); hub.getStartSignal() .registerConsumer(x -> serviceDataSource.start()) - .registerConsumer(x -> refreshSignal.start()) .registerConsumers(extraStartSignalConsumers); hub.getStopSignal() .registerConsumers(extraStopSignalConsumers) - .registerConsumer(x -> refreshSignal.stop()) .registerConsumer(x -> serviceDataSource.stop()); postBuild(hub); return hub; diff --git a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java index de92dbac..4af99f28 100644 --- a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java +++ b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java @@ -93,7 +93,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(5) - .build(), 1_000, 5_000, Set.of() + .build(), 1_000, 5_000, 5_000, Set.of() ); Assertions.assertThrows(IllegalStateException.class, delayedHub::start); val serviceFinderHub = new ServiceFinderHub<>(new DynamicDataSource(Lists.newArrayList(new Service("NS", "SERVICE"))), @@ -102,7 +102,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(1) - .build(), 5_000, 5_000, Set.of() + .build(), 5_000, 5_000, 5_000, Set.of() ); serviceFinderHub.start(); Assertions.assertTrue(serviceFinderHub.finder(new Service("NS", "SERVICE")).isPresent());