This commit is contained in:
Edward Capriolo
2015-01-17 18:17:38 -05:00
parent 6d70b28e82
commit 4506fe4a79
2 changed files with 76 additions and 68 deletions

View File

@ -7,40 +7,41 @@ import java.io.IOException;
import org.json.JSONException;
public class GossipRunner {
private StartupSettings _settings;
public static void main(String[] args) {
File configFile;
if (args.length == 1) {
configFile = new File("./"+args[0]);
} else {
configFile = new File("gossip.conf");
}
new GossipRunner(configFile);
}
public GossipRunner(File configFile) {
if (configFile != null && configFile.exists()) {
try {
System.out.println("Parsing the configuration file...");
_settings = StartupSettings.fromJSONFile(configFile);
GossipService gossipService = new GossipService(_settings);
System.out.println("Gossip service successfully inialized, let's start it...");
gossipService.start();
} catch (FileNotFoundException e) {
System.err.println("The given file is not found!");
} catch (JSONException e) {
System.err.println("The given file is not in the correct JSON format!");
} catch (IOException e) {
System.err.println("Could not read the configuration file: " + e.getMessage());
} catch (InterruptedException e) {
System.err.println("Error while starting the gossip service: " + e.getMessage());
}
} else {
System.out.println("The gossip.conf file is not found.\n\nEither specify the path to the startup settings file or place the gossip.json file in the same folder as the JAR file.");
}
}
private StartupSettings _settings;
public static void main(String[] args) {
File configFile;
if (args.length == 1) {
configFile = new File("./" + args[0]);
} else {
configFile = new File("gossip.conf");
}
new GossipRunner(configFile);
}
public GossipRunner(File configFile) {
if (configFile != null && configFile.exists()) {
try {
System.out.println("Parsing the configuration file...");
_settings = StartupSettings.fromJSONFile(configFile);
GossipService gossipService = new GossipService(_settings);
System.out.println("Gossip service successfully inialized, let's start it...");
gossipService.start();
} catch (FileNotFoundException e) {
System.err.println("The given file is not found!");
} catch (JSONException e) {
System.err.println("The given file is not in the correct JSON format!");
} catch (IOException e) {
System.err.println("Could not read the configuration file: " + e.getMessage());
} catch (InterruptedException e) {
System.err.println("Error while starting the gossip service: " + e.getMessage());
}
} else {
System.out
.println("The gossip.conf file is not found.\n\nEither specify the path to the startup settings file or place the gossip.json file in the same folder as the JAR file.");
}
}
}

View File

@ -15,37 +15,45 @@ import com.google.code.gossip.manager.random.RandomGossipManager;
* @author joshclemm, harmenw
*/
public class GossipService {
public static final Logger LOGGER = Logger.getLogger(GossipService.class);
private GossipManager _gossipManager;
/**
* Constructor with the default settings.
* @throws InterruptedException
* @throws UnknownHostException
*/
public GossipService(StartupSettings startupSettings) throws InterruptedException, UnknownHostException {
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "", startupSettings.getLogLevel(), startupSettings.getGossipMembers(), startupSettings.getGossipSettings());
}
/**
* Setup the client's lists, gossiping parameters, and parse the startup config file.
* @throws SocketException
* @throws InterruptedException
* @throws UnknownHostException
*/
public GossipService(String ipAddress, int port, String id, int logLevel, ArrayList<GossipMember> gossipMembers, GossipSettings settings) throws InterruptedException, UnknownHostException {
_gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers);
}
public void start() {
_gossipManager.start();
}
public void shutdown() {
_gossipManager.shutdown();
}
public static final Logger LOGGER = Logger.getLogger(GossipService.class);
private GossipManager _gossipManager;
/**
* Constructor with the default settings.
*
* @throws InterruptedException
* @throws UnknownHostException
*/
public GossipService(StartupSettings startupSettings) throws InterruptedException,
UnknownHostException {
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
startupSettings.getLogLevel(), startupSettings.getGossipMembers(), startupSettings
.getGossipSettings());
}
/**
* Setup the client's lists, gossiping parameters, and parse the startup config file.
*
* @throws SocketException
* @throws InterruptedException
* @throws UnknownHostException
*/
public GossipService(String ipAddress, int port, String id, int logLevel,
ArrayList<GossipMember> gossipMembers, GossipSettings settings)
throws InterruptedException, UnknownHostException {
_gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers);
}
public void start() {
_gossipManager.start();
}
public void shutdown() {
_gossipManager.shutdown();
}
public GossipManager get_gossipManager() {
return _gossipManager;
}
@ -53,6 +61,5 @@ public class GossipService {
public void set_gossipManager(GossipManager _gossipManager) {
this._gossipManager = _gossipManager;
}
}