60 lines
1.9 KiB
Java
60 lines
1.9 KiB
Java
package com.google.code.gossip.manager;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import com.google.code.gossip.GossipService;
|
|
import com.google.code.gossip.LocalGossipMember;
|
|
|
|
/**
|
|
* [The active thread: periodically send gossip request.]
|
|
* The class handles gossiping the membership list.
|
|
* This information is important to maintaining a common
|
|
* state among all the nodes, and is important for detecting
|
|
* failures.
|
|
*/
|
|
abstract public class ActiveGossipThread implements Runnable {
|
|
|
|
private GossipManager _gossipManager;
|
|
|
|
private AtomicBoolean _keepRunning;
|
|
|
|
public ActiveGossipThread(GossipManager gossipManager) {
|
|
_gossipManager = gossipManager;
|
|
|
|
_keepRunning = new AtomicBoolean(true);
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
while(_keepRunning.get()) {
|
|
try {
|
|
TimeUnit.MILLISECONDS.sleep(_gossipManager.getSettings().getGossipInterval());
|
|
sendMembershipList(_gossipManager.getMyself(), _gossipManager.getMemberList());
|
|
} catch (InterruptedException e) {
|
|
// This membership thread was interrupted externally, shutdown
|
|
GossipService.debug("The ActiveGossipThread was interrupted externally, shutdown.");
|
|
e.printStackTrace();
|
|
_keepRunning.set(false);
|
|
}
|
|
}
|
|
|
|
_keepRunning = null;
|
|
}
|
|
|
|
/**
|
|
* Performs the sending of the membership list, after we have
|
|
* incremented our own heartbeat.
|
|
*/
|
|
abstract protected void sendMembershipList(LocalGossipMember me, ArrayList<LocalGossipMember> memberList);
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
abstract protected LocalGossipMember selectPartner(ArrayList<LocalGossipMember> memberList);
|
|
}
|