Add a logger

This commit is contained in:
Edward Capriolo
2015-01-17 18:35:45 -05:00
parent 2585d06499
commit a94ce621db
2 changed files with 9 additions and 20 deletions

View File

@ -10,12 +10,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.management.Notification; import javax.management.Notification;
import javax.management.NotificationListener; import javax.management.NotificationListener;
import org.apache.log4j.Logger;
import com.google.code.gossip.GossipMember; import com.google.code.gossip.GossipMember;
import com.google.code.gossip.GossipService; import com.google.code.gossip.GossipService;
import com.google.code.gossip.GossipSettings; import com.google.code.gossip.GossipSettings;
import com.google.code.gossip.LocalGossipMember; import com.google.code.gossip.LocalGossipMember;
public abstract class GossipManager extends Thread implements NotificationListener { public abstract class GossipManager extends Thread implements NotificationListener {
public static final Logger LOGGER = Logger.getLogger(GossipManager.class);
/** The maximal number of bytes the packet with the GOSSIP may be. (Default is 100 kb) */ /** The maximal number of bytes the packet with the GOSSIP may be. (Default is 100 kb) */
public static final int MAX_PACKET_SIZE = 102400; public static final int MAX_PACKET_SIZE = 102400;
@ -153,9 +158,11 @@ public abstract class GossipManager extends Thread implements NotificationListen
activeGossipThread.shutdown(); activeGossipThread.shutdown();
try { try {
boolean result = _gossipThreadExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS); boolean result = _gossipThreadExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS);
System.err.println("Terminate retuned " + result); if (result == false){
LOGGER.error("executor shutdown timed out");
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); LOGGER.error(e);
} }
_gossipServiceRunning.set(false); _gossipServiceRunning.set(false);
} }

View File

@ -25,42 +25,24 @@ abstract public class SendMembersActiveGossipThread extends ActiveGossipThread {
*/ */
protected void sendMembershipList(LocalGossipMember me, ArrayList<LocalGossipMember> memberList) { protected void sendMembershipList(LocalGossipMember me, ArrayList<LocalGossipMember> memberList) {
GossipService.LOGGER.debug("Send sendMembershipList() is called."); GossipService.LOGGER.debug("Send sendMembershipList() is called.");
// Increase the heartbeat of myself by 1.
me.setHeartbeat(me.getHeartbeat() + 1); me.setHeartbeat(me.getHeartbeat() + 1);
synchronized (memberList) { synchronized (memberList) {
try { try {
LocalGossipMember member = selectPartner(memberList); LocalGossipMember member = selectPartner(memberList);
if (member != null) { if (member != null) {
InetAddress dest = InetAddress.getByName(member.getHost()); InetAddress dest = InetAddress.getByName(member.getHost());
// Create a StringBuffer for the JSON message.
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
GossipService.LOGGER.debug("Sending memberlist to " + dest + ":" + member.getPort()); GossipService.LOGGER.debug("Sending memberlist to " + dest + ":" + member.getPort());
GossipService.LOGGER.debug("---------------------");
// First write myself, append the JSON representation of the member to the buffer.
jsonArray.put(me.toJSONObject()); jsonArray.put(me.toJSONObject());
GossipService.LOGGER.debug(me); GossipService.LOGGER.debug(me);
// Then write the others.
for (int i = 0; i < memberList.size(); i++) { for (int i = 0; i < memberList.size(); i++) {
LocalGossipMember other = memberList.get(i); LocalGossipMember other = memberList.get(i);
// Append the JSON representation of the member to the buffer.
jsonArray.put(other.toJSONObject()); jsonArray.put(other.toJSONObject());
GossipService.LOGGER.debug(other); GossipService.LOGGER.debug(other);
} }
GossipService.LOGGER.debug("---------------------");
// Write the objects to a byte array.
byte[] json_bytes = jsonArray.toString().getBytes(); byte[] json_bytes = jsonArray.toString().getBytes();
int packet_length = json_bytes.length; int packet_length = json_bytes.length;
if (packet_length < GossipManager.MAX_PACKET_SIZE) { if (packet_length < GossipManager.MAX_PACKET_SIZE) {
// Convert the packet length to the byte representation of the int. // Convert the packet length to the byte representation of the int.
byte[] length_bytes = new byte[4]; byte[] length_bytes = new byte[4];
length_bytes[0] = (byte) (packet_length >> 24); length_bytes[0] = (byte) (packet_length >> 24);