@Override public void handle(CoordinatorMessage event) { System.err.println( "[ELECTION::" + self.getPeerId() + "] I got a coordinator message from " + event.getPeerSource().getPeerId() + " the leader is " + event.getLeader().getPeerId() + "!"); CancelTimeout ct = new CancelTimeout(timeoutId); trigger(ct, timerPort); leader = event.getLeader(); electionGroup = event.getElectionGroup(); electing = false; if (self.getPeerId().compareTo(leader.getPeerId()) != 0) { ScheduleTimeout heartbeatTimeout = new ScheduleTimeout(JRConfig.HEARTBEAT_TIMEOUT); heartbeatTimeout.setTimeoutEvent(new HeartbeatTimeout(heartbeatTimeout)); trigger(heartbeatTimeout, timerPort); } Stats.reportElectionMessages(); Stats.reportLeader(leader); }