correcting task random candidate election logic

revert-70ac1926
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
if (presentCandidate.getTimeOfElection().before(new Timestamp(System.currentTimeMillis()
- TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)))) { - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)))) {
heartBeatDAO.purgeCandidates(); 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