use of org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistry in project sling by apache.
the class AbstractClusterTest method ping.
private Announcement ping(VirtualInstance to, final Announcement incomingTopologyAnnouncement) throws UndefinedClusterViewException {
final String slingId = to.slingId;
final ClusterViewService clusterViewService = to.getClusterViewService();
final AnnouncementRegistry announcementRegistry = to.getAnnouncementRegistry();
incomingTopologyAnnouncement.removeInherited(slingId);
final Announcement replyAnnouncement = new Announcement(slingId);
long backoffInterval = -1;
final ClusterView clusterView = clusterViewService.getLocalClusterView();
if (!incomingTopologyAnnouncement.isCorrectVersion()) {
fail("incorrect version");
// never reached
return null;
} else if (ClusterViewHelper.contains(clusterView, incomingTopologyAnnouncement.getOwnerId())) {
fail("loop=true");
// never reached
return null;
} else if (ClusterViewHelper.containsAny(clusterView, incomingTopologyAnnouncement.listInstances())) {
fail("incoming announcement contains instances that are part of my cluster");
// never reached
return null;
} else {
backoffInterval = announcementRegistry.registerAnnouncement(incomingTopologyAnnouncement);
if (backoffInterval == -1) {
fail("rejecting an announcement from an instance that I already see in my topology: ");
// never reached
return null;
} else {
// normal, successful case: replying with the part of the topology which this instance sees
replyAnnouncement.setLocalCluster(clusterView);
announcementRegistry.addAllExcept(replyAnnouncement, clusterView, new AnnouncementFilter() {
@Override
public boolean accept(final String receivingSlingId, Announcement announcement) {
if (announcement.getPrimaryKey().equals(incomingTopologyAnnouncement.getPrimaryKey())) {
return false;
}
return true;
}
});
return replyAnnouncement;
}
}
}
Aggregations