From d191c7cb6d37039d2582fda1589348c3d01be0d0 Mon Sep 17 00:00:00 2001 From: Edward Capriolo Date: Tue, 3 May 2016 11:15:26 -0400 Subject: [PATCH] Cluster name was null at this context --- .../google/code/gossip/StartupSettings.java | 25 +++++++------------ .../gossip/manager/PassiveGossipThread.java | 3 +++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/google/code/gossip/StartupSettings.java b/src/main/java/com/google/code/gossip/StartupSettings.java index 6d9d43c..53ed725 100644 --- a/src/main/java/com/google/code/gossip/StartupSettings.java +++ b/src/main/java/com/google/code/gossip/StartupSettings.java @@ -62,8 +62,8 @@ public class StartupSettings { * @param logLevel * unused */ - public StartupSettings(String id, int port, int logLevel) { - this(id, port, new GossipSettings()); + public StartupSettings(String id, int port, int logLevel, String cluster) { + this(id, port, new GossipSettings(), cluster); } /** @@ -74,10 +74,11 @@ public class StartupSettings { * @param port * The port to start the service on. */ - public StartupSettings(String id, int port, GossipSettings gossipSettings) { + public StartupSettings(String id, int port, GossipSettings gossipSettings, String cluster) { this.id = id; this.port = port; this.gossipSettings = gossipSettings; + this.setCluster(cluster); gossipMembers = new ArrayList<>(); } @@ -179,25 +180,17 @@ public class StartupSettings { } } - - // Lets parse the String as JSON. JSONObject jsonObject = new JSONArray(buffer.toString()).getJSONObject(0); - - // Now get the port number. int port = jsonObject.getInt("port"); - - // Get the id to be used String id = jsonObject.getString("id"); - - // Get the gossip_interval from the config file. int gossipInterval = jsonObject.getInt("gossip_interval"); - - // Get the cleanup_interval from the config file. int cleanupInterval = jsonObject.getInt("cleanup_interval"); - - // Initiate the settings with the port number. + String cluster = jsonObject.getString("cluster"); + if (cluster == null){ + throw new IllegalArgumentException("cluster was null. It is required"); + } StartupSettings settings = new StartupSettings(id, port, new GossipSettings(gossipInterval, - cleanupInterval)); + cleanupInterval), cluster); // Now iterate over the members from the config file and add them to the settings. String configMembersDetails = "Config-members ["; diff --git a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java index e8eb034..b05a780 100644 --- a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java @@ -65,6 +65,9 @@ abstract public class PassiveGossipThread implements Runnable { + gossipManager.getMyself().getPort()); GossipService.LOGGER.debug("I am " + gossipManager.getMyself()); cluster = gossipManager.getMyself().getClusterName(); + if (cluster == null){ + throw new IllegalArgumentException("cluster was null"); + } } catch (SocketException ex) { GossipService.LOGGER.warn(ex); throw new RuntimeException(ex);