Cluster name was null at this context

This commit is contained in:
Edward Capriolo
2016-05-03 11:15:26 -04:00
parent a7f90aae08
commit d191c7cb6d
2 changed files with 12 additions and 16 deletions

View File

@ -62,8 +62,8 @@ public class StartupSettings {
* @param logLevel * @param logLevel
* unused * unused
*/ */
public StartupSettings(String id, int port, int logLevel) { public StartupSettings(String id, int port, int logLevel, String cluster) {
this(id, port, new GossipSettings()); this(id, port, new GossipSettings(), cluster);
} }
/** /**
@ -74,10 +74,11 @@ public class StartupSettings {
* @param port * @param port
* The port to start the service on. * 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.id = id;
this.port = port; this.port = port;
this.gossipSettings = gossipSettings; this.gossipSettings = gossipSettings;
this.setCluster(cluster);
gossipMembers = new ArrayList<>(); gossipMembers = new ArrayList<>();
} }
@ -179,25 +180,17 @@ public class StartupSettings {
} }
} }
// Lets parse the String as JSON.
JSONObject jsonObject = new JSONArray(buffer.toString()).getJSONObject(0); JSONObject jsonObject = new JSONArray(buffer.toString()).getJSONObject(0);
// Now get the port number.
int port = jsonObject.getInt("port"); int port = jsonObject.getInt("port");
// Get the id to be used
String id = jsonObject.getString("id"); String id = jsonObject.getString("id");
// Get the gossip_interval from the config file.
int gossipInterval = jsonObject.getInt("gossip_interval"); int gossipInterval = jsonObject.getInt("gossip_interval");
// Get the cleanup_interval from the config file.
int cleanupInterval = jsonObject.getInt("cleanup_interval"); int cleanupInterval = jsonObject.getInt("cleanup_interval");
String cluster = jsonObject.getString("cluster");
// Initiate the settings with the port number. if (cluster == null){
throw new IllegalArgumentException("cluster was null. It is required");
}
StartupSettings settings = new StartupSettings(id, port, new GossipSettings(gossipInterval, 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. // Now iterate over the members from the config file and add them to the settings.
String configMembersDetails = "Config-members ["; String configMembersDetails = "Config-members [";

View File

@ -65,6 +65,9 @@ abstract public class PassiveGossipThread implements Runnable {
+ gossipManager.getMyself().getPort()); + gossipManager.getMyself().getPort());
GossipService.LOGGER.debug("I am " + gossipManager.getMyself()); GossipService.LOGGER.debug("I am " + gossipManager.getMyself());
cluster = gossipManager.getMyself().getClusterName(); cluster = gossipManager.getMyself().getClusterName();
if (cluster == null){
throw new IllegalArgumentException("cluster was null");
}
} catch (SocketException ex) { } catch (SocketException ex) {
GossipService.LOGGER.warn(ex); GossipService.LOGGER.warn(ex);
throw new RuntimeException(ex); throw new RuntimeException(ex);