in src/main/java/org/apache/sling/discovery/oak/JoinerDelay.java [154:206]
public void sync(BaseTopologyView view, final Runnable callback) {
if (callback == null) {
throw new IllegalArgumentException("callback must not be null");
}
if (view == null) {
throw new IllegalArgumentException("view must not be null");
}
// here we can be in any phase (IDLE, DELAYING, DONE)
final boolean isPhaseDone;
synchronized(this) {
if (phase == Phase.IDLE) {
if (joinerConditionApplies(view)) {
markDelaying();
} else {
markDone();
}
}
isPhaseDone = phase == Phase.DONE;
}
logSilencer.infoOrDebug("sync-status", "sync: isPhaseDone : " + isPhaseDone);
if (isPhaseDone) {
// invoke callback (outside synchronization)
callback.run();
return;
}
// here we are in phase DELAYING and absoluteTimeout is set
cancelSync();
final Job doContinue = new Job() {
@Override
public void execute(JobContext context) {
if (context != null) {
// context should not be null when invoked by scheduler
// (but it is null within the outer sync() )
assertCorrectThreadPool();
}
markDone();
// invoke callback (outside synchronization)
callback.run();
}
};
if (absoluteTimeout.compareTo(new Date()) < 0) {
// invoke callback (outside synchronization)
doContinue.execute(null);
} else if (!scheduler.schedule(doContinue,
scheduler.AT(absoluteTimeout).name(NAME).threadPoolName("discovery"))) {
// then let's do it anyway
logger.error("sync : schedule failed - ignoring JoinerDelay");
// invoke callback (outside synchronization)
doContinue.execute(null);
}
}