Skip to content

Commit

Permalink
revert scheduled signal change
Browse files Browse the repository at this point in the history
  • Loading branch information
Jitendra Dhawan committed Dec 12, 2024
1 parent c106588 commit 99c0370
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,25 @@ public class ServiceFinderHub<T, R extends ServiceRegistry<T>> {
public ServiceFinderHub(
ServiceDataSource serviceDataSource,
ServiceFinderFactory<T, R> 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(
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;
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.refreshSignals.add(new ScheduledSignal<>("service-hub-updater",
() -> null,
Collections.emptyList(),
10_000));
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,14 +93,21 @@ public ServiceFinderHub<T, R> 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<Void> 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;
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, 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"))),
Expand All @@ -102,7 +102,7 @@ void testDelayedServiceAddition() {
.withServiceName(service.getServiceName())
.withDeserializer(new Deserializer<TestNodeData>() {})
.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());
Expand Down Expand Up @@ -142,18 +142,18 @@ public ServiceFinder<TestNodeData, MapBasedServiceRegistry<TestNodeData>> buildF
}
}

private static class TestServiceFinderHubBuilder extends ServiceFinderHubBuilder<TestNodeData, MapBasedServiceRegistry<TestNodeData>> {
private static class TestServiceFinderHubBuilder extends ServiceFinderHubBuilder<TestNodeData, MapBasedServiceRegistry<TestNodeData>> {

@Override
protected void preBuild() {
@Override
protected void preBuild() {

}
}

@Override
protected void postBuild(ServiceFinderHub<TestNodeData, MapBasedServiceRegistry<TestNodeData>> serviceFinderHub) {
@Override
protected void postBuild(ServiceFinderHub<TestNodeData, MapBasedServiceRegistry<TestNodeData>> serviceFinderHub) {

}
}
}
private static class TestServiceFinderBuilder extends BaseServiceFinderBuilder<TestNodeData, MapBasedServiceRegistry<TestNodeData>, ServiceFinder<TestNodeData, MapBasedServiceRegistry<TestNodeData>>, TestServiceFinderBuilder, Deserializer<TestNodeData>> {

private int finderSleepDurationSeconds = 0;
Expand Down

0 comments on commit 99c0370

Please sign in to comment.