setMaster(null, false);
}
try {
// first we query all servers to know who is the current master
for (Iterator iter = serversToQuery.iterator(); iter.hasNext();) {
Server server = (Server)iter.next();
LOGGER.debug("querying "+server);
Server master = null;
try {
master = ServerServicesProvider.get(server).getServerManagementService().getMaster();
} catch (Exception ex) {
LOGGER.debug("a problem occured while querying "+server+" to know the master: ignoring");
continue;
}
synchronized (this) {
if (_master != null) {
LOGGER.info("a new master has been elected during our own election process: "+_master);
return;
}
}
try {
if (master != null) {
if (master.getId() < _localServer.getId()) {
if (!master.equals(server)) {
LOGGER.debug("master found wasn't previously queried: "+master);
if (ServerServicesProvider.get(master).getServerManagementService().ping()) {
LOGGER.debug("it seems that we didn't know master before, but it is up, we can synchronize with it: "+master);
syncAndRegister(master);
return;
} else {
LOGGER.debug(master+" is down, electing "+server);
markServerDown(server);
elect(server);
return;
}
} else {
LOGGER.info("found master: "+master);
syncAndRegister(master);
return;
}
} else if (server.getId() < _localServer.getId()) {
LOGGER.warn("a higher server ("+server+") thought that the master was a lower one: "+master);
LOGGER.info("electing "+server);
elect(server);
return;
} else if (master.getId() == _localServer.getId()) {
LOGGER.debug("another server already thought we were the master, we just take our place back");
} else {
LOGGER.debug("a lower server was the master, we take its place: "+master);
replaceMaster(master);
return;