public static Announcement fromJSON()

in src/main/java/org/apache/sling/discovery/base/connectors/announcement/Announcement.java [278:331]


    public static Announcement fromJSON(final String topologyAnnouncementJSON) {
        
        JsonObject announcement = jsonReaderFactory.createReader(new StringReader(topologyAnnouncementJSON)).readObject();
        final String ownerId = announcement.getString("ownerId");
        final int protocolVersion;
        if (!announcement.containsKey("protocolVersion")) {
            protocolVersion = -1;
        } else {
            protocolVersion = announcement.getInt("protocolVersion");
        }
        final Announcement result = new Announcement(ownerId, protocolVersion);
        if (announcement.containsKey("created")) {
            result.originallyCreatedAt = announcement.getJsonNumber("created").longValue();
        }
        if (announcement.containsKey("backoffInterval")) {
            long backoffInterval = announcement.getJsonNumber("backoffInterval").longValue();
            result.backoffInterval = backoffInterval;
        }
        if (announcement.containsKey("resetBackoff")) {
            boolean resetBackoff = announcement.getBoolean("resetBackoff");
            result.resetBackoff = resetBackoff;
        }
        if (announcement.containsKey("loop") && announcement.getBoolean("loop")) {
            result.setLoop(true);
            return result;
        }
        if (announcement.containsKey("localClusterView"))
        {
            final String localClusterViewJSON = asJSON(announcement
                    .getJsonObject("localClusterView"));
            
            final ClusterView localClusterView = asClusterView(localClusterViewJSON);
    
            result.setLocalCluster(localClusterView);
        }

        if (announcement.containsKey("inherited")) {
            final Boolean inherited = announcement.getBoolean("inherited");
            result.inherited = inherited;
        }
        if (announcement.containsKey("serverInfo")) {
            String serverInfo = announcement.getString("serverInfo");
            result.serverInfo = serverInfo;
        }

        final JsonArray subAnnouncements = announcement
                .getJsonArray("topologyAnnouncements");
        
        for (int i = 0; i < subAnnouncements.size(); i++) {
            String subAnnouncementJSON = subAnnouncements.get(i).toString();
            result.addIncomingTopologyAnnouncement(fromJSON(subAnnouncementJSON));
        }
        return result;
    }