- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("FollowerLogInformationImpl [id=").append(id).append(", nextIndex=").append(nextIndex)
- .append(", matchIndex=").append(matchIndex).append(", stopwatch=")
- .append(stopwatch.elapsed(TimeUnit.MILLISECONDS))
- .append(", followerTimeoutMillis=")
- .append(context.getConfigParams().getElectionTimeOutInterval().toMillis()).append("]");
- return builder.toString();
+ public boolean okToReplicate() {
+ if(peerInfo.getVotingState() == VotingState.VOTING_NOT_INITIALIZED) {
+ return false;
+ }
+
+ // Return false if we are trying to send duplicate data before the heartbeat interval
+ if(getNextIndex() == lastReplicatedIndex){
+ if(lastReplicatedStopwatch.elapsed(TimeUnit.MILLISECONDS) < context.getConfigParams()
+ .getHeartBeatInterval().toMillis()){
+ return false;
+ }
+ }
+
+ resetLastReplicated();
+ return true;
+ }
+
+ private void resetLastReplicated(){
+ lastReplicatedIndex = getNextIndex();
+ if(lastReplicatedStopwatch.isRunning()){
+ lastReplicatedStopwatch.reset();
+ }
+ lastReplicatedStopwatch.start();
+ }
+
+ @Override
+ public short getPayloadVersion() {
+ return payloadVersion;