+
+ @Override
+ public boolean okToReplicate() {
+ // 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 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();
+ }
+
+ @Override
+ public short getPayloadVersion() {
+ return payloadVersion;
+ }
+
+ @Override
+ public void setPayloadVersion(short payloadVersion) {
+ this.payloadVersion = payloadVersion;
+ }