Make Netty-3 dependency optional
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / NoopPayload.java
index 2393a30610be51f7bd860edc45e20fcbbd66fa31..0f076c55d755a3286433d388aad2e33faeef1fdb 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.controller.cluster.raft.persisted;
 
-import java.io.Serializable;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
+import akka.dispatch.ControlMessage;
+import org.apache.commons.lang3.SerializationUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.cluster.raft.messages.Payload;
 
 /**
  * Payload used for no-op log entries that are put into the journal by the PreLeader in order to commit
@@ -16,11 +18,17 @@ import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payloa
  *
  * @author Thomas Pantelis
  */
-public final class NoopPayload extends Payload implements Serializable {
+public final class NoopPayload extends Payload implements ControlMessage {
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
-    public static final NoopPayload INSTANCE = new NoopPayload();
+    private static final @NonNull NP PROXY = new NP();
+    // 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(PROXY).length;
+
+    public static final @NonNull NoopPayload INSTANCE = new NoopPayload();
 
     private NoopPayload() {
+        // Hidden on purpose
     }
 
     @Override
@@ -28,7 +36,13 @@ public final class NoopPayload extends Payload implements Serializable {
         return 0;
     }
 
-    private Object readResolve() {
-        return INSTANCE;
+    @Override
+    public int serializedSize() {
+        return PROXY_SIZE;
+    }
+
+    @Override
+    protected Object writeReplace() {
+        return PROXY;
     }
 }