Search in sources :

Example 1 with AnnouncementRegistry

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;
        }
    }
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) AnnouncementRegistry(org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistry) AnnouncementFilter(org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter) ClusterViewService(org.apache.sling.discovery.base.commons.ClusterViewService)

Aggregations

ClusterView (org.apache.sling.discovery.ClusterView)1 ClusterViewService (org.apache.sling.discovery.base.commons.ClusterViewService)1 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)1 AnnouncementFilter (org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter)1 AnnouncementRegistry (org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistry)1