Bump versions 9.0.4-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / PurgeLocalHistoryPayload.java
index 91ad74d505e5494521d4d27d0d9864d47b34909d..3608e7589fea0640616ba72039b98fc3624848aa 100644 (file)
@@ -7,10 +7,8 @@
  */
 package org.opendaylight.controller.cluster.datastore.persisted;
 
-import com.google.common.base.Throwables;
 import com.google.common.io.ByteArrayDataOutput;
 import com.google.common.io.ByteStreams;
-import java.io.DataInput;
 import java.io.IOException;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
 import org.slf4j.Logger;
@@ -23,53 +21,35 @@ import org.slf4j.LoggerFactory;
  * @author Robert Varga
  */
 public final class PurgeLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
-    private static final class Proxy extends AbstractProxy<LocalHistoryIdentifier> {
-        private static final long serialVersionUID = 1L;
-
-        // 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 byte[] serialized) {
-            super(serialized);
-        }
-
-        @Override
-        protected LocalHistoryIdentifier readIdentifier(final DataInput in) throws IOException {
-            return LocalHistoryIdentifier.readFrom(in);
-        }
-
-        @Override
-        protected PurgeLocalHistoryPayload createObject(final LocalHistoryIdentifier identifier,
-                final byte[] serialized) {
-            return new PurgeLocalHistoryPayload(identifier, serialized);
-        }
-    }
-
     private static final Logger LOG = LoggerFactory.getLogger(PurgeLocalHistoryPayload.class);
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
+    private static final int PROXY_SIZE = externalizableProxySize(PH::new);
 
     PurgeLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
         super(historyId, serialized);
     }
 
-    public static PurgeLocalHistoryPayload create(final LocalHistoryIdentifier historyId) {
-        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
+    public static PurgeLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
+            final int initialSerializedBufferCapacity) {
+        final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
         try {
             historyId.writeTo(out);
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", historyId, e);
-            throw Throwables.propagate(e);
+            throw new IllegalStateException("Failed to serialize " + historyId, e);
         }
         return new PurgeLocalHistoryPayload(historyId, out.toByteArray());
     }
 
     @Override
-    protected Proxy externalizableProxy(final byte[] serialized) {
-        return new Proxy(serialized);
+    protected PH externalizableProxy(final byte[] serialized) {
+        return new PH(serialized);
+    }
+
+    @Override
+    protected int externalizableProxySize() {
+        return PROXY_SIZE;
     }
 }