Logging cleanup
This commit is contained in:
@ -30,7 +30,7 @@ public class GossipService {
|
||||
public GossipService(StartupSettings startupSettings) throws InterruptedException,
|
||||
UnknownHostException {
|
||||
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
|
||||
startupSettings.getLogLevel(), startupSettings.getGossipMembers(), startupSettings
|
||||
startupSettings.getGossipMembers(), startupSettings
|
||||
.getGossipSettings(), null);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class GossipService {
|
||||
* @throws InterruptedException
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public GossipService(String ipAddress, int port, String id, int logLevel,
|
||||
public GossipService(String ipAddress, int port, String id,
|
||||
List<GossipMember> gossipMembers, GossipSettings settings, GossipListener listener)
|
||||
throws InterruptedException, UnknownHostException {
|
||||
_gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers, listener);
|
||||
|
@ -1,27 +0,0 @@
|
||||
package com.google.code.gossip;
|
||||
|
||||
public class LogLevel {
|
||||
|
||||
public static final String CONFIG_ERROR = "ERROR";
|
||||
|
||||
public static final String CONFIG_INFO = "INFO";
|
||||
|
||||
public static final String CONFIG_DEBUG = "DEBUG";
|
||||
|
||||
public static final int ERROR = 1;
|
||||
|
||||
public static final int INFO = 2;
|
||||
|
||||
public static final int DEBUG = 3;
|
||||
|
||||
public static int fromString(String logLevel) {
|
||||
if (logLevel.equals(CONFIG_ERROR))
|
||||
return ERROR;
|
||||
else if (logLevel.equals(CONFIG_INFO))
|
||||
return INFO;
|
||||
else if (logLevel.equals(CONFIG_DEBUG))
|
||||
return DEBUG;
|
||||
else
|
||||
return INFO;
|
||||
}
|
||||
}
|
@ -22,9 +22,6 @@ public class StartupSettings {
|
||||
/** The port to start the gossip service on. */
|
||||
private int _port;
|
||||
|
||||
/** The logging level of the gossip service. */
|
||||
private int _logLevel;
|
||||
|
||||
/** The gossip settings used at startup. */
|
||||
private final GossipSettings _gossipSettings;
|
||||
|
||||
@ -38,7 +35,7 @@ public class StartupSettings {
|
||||
* The port to start the service on.
|
||||
*/
|
||||
public StartupSettings(int port, int logLevel) {
|
||||
this(port, logLevel, new GossipSettings());
|
||||
this(port, new GossipSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,9 +44,8 @@ public class StartupSettings {
|
||||
* @param port
|
||||
* The port to start the service on.
|
||||
*/
|
||||
public StartupSettings(int port, int logLevel, GossipSettings gossipSettings) {
|
||||
public StartupSettings(int port, GossipSettings gossipSettings) {
|
||||
_port = port;
|
||||
_logLevel = logLevel;
|
||||
_gossipSettings = gossipSettings;
|
||||
_gossipMembers = new ArrayList<>();
|
||||
}
|
||||
@ -73,25 +69,6 @@ public class StartupSettings {
|
||||
return _port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log level of the gossip service.
|
||||
*
|
||||
* @param logLevel
|
||||
* The log level({LogLevel}).
|
||||
*/
|
||||
public void setLogLevel(int logLevel) {
|
||||
_logLevel = logLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log level of the gossip service.
|
||||
*
|
||||
* @return The log level.
|
||||
*/
|
||||
public int getLogLevel() {
|
||||
return _logLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the GossipSettings.
|
||||
*
|
||||
@ -149,20 +126,14 @@ public class StartupSettings {
|
||||
// Now get the port number.
|
||||
int port = jsonObject.getInt("port");
|
||||
|
||||
// Get the log level from the config file.
|
||||
int logLevel = LogLevel.fromString(jsonObject.getString("log_level"));
|
||||
|
||||
// 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");
|
||||
|
||||
System.out.println("Config [port: " + port + ", log_level: " + logLevel + ", gossip_interval: "
|
||||
+ gossipInterval + ", cleanup_interval: " + cleanupInterval + "]");
|
||||
|
||||
// Initiate the settings with the port number.
|
||||
StartupSettings settings = new StartupSettings(port, logLevel, new GossipSettings(
|
||||
StartupSettings settings = new StartupSettings(port, new GossipSettings(
|
||||
gossipInterval, cleanupInterval));
|
||||
|
||||
// Now iterate over the members from the config file and add them to the settings.
|
||||
|
@ -8,7 +8,6 @@ import java.util.List;
|
||||
import com.google.code.gossip.GossipMember;
|
||||
import com.google.code.gossip.GossipService;
|
||||
import com.google.code.gossip.GossipSettings;
|
||||
import com.google.code.gossip.LogLevel;
|
||||
import com.google.code.gossip.RemoteGossipMember;
|
||||
|
||||
/**
|
||||
@ -59,7 +58,7 @@ public class GossipExample extends Thread {
|
||||
// dead list handling.
|
||||
for (GossipMember member : startupMembers) {
|
||||
GossipService gossipService = new GossipService(myIpAddress, member.getPort(), "",
|
||||
LogLevel.DEBUG, startupMembers, settings, null);
|
||||
startupMembers, settings, null);
|
||||
clients.add(gossipService);
|
||||
gossipService.start();
|
||||
sleep(settings.getCleanupInterval() + 1000);
|
||||
|
@ -62,7 +62,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
this.listener = listener;
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
GossipService.LOGGER.info("Service has been shutdown...");
|
||||
GossipService.LOGGER.debug("Service has been shutdown...");
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -74,7 +74,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
@Override
|
||||
public void handleNotification(Notification notification, Object handback) {
|
||||
LocalGossipMember deadMember = (LocalGossipMember) notification.getUserData();
|
||||
GossipService.LOGGER.info("Dead member detected: " + deadMember);
|
||||
GossipService.LOGGER.debug("Dead member detected: " + deadMember);
|
||||
members.put(deadMember, GossipState.DOWN);
|
||||
if (listener != null) {
|
||||
listener.gossipEvent(deadMember, GossipState.DOWN);
|
||||
@ -138,13 +138,13 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
GossipService.LOGGER.info("The GossipService is started.");
|
||||
GossipService.LOGGER.debug("The GossipService is started.");
|
||||
while (_gossipServiceRunning.get()) {
|
||||
try {
|
||||
// TODO
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
GossipService.LOGGER.info("The GossipClient was interrupted.");
|
||||
GossipService.LOGGER.warn("The GossipClient was interrupted.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ abstract public class PassiveGossipThread implements Runnable {
|
||||
SocketAddress socketAddress = new InetSocketAddress(_gossipManager.getMyself().getHost(),
|
||||
_gossipManager.getMyself().getPort());
|
||||
_server = new DatagramSocket(socketAddress);
|
||||
GossipService.LOGGER.info("Gossip service successfully initialized on port "
|
||||
GossipService.LOGGER.debug("Gossip service successfully initialized on port "
|
||||
+ _gossipManager.getMyself().getPort());
|
||||
GossipService.LOGGER.debug("I am " + _gossipManager.getMyself());
|
||||
} catch (SocketException ex) {
|
||||
GossipService.LOGGER.error(ex);
|
||||
GossipService.LOGGER.warn(ex);
|
||||
_server = null;
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
// gossipManager.getMemberList().add(newLocalMember);
|
||||
gossipManager.createOrRevivieMember(newLocalMember);
|
||||
newLocalMember.startTimeoutTimer();
|
||||
GossipService.LOGGER.info("Removed remote member " + remoteMember.getAddress()
|
||||
GossipService.LOGGER.debug("Removed remote member " + remoteMember.getAddress()
|
||||
+ " from dead list and added to local member list.");
|
||||
}
|
||||
} else {
|
||||
@ -86,7 +86,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
gossipManager, gossipManager.getSettings().getCleanupInterval());
|
||||
gossipManager.createOrRevivieMember(newLocalMember);
|
||||
newLocalMember.startTimeoutTimer();
|
||||
GossipService.LOGGER.info("Added new remote member " + remoteMember.getAddress()
|
||||
GossipService.LOGGER.debug("Added new remote member " + remoteMember.getAddress()
|
||||
+ " to local member list.");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user