correcting task random candidate election logic

4.x.x
Ace 4 years ago
parent 7734dbd654
commit cfe206b32c

@ -208,12 +208,17 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
Map<String, ServerContext> servers = heartBeatDAO.getActiveServerDetails(elapsedTimeInSeconds); Map<String, ServerContext> servers = heartBeatDAO.getActiveServerDetails(elapsedTimeInSeconds);
if (servers != null && !servers.isEmpty()) { if (servers != null && !servers.isEmpty()) {
ElectedCandidate presentCandidate = heartBeatDAO.retrieveCandidate(); ElectedCandidate presentCandidate = heartBeatDAO.retrieveCandidate();
if (presentCandidate != null && if (presentCandidate != null) {
presentCandidate.getTimeOfElection().before(new Timestamp(System.currentTimeMillis() //if candidate is older than stipulated elapsed-time, purge and re-elect
- TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)))) { if (presentCandidate.getTimeOfElection().before(new Timestamp(System.currentTimeMillis()
heartBeatDAO.purgeCandidates(); - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)))) {
heartBeatDAO.purgeCandidates();
electCandidate(servers);
}
} else {
//first time execution, elect if not present
electCandidate(servers);
} }
electCandidate(servers);
HeartBeatBeaconDAOFactory.commitTransaction(); HeartBeatBeaconDAOFactory.commitTransaction();
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {

Loading…
Cancel
Save