public void handleTopologyEvent()

in src/main/java/org/apache/sling/discovery/commons/InitDelayingTopologyEventListener.java [186:227]


    public void handleTopologyEvent(TopologyEvent event) {
        synchronized ( syncObj ) {
            if ( this.delaying ) {
                // when we're delaying, keep hold of the last event
                // as action afterStartupDelay depends on this last
                // event
                this.logger.debug("handleTopologyEvent: delaying processing of received topology event (startup delay active) {}", event);
                this.pendingDelayedEvent = event;

                // and we're delaying - so stop processing now and return
                return;
            } else if ( this.pendingDelayedEvent != null ) {
                // this means that while we're no longer delaying we still
                // have a pending delayed event to process.
                // more concretely, it means that this event is a CHANGING
                // event (as the others are treated via an artificial INIT event
                // in afterStartupDelay).
                // which means that we must now convert the new event into an INIT
                // to ensure our code gets an INIT first thing

                // paranoia check:
                if ( event.getType() == Type.TOPOLOGY_CHANGING ) {
                    // this should never happen - but if it does, rinse and repeat
                    this.pendingDelayedEvent = event;
                    this.logger.info("handleTopologyEvent: ignoring received topology event of type CHANGING {}", event);
                    return;
                } else {
                    // otherwise we now **convert** the event to an init event
                    this.pendingDelayedEvent = null;
                    this.logger.debug("handleTopologyEvent: first stable topology event received after startup delaying. "
                            + "Simulating an INIT event with this new view: {}", event);
                    event = new TopologyEvent(Type.TOPOLOGY_INIT, null, event.getNewView());
                }
            } else {
                // otherwise we're no longer delaying nor do we have a pending-backlog.
                // we can just pass the event through
                this.logger.debug("handleTopologyEvent: received topology event {}", event);
            }
        }
        // no delaying applicable - call delegate
        this.delegate.handleTopologyEvent(event);
    }