return;
}
if (oldView == null) {
throw new IllegalStateException("oldView must not be null");
}
TopologyViewImpl newView = (TopologyViewImpl) getTopology();
TopologyViewImpl oldView = this.oldView;
Type difference = newView.compareTopology(oldView);
if (difference == null) {
// then dont send any event then
logger.debug("handlePotentialTopologyChange: identical views. not informing listeners");
return;
} else {
if (logger.isDebugEnabled()) {
logger.debug("handlePotentialTopologyChange: difference: {}, oldView={}, newView={}",
new Object[] {difference, oldView, newView});
}
}
oldView.markOld();
if (difference!=Type.TOPOLOGY_CHANGED) {
for (final TopologyEventListener da : eventListeners) {
sendTopologyEvent(da, new TopologyEvent(difference, oldView,
newView));
}
} else { // TOPOLOGY_CHANGED
// send a TOPOLOGY_CHANGING first
for (final TopologyEventListener da : eventListeners) {
sendTopologyEvent(da, new TopologyEvent(Type.TOPOLOGY_CHANGING, oldView,
null));
}
if (config.getMinEventDelay()>0) {
// then delay the sending of the next event
logger.debug("handlePotentialTopologyChange: delaying event sending to avoid event flooding");
if (runAfter(config.getMinEventDelay() /*seconds*/ , new Runnable() {
public void run() {
synchronized(lock) {
delayedEventPending = false;
logger.debug("handlePotentialTopologyChange: sending delayed event now");
if (!activated) {
logger.debug("handlePotentialTopologyChange: no longer activated. not sending delayed event");
return;
}
final TopologyViewImpl newView = (TopologyViewImpl) getTopology();
// irrespective of the difference, send the latest topology
// via a topology_changed event (since we already sent a changing)
for (final TopologyEventListener da : eventListeners) {
sendTopologyEvent(da, new TopologyEvent(Type.TOPOLOGY_CHANGED,
DiscoveryServiceImpl.this.oldView, newView));