Merge pull request #14 from irstevenson/doc-updates-fileconfig-test
Added test for `StartupSettings` and documentation of use - in `README.md`
This commit is contained in:
@ -29,7 +29,7 @@ public class GossipService {
|
||||
*/
|
||||
public GossipService(StartupSettings startupSettings) throws InterruptedException,
|
||||
UnknownHostException {
|
||||
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
|
||||
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), startupSettings.getId(),
|
||||
startupSettings.getGossipMembers(), startupSettings
|
||||
.getGossipSettings(), null);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -18,6 +19,10 @@ import org.json.JSONObject;
|
||||
* @author harmenw
|
||||
*/
|
||||
public class StartupSettings {
|
||||
private static final Logger log = Logger.getLogger(StartupSettings.class);
|
||||
|
||||
/** The id to use fo the service */
|
||||
private String _id;
|
||||
|
||||
/** The port to start the gossip service on. */
|
||||
private int _port;
|
||||
@ -31,25 +36,51 @@ public class StartupSettings {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id
|
||||
* The id to be used for this service
|
||||
* @param port
|
||||
* The port to start the service on.
|
||||
* @param logLevel
|
||||
* unused
|
||||
*/
|
||||
public StartupSettings(int port, int logLevel) {
|
||||
this(port, new GossipSettings());
|
||||
public StartupSettings(String id, int port, int logLevel) {
|
||||
this(id, port, new GossipSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id
|
||||
* The id to be used for this service
|
||||
* @param port
|
||||
* The port to start the service on.
|
||||
*/
|
||||
public StartupSettings(int port, GossipSettings gossipSettings) {
|
||||
public StartupSettings(String id, int port, GossipSettings gossipSettings) {
|
||||
_id = id;
|
||||
_port = port;
|
||||
_gossipSettings = gossipSettings;
|
||||
_gossipMembers = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the id to be used for this service.
|
||||
*
|
||||
* @param id
|
||||
* The id for this service.
|
||||
*/
|
||||
public void setId( String id ) {
|
||||
_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id for this service.
|
||||
*
|
||||
* @return the service's id.
|
||||
*/
|
||||
public String getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the port of the gossip service.
|
||||
*
|
||||
@ -126,6 +157,9 @@ public class StartupSettings {
|
||||
// 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");
|
||||
|
||||
@ -133,22 +167,22 @@ public class StartupSettings {
|
||||
int cleanupInterval = jsonObject.getInt("cleanup_interval");
|
||||
|
||||
// Initiate the settings with the port number.
|
||||
StartupSettings settings = new StartupSettings(port, new GossipSettings(
|
||||
StartupSettings settings = new StartupSettings(id, port, new GossipSettings(
|
||||
gossipInterval, cleanupInterval));
|
||||
|
||||
// Now iterate over the members from the config file and add them to the settings.
|
||||
System.out.print("Config-members [");
|
||||
String configMembersDetails = "Config-members [";
|
||||
JSONArray membersJSON = jsonObject.getJSONArray("members");
|
||||
for (int i = 0; i < membersJSON.length(); i++) {
|
||||
JSONObject memberJSON = membersJSON.getJSONObject(i);
|
||||
RemoteGossipMember member = new RemoteGossipMember(memberJSON.getString("host"),
|
||||
memberJSON.getInt("port"), "");
|
||||
settings.addGossipMember(member);
|
||||
System.out.print(member.getAddress());
|
||||
configMembersDetails += member.getAddress();
|
||||
if (i < (membersJSON.length() - 1))
|
||||
System.out.print(", ");
|
||||
configMembersDetails += ", ";
|
||||
}
|
||||
System.out.println("]");
|
||||
log.info( configMembersDetails + "]" );
|
||||
|
||||
// Return the created settings object.
|
||||
return settings;
|
||||
|
Reference in New Issue
Block a user