Skip to content

Commit

Permalink
remove wait strategy from service registry updater and remove duplica…
Browse files Browse the repository at this point in the history
…te scheduled signal in service finder hub
  • Loading branch information
Jitendra Dhawan committed Dec 11, 2024
1 parent c05404a commit 38d2e8e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void start() {
RetryerBuilder.<Boolean>newBuilder()
.retryIfResult(r -> null == r || !r)
.retryIfException()
.withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
.build()
.call(serviceRegistry::isRefreshed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,30 @@ public ServiceFinderHub(
ServiceFinderFactory<T, R> 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(
ServiceDataSource serviceDataSource,
ServiceFinderFactory<T, R> finderFactory,
long serviceRefreshTimeoutMs,
long hubStartTimeoutMs,
long refreshTimeIntervalMs,
final Set<String> 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<Void> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,14 @@ public ServiceFinderHub<T, R> build() {
Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory");

val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshTimeoutMs,
hubStartTimeoutMs, excludedServices);
final ScheduledSignal<Void> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testDelayedServiceAddition() {
.withServiceName(service.getServiceName())
.withDeserializer(new Deserializer<TestNodeData>() {})
.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"))),
Expand All @@ -102,7 +102,7 @@ void testDelayedServiceAddition() {
.withServiceName(service.getServiceName())
.withDeserializer(new Deserializer<TestNodeData>() {})
.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());
Expand Down

0 comments on commit 38d2e8e

Please sign in to comment.