@Override public synchronized boolean handleStartElectionRequest(L2StateMessage msg) { Assert.assertEquals(L2StateMessage.START_ELECTION, msg.getType()); if (state == ELECTION_IN_PROGRESS && (myVote.isANewCandidate() || !msg.getEnrollment().isANewCandidate())) { // Another node is also joining in the election process, Cast its vote and notify my vote // Note : WE dont want to do this for new candidates when we are not new. Enrollment vote = msg.getEnrollment(); Enrollment old = votes.put(vote.getNodeID(), vote); boolean sendResponse = msg.inResponseTo().isNull(); if (old != null && !vote.equals(old)) { logger.warn( "Received duplicate vote : Replacing with new one : " + vote + " old one : " + old); sendResponse = true; } if (sendResponse) { // This is either not a response to this node initiating election or a duplicate vote. // Either case notify this // nodes vote L2StateMessage response = createElectionStartedMessage(msg, myVote); logger.info("Casted vote from " + msg + " My Response : " + response); try { groupManager.sendTo(msg.messageFrom(), response); } catch (GroupException e) { logger.error("Error sending Votes to : " + msg.messageFrom(), e); } } else { logger.info("Casted vote from " + msg); } return true; } else { logger.info("Ignoring Start Election Request : " + msg + " My state = " + state); return false; } }