in src/main/java/org/apache/sling/discovery/commons/InitDelayingTopologyEventListener.java [248:288]
private void afterStartupDelay() {
synchronized ( this.syncObj ) {
// stop any future delaying
this.delaying = false;
if ( this.pendingDelayedEvent == null ) {
// if no event received while we delayed,
// then we don't have to do anything later
this.logger.debug("afterStartupDelay: startup delay passed without any events delayed. "
+ "So, ready for first upcoming INIT event");
} else if ( this.pendingDelayedEvent.getType() == Type.TOPOLOGY_CHANGING ) {
// if the last delayed event was CHANGING
// then we must convert the next upcoming CHANGED, PROPERTIES
// into an INIT
// and the way this is done in this class is by leving this
// event sit in this.pendingDelayedEvent, for grabs in handleTopologyEvent later
this.logger.debug("afterStartupDelay: startup delay passed, pending delayed event was CHANGING. "
+ "Waiting for next stable topology event");
} else {
// otherwise the last delayed event was either an INIT, CHANGED or PROPERTIES
// - but in any case we definitely never
// processed any INIT - and our code expects an INIT
// as the first event ever..
// so we now convert the event into an INIT
final TopologyEvent artificialInitEvent =
new TopologyEvent(Type.TOPOLOGY_INIT, null, this.pendingDelayedEvent.getNewView());
this.logger.debug("afterStartupDelay: startup delay passed, last pending delayed event was stable ({}). "
+ "Simulating an INIT event with that view: {}", this.pendingDelayedEvent, artificialInitEvent);
this.pendingDelayedEvent = null;
// call the delegate.
// we must do this call in the synchronized block
// to ensure any concurrent new event waits properly
// before the INIT is done
delegate.handleTopologyEvent(artificialInitEvent);
}
}
}