Skip to content

Commit

Permalink
Remove unneeded delay on address changed event
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur committed May 6, 2024
1 parent e7e80df commit df22189
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,7 @@ public IpAddonFinder(final @Reference NetworkAddressService networkAddressServic
logger.trace("IpAddonFinder::IpAddonFinder");
// start of scan will be triggered by setAddonCandidates to ensure addonCandidates are available
this.networkAddressService = networkAddressService;
}

@Activate
public void activate() {
logger.trace("IpAddonFinder::activate");
networkAddressService.addNetworkAddressChangeListener(this);
this.networkAddressService.addNetworkAddressChangeListener(this);
}

@Deactivate
Expand All @@ -235,7 +230,7 @@ public void deactivate() {
public void setAddonCandidates(List<AddonInfo> candidates) {
logger.debug("IpAddonFinder::setAddonCandidates({})", candidates.size());
super.setAddonCandidates(candidates);
startScan();
startScan(20);
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -254,17 +249,17 @@ public void onChanged(List<CidrAddress> added, List<CidrAddress> removed) {

@Override
public void onPrimaryAddressChanged(@Nullable String oldPrimaryAddress, @Nullable String newPrimaryAddress) {
startScan();
startScan(0);
}

private void startScan() {
private void startScan(long delayInSeconds) {
// The setAddonCandidates() method is called for each info provider.
// In order to do the scan only once, but on the full set of candidates, we have to delay the execution.
// At the same time we must make sure that a scheduled scan is rescheduled - or (after more than our delay) is
// executed once more.
stopScan();
logger.trace("Scheduling new IP scan");
scanJob = scheduler.schedule(this::scan, 20, TimeUnit.SECONDS);
scanJob = scheduler.schedule(this::scan, delayInSeconds, TimeUnit.SECONDS);
}

private void stopScan() {
Expand Down

0 comments on commit df22189

Please sign in to comment.