Add a logger
This commit is contained in:
@ -10,12 +10,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationListener;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.code.gossip.GossipMember;
|
||||
import com.google.code.gossip.GossipService;
|
||||
import com.google.code.gossip.GossipSettings;
|
||||
import com.google.code.gossip.LocalGossipMember;
|
||||
|
||||
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) */
|
||||
public static final int MAX_PACKET_SIZE = 102400;
|
||||
|
||||
@ -153,9 +158,11 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
activeGossipThread.shutdown();
|
||||
try {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e);
|
||||
}
|
||||
_gossipServiceRunning.set(false);
|
||||
}
|
||||
|
@ -25,42 +25,24 @@ abstract public class SendMembersActiveGossipThread extends ActiveGossipThread {
|
||||
*/
|
||||
protected void sendMembershipList(LocalGossipMember me, ArrayList<LocalGossipMember> memberList) {
|
||||
GossipService.LOGGER.debug("Send sendMembershipList() is called.");
|
||||
|
||||
// Increase the heartbeat of myself by 1.
|
||||
me.setHeartbeat(me.getHeartbeat() + 1);
|
||||
|
||||
synchronized (memberList) {
|
||||
try {
|
||||
LocalGossipMember member = selectPartner(memberList);
|
||||
|
||||
if (member != null) {
|
||||
InetAddress dest = InetAddress.getByName(member.getHost());
|
||||
|
||||
// Create a StringBuffer for the JSON message.
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
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());
|
||||
GossipService.LOGGER.debug(me);
|
||||
|
||||
// Then write the others.
|
||||
for (int i = 0; i < memberList.size(); i++) {
|
||||
LocalGossipMember other = memberList.get(i);
|
||||
// Append the JSON representation of the member to the buffer.
|
||||
jsonArray.put(other.toJSONObject());
|
||||
GossipService.LOGGER.debug(other);
|
||||
}
|
||||
GossipService.LOGGER.debug("---------------------");
|
||||
|
||||
// Write the objects to a byte array.
|
||||
byte[] json_bytes = jsonArray.toString().getBytes();
|
||||
|
||||
int packet_length = json_bytes.length;
|
||||
|
||||
if (packet_length < GossipManager.MAX_PACKET_SIZE) {
|
||||
|
||||
// Convert the packet length to the byte representation of the int.
|
||||
byte[] length_bytes = new byte[4];
|
||||
length_bytes[0] = (byte) (packet_length >> 24);
|
||||
|
Reference in New Issue
Block a user