diff --git a/CHANGELOG.md b/CHANGELOG.md index d842aa96..6359ecc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ All notable changes to this project will be documented in this file. ## [1.1-RC4] - Remove WaitStrategy in the Retryer used to check if ServiceRegistry is refreshed during ServiceRegistryUpdater startup -- Remove service-hub-refresh-timer ScheduledSignal because there's already one ScheduledSignal service-hub-updater used in ServiceFinderHub ## [1.1-RC3] - Execute updateRegistry operation in async inside ServiceFinderHub so that main thread reaches till waitTillHubIsReady instead of waiting for lock release and hubStartTimeoutMs is honoured as expected 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 82d5e325..9291c196 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 @@ -84,9 +84,9 @@ public class ServiceFinderHub> { public ServiceFinderHub( ServiceDataSource serviceDataSource, ServiceFinderFactory finderFactory - ) { + ) { this(serviceDataSource, finderFactory, - HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, 5_000, Set.of()); + HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of()); } public ServiceFinderHub( @@ -94,21 +94,15 @@ 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; - 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.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", + () -> null, + Collections.emptyList(), + 10_000)); 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 bd7519b9..848d4080 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,14 +93,21 @@ public ServiceFinderHub build() { Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshTimeoutMs, - hubStartTimeoutMs, refreshFrequencyMs, excludedServices); + hubStartTimeoutMs, excludedServices); + final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", + () -> null, + Collections.emptyList(), + refreshFrequencyMs); + hub.registerUpdateSignal(refreshSignal); 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 4af99f28..4137176c 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, 5_000, Set.of() + .build(), 1_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, 5_000, Set.of() + .build(), 5_000, 5_000, Set.of() ); serviceFinderHub.start(); Assertions.assertTrue(serviceFinderHub.finder(new Service("NS", "SERVICE")).isPresent()); @@ -142,18 +142,18 @@ public ServiceFinder> buildF } } -private static class TestServiceFinderHubBuilder extends ServiceFinderHubBuilder> { + private static class TestServiceFinderHubBuilder extends ServiceFinderHubBuilder> { - @Override - protected void preBuild() { + @Override + protected void preBuild() { - } + } - @Override - protected void postBuild(ServiceFinderHub> serviceFinderHub) { + @Override + protected void postBuild(ServiceFinderHub> serviceFinderHub) { + } } -} private static class TestServiceFinderBuilder extends BaseServiceFinderBuilder, ServiceFinder>, TestServiceFinderBuilder, Deserializer> { private int finderSleepDurationSeconds = 0;