Bug 5419: Persist log entries asycnhronously
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ReplicatedLogImplEntry.java
index e5bf72233c197952daac0152f4eef53d01737c17..80193590dbfab16c6572a259a7b46f13cf894703 100644 (file)
@@ -15,13 +15,21 @@ import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payloa
 /**
  * A {@link ReplicatedLogEntry} implementation.
  */
-public final class ReplicatedLogImplEntry implements ReplicatedLogEntry, Serializable {
+public class ReplicatedLogImplEntry implements ReplicatedLogEntry, Serializable {
     private static final long serialVersionUID = -9085798014576489130L;
 
     private final long index;
     private final long term;
     private final Payload payload;
+    private transient boolean persistencePending = false;
 
+    /**
+     * Constructs an instance.
+     *
+     * @param index the index
+     * @param term the term
+     * @param payload the payload
+     */
     public ReplicatedLogImplEntry(final long index, final long term, final Payload payload) {
         this.index = index;
         this.term = term;
@@ -48,6 +56,60 @@ public final class ReplicatedLogImplEntry implements ReplicatedLogEntry, Seriali
         return getData().size();
     }
 
+    @Override
+    public boolean isPersistencePending() {
+        return persistencePending;
+    }
+
+    @Override
+    public void setPersistencePending(boolean pending) {
+        persistencePending = pending;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + payload.hashCode();
+        result = prime * result + (int) (index ^ index >>> 32);
+        result = prime * result + (int) (term ^ term >>> 32);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj == null) {
+            return false;
+        }
+
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+
+        ReplicatedLogImplEntry other = (ReplicatedLogImplEntry) obj;
+        if (payload == null) {
+            if (other.payload != null) {
+                return false;
+            }
+        } else if (!payload.equals(other.payload)) {
+            return false;
+        }
+
+        if (index != other.index) {
+            return false;
+        }
+
+        if (term != other.term) {
+            return false;
+        }
+
+        return true;
+    }
+
     @Override
     public String toString() {
         return "Entry{index=" + index + ", term=" + term + '}';