}
/** Create an announcement form json **/
public static Announcement fromJSON(final String topologyAnnouncementJSON)
throws JSONException {
JSONObject announcement = new JSONObject(topologyAnnouncementJSON);
final String ownerId = announcement.getString("ownerId");
final int protocolVersion;
if (!announcement.has("protocolVersion")) {
protocolVersion = -1;
} else {
protocolVersion = announcement.getInt("protocolVersion");
}
final Announcement result = new Announcement(ownerId, protocolVersion);
if (announcement.has("backoffInterval")) {
long backoffInterval = announcement.getLong("backoffInterval");
result.backoffInterval = backoffInterval;
}
if (announcement.has("resetBackoff")) {
boolean resetBackoff = announcement.getBoolean("resetBackoff");
result.resetBackoff = resetBackoff;
}
if (announcement.has("loop") && announcement.getBoolean("loop")) {
result.setLoop(true);
return result;
}
final String localClusterViewJSON = announcement
.getString("localClusterView");
final ClusterView localClusterView = asClusterView(localClusterViewJSON);
final JSONArray subAnnouncements = announcement
.getJSONArray("topologyAnnouncements");
if (announcement.has("inherited")) {
final Boolean inherited = announcement.getBoolean("inherited");
result.inherited = inherited;
}
if (announcement.has("serverInfo")) {
String serverInfo = announcement.getString("serverInfo");
result.serverInfo = serverInfo;
}
result.setLocalCluster(localClusterView);
for (int i = 0; i < subAnnouncements.length(); i++) {
String subAnnouncementJSON = subAnnouncements.getString(i);