Small cleanup
This commit is contained in:
@ -14,7 +14,7 @@ import com.google.code.gossip.LocalGossipMember;
|
||||
*/
|
||||
abstract public class ActiveGossipThread implements Runnable {
|
||||
|
||||
private GossipManager _gossipManager;
|
||||
private final GossipManager _gossipManager;
|
||||
|
||||
private final AtomicBoolean _keepRunning;
|
||||
|
||||
@ -50,7 +50,7 @@ abstract public class ActiveGossipThread implements Runnable {
|
||||
/**
|
||||
* Abstract method which should be implemented by a subclass. This method should return a member
|
||||
* of the list to gossip with.
|
||||
*
|
||||
*
|
||||
* @param memberList
|
||||
* The list of members which are stored in the local list of members.
|
||||
* @return The chosen LocalGossipMember to gossip with.
|
||||
|
@ -24,24 +24,24 @@ import com.google.code.gossip.event.GossipListener;
|
||||
import com.google.code.gossip.event.GossipState;
|
||||
|
||||
public abstract class GossipManager extends Thread implements NotificationListener {
|
||||
|
||||
|
||||
public static final Logger LOGGER = Logger.getLogger(GossipManager.class);
|
||||
public static final int MAX_PACKET_SIZE = 102400;
|
||||
|
||||
private ConcurrentSkipListMap<LocalGossipMember,GossipState> members;
|
||||
private LocalGossipMember _me;
|
||||
private GossipSettings _settings;
|
||||
private AtomicBoolean _gossipServiceRunning;
|
||||
private ExecutorService _gossipThreadExecutor;
|
||||
private Class<? extends PassiveGossipThread> _passiveGossipThreadClass;
|
||||
private PassiveGossipThread passiveGossipThread;
|
||||
private Class<? extends ActiveGossipThread> _activeGossipThreadClass;
|
||||
private final ConcurrentSkipListMap<LocalGossipMember,GossipState> members;
|
||||
private final LocalGossipMember _me;
|
||||
private final GossipSettings _settings;
|
||||
private final AtomicBoolean _gossipServiceRunning;
|
||||
private final Class<? extends PassiveGossipThread> _passiveGossipThreadClass;
|
||||
private final Class<? extends ActiveGossipThread> _activeGossipThreadClass;
|
||||
private final GossipListener listener;
|
||||
private ActiveGossipThread activeGossipThread;
|
||||
private GossipListener listener;
|
||||
private PassiveGossipThread passiveGossipThread;
|
||||
private ExecutorService _gossipThreadExecutor;
|
||||
|
||||
public GossipManager(Class<? extends PassiveGossipThread> passiveGossipThreadClass,
|
||||
Class<? extends ActiveGossipThread> activeGossipThreadClass, String address, int port,
|
||||
String id, GossipSettings settings, ArrayList<GossipMember> gossipMembers,
|
||||
String id, GossipSettings settings, List<GossipMember> gossipMembers,
|
||||
GossipListener listener) {
|
||||
_passiveGossipThreadClass = passiveGossipThreadClass;
|
||||
_activeGossipThreadClass = activeGossipThreadClass;
|
||||
@ -87,7 +87,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
listener.gossipEvent(m, GossipState.UP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GossipSettings getSettings() {
|
||||
return _settings;
|
||||
}
|
||||
@ -105,7 +105,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
public LocalGossipMember getMyself() {
|
||||
return _me;
|
||||
}
|
||||
|
||||
|
||||
public List<LocalGossipMember> getDeadList() {
|
||||
List<LocalGossipMember> up = new ArrayList<>();
|
||||
for (Entry<LocalGossipMember, GossipState> entry : members.entrySet()){
|
||||
@ -119,8 +119,6 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
/**
|
||||
* Starts the client. Specifically, start the various cycles for this protocol. Start the gossip
|
||||
* thread and start the receiver thread.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void run() {
|
||||
for (LocalGossipMember member : members.keySet()) {
|
||||
@ -160,7 +158,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
activeGossipThread.shutdown();
|
||||
try {
|
||||
boolean result = _gossipThreadExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS);
|
||||
if (result == false){
|
||||
if (!result){
|
||||
LOGGER.error("executor shutdown timed out");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -26,13 +26,13 @@ import com.google.code.gossip.RemoteGossipMember;
|
||||
* determine the incoming message.
|
||||
*/
|
||||
abstract public class PassiveGossipThread implements Runnable {
|
||||
|
||||
|
||||
public static final Logger LOGGER = Logger.getLogger(PassiveGossipThread.class);
|
||||
|
||||
/** The socket used for the passive thread of the gossip service. */
|
||||
private DatagramSocket _server;
|
||||
|
||||
private GossipManager _gossipManager;
|
||||
private final GossipManager _gossipManager;
|
||||
|
||||
private AtomicBoolean _keepRunning;
|
||||
|
||||
@ -73,7 +73,7 @@ abstract public class PassiveGossipThread implements Runnable {
|
||||
// A package larger than this would not be possible to be send from a GossipService,
|
||||
// since this is check before sending the message.
|
||||
// This could normally only occur when the list of members is very big,
|
||||
// or when the packet is misformed, and the first 4 bytes is not the right in anymore.
|
||||
// or when the packet is malformed, and the first 4 bytes is not the right in anymore.
|
||||
// For this reason we regards the message.
|
||||
if (packet_length <= GossipManager.MAX_PACKET_SIZE) {
|
||||
byte[] json_bytes = new byte[packet_length];
|
||||
@ -84,7 +84,7 @@ abstract public class PassiveGossipThread implements Runnable {
|
||||
GossipService.LOGGER.debug("Received message (" + packet_length + " bytes): "
|
||||
+ receivedMessage);
|
||||
try {
|
||||
ArrayList<GossipMember> remoteGossipMembers = new ArrayList<GossipMember>();
|
||||
List<GossipMember> remoteGossipMembers = new ArrayList<>();
|
||||
RemoteGossipMember senderMember = null;
|
||||
GossipService.LOGGER.debug("Received member list:");
|
||||
JSONArray jsonArray = new JSONArray(receivedMessage);
|
||||
@ -136,7 +136,7 @@ abstract public class PassiveGossipThread implements Runnable {
|
||||
|
||||
/**
|
||||
* Abstract method for merging the local and remote list.
|
||||
*
|
||||
*
|
||||
* @param gossipManager
|
||||
* The GossipManager for retrieving the local members and dead members list.
|
||||
* @param senderMember
|
||||
@ -147,4 +147,4 @@ abstract public class PassiveGossipThread implements Runnable {
|
||||
*/
|
||||
abstract protected void mergeLists(GossipManager gossipManager, RemoteGossipMember senderMember,
|
||||
List<GossipMember> remoteList);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
* Merge remote list (received from peer), and our local member list. Simply, we must update the
|
||||
* heartbeats that the remote list has with our list. Also, some additional logic is needed to
|
||||
* make sure we have not timed out a member and then immediately received a list with that member.
|
||||
*
|
||||
*
|
||||
* @param gossipManager
|
||||
* @param senderMember
|
||||
* @param remoteList
|
||||
*/
|
||||
protected void mergeLists(GossipManager gossipManager, RemoteGossipMember senderMember,
|
||||
@ -92,6 +94,6 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ abstract public class SendMembersActiveGossipThread extends ActiveGossipThread {
|
||||
GossipService.LOGGER.debug("Sending memberlist to " + dest + ":" + member.getPort());
|
||||
jsonArray.put(me.toJSONObject());
|
||||
GossipService.LOGGER.debug(me);
|
||||
for (int i = 0; i < memberList.size(); i++) {
|
||||
LocalGossipMember other = memberList.get(i);
|
||||
for (LocalGossipMember other : memberList) {
|
||||
jsonArray.put(other.toJSONObject());
|
||||
GossipService.LOGGER.debug(other);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import com.google.code.gossip.manager.impl.SendMembersActiveGossipThread;
|
||||
public class RandomActiveGossipThread extends SendMembersActiveGossipThread {
|
||||
|
||||
/** The Random used for choosing a member to gossip with. */
|
||||
private Random _random;
|
||||
private final Random _random;
|
||||
|
||||
public RandomActiveGossipThread(GossipManager gossipManager) {
|
||||
super(gossipManager);
|
||||
@ -21,7 +21,7 @@ public class RandomActiveGossipThread extends SendMembersActiveGossipThread {
|
||||
/**
|
||||
* [The selectToSend() function.] Find a random peer from the local membership list. In the case
|
||||
* where this client is the only member in the list, this method will return null.
|
||||
*
|
||||
*
|
||||
* @return Member random member if list is greater than 1, null otherwise
|
||||
*/
|
||||
protected LocalGossipMember selectPartner(List<LocalGossipMember> memberList) {
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.google.code.gossip.manager.random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.code.gossip.GossipMember;
|
||||
import com.google.code.gossip.GossipSettings;
|
||||
import com.google.code.gossip.event.GossipListener;
|
||||
import com.google.code.gossip.manager.GossipManager;
|
||||
import com.google.code.gossip.manager.impl.OnlyProcessReceivedPassiveGossipThread;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RandomGossipManager extends GossipManager {
|
||||
public RandomGossipManager(String address, int port, String id, GossipSettings settings,
|
||||
ArrayList<GossipMember> gossipMembers, GossipListener listener) {
|
||||
List<GossipMember> gossipMembers, GossipListener listener) {
|
||||
super(OnlyProcessReceivedPassiveGossipThread.class, RandomActiveGossipThread.class, address,
|
||||
port, id, settings, gossipMembers, listener);
|
||||
}
|
||||
|
Reference in New Issue
Block a user