Remove shard-snapshot-chunk-size
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / SimpleReplicatedLogEntry.java
index 3dc5a286a73f299075047c062950d6c7366ff01c..610d53a9e72efcb7bded805e79d7d6a4a5e1b63f 100644 (file)
@@ -5,70 +5,30 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.raft.persisted;
 
-import com.google.common.base.Preconditions;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
+import static java.util.Objects.requireNonNull;
+
+import java.io.Serializable;
+import org.apache.commons.lang3.SerializationUtils;
 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
+import org.opendaylight.controller.cluster.raft.messages.Payload;
 
 /**
  * A {@link ReplicatedLogEntry} implementation.
  *
  * @author Thomas Pantelis
  */
-public class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSerializable {
-    private static final class Proxy implements Externalizable {
-        private static final long serialVersionUID = 1L;
-
-        private ReplicatedLogEntry replicatedLogEntry;
-
-        // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
-        // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
-        @SuppressWarnings("checkstyle:RedundantModifier")
-        public Proxy() {
-            // For Externalizable
-        }
-
-        Proxy(final ReplicatedLogEntry replicatedLogEntry) {
-            this.replicatedLogEntry = replicatedLogEntry;
-        }
-
-        @Override
-        public void writeExternal(final ObjectOutput out) throws IOException {
-            out.writeLong(replicatedLogEntry.getIndex());
-            out.writeLong(replicatedLogEntry.getTerm());
-            out.writeObject(replicatedLogEntry.getData());
-        }
-
-        @Override
-        public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
-            replicatedLogEntry = new SimpleReplicatedLogEntry(in.readLong(), in.readLong(), (Payload) in.readObject());
-        }
-
-        private Object readResolve() {
-            return replicatedLogEntry;
-        }
-    }
-
+public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
+    // Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative.
+    private static final int PROXY_SIZE = SerializationUtils.serialize(new LE((Void) null)).length;
 
     private final long index;
     private final long term;
     private final Payload payload;
     private boolean persistencePending;
-    private final boolean migrated;
-
-    private SimpleReplicatedLogEntry(long index, long term, Payload payload, boolean migrated) {
-        this.index = index;
-        this.term = term;
-        this.payload = Preconditions.checkNotNull(payload);
-        this.migrated = migrated;
-    }
 
     /**
      * Constructs an instance.
@@ -78,12 +38,9 @@ public class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSer
      * @param payload the payload
      */
     public SimpleReplicatedLogEntry(final long index, final long term, final Payload payload) {
-        this(index, term, payload, false);
-    }
-
-    @Deprecated
-    public static ReplicatedLogEntry createMigrated(final long index, final long term, final Payload payload) {
-        return new SimpleReplicatedLogEntry(index, term, payload, true);
+        this.index = index;
+        this.term = term;
+        this.payload = requireNonNull(payload);
     }
 
     @Override
@@ -103,27 +60,22 @@ public class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSer
 
     @Override
     public int size() {
-        return getData().size();
+        return payload.size();
     }
 
     @Override
-    public boolean isPersistencePending() {
-        return persistencePending;
-    }
-
-    @Override
-    public void setPersistencePending(boolean pending) {
-        persistencePending = pending;
+    public int serializedSize() {
+        return PROXY_SIZE + payload.serializedSize();
     }
 
     @Override
-    public boolean isMigrated() {
-        return migrated;
+    public boolean isPersistencePending() {
+        return persistencePending;
     }
 
     @Override
-    public Object writeReplace() {
-        return new Proxy(this);
+    public void setPersistencePending(final boolean pending) {
+        persistencePending = pending;
     }
 
     @Override
@@ -137,21 +89,18 @@ public class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSer
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-
-        SimpleReplicatedLogEntry other = (SimpleReplicatedLogEntry) obj;
-        return index == other.index && term == other.term && payload.equals(other.payload);
+    public boolean equals(final Object obj) {
+        return this == obj || obj instanceof SimpleReplicatedLogEntry other && index == other.index
+            && term == other.term && payload.equals(other.payload);
     }
 
     @Override
     public String toString() {
         return "SimpleReplicatedLogEntry [index=" + index + ", term=" + term + ", payload=" + payload + "]";
     }
+
+    @java.io.Serial
+    private Object writeReplace() {
+        return new LE(this);
+    }
 }