Remove old payload proxies
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / AbortTransactionPayload.java
index b553bf92a2739cbb1e27474fd775fd7692281718..3c765be6152284aa8f50b17a1d3b3a223fa4fe06 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.controller.cluster.datastore.persisted;
 
 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.TransactionIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Payload persisted when a transaction is aborted. It contains the transaction identifier.
@@ -19,46 +20,35 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
  * @author Robert Varga
  */
 public final class AbortTransactionPayload extends AbstractIdentifiablePayload<TransactionIdentifier> {
-    private static final class Proxy extends AbstractProxy<TransactionIdentifier> {
-        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 TransactionIdentifier readIdentifier(final DataInput in) throws IOException {
-            return TransactionIdentifier.readFrom(in);
-        }
-
-        @Override
-        protected AbortTransactionPayload createObject(final TransactionIdentifier identifier,
-                final byte[] serialized) {
-            return new AbortTransactionPayload(identifier, serialized);
-        }
-    }
-
+    private static final Logger LOG = LoggerFactory.getLogger(AbortTransactionPayload.class);
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
+    private static final int PROXY_SIZE = externalizableProxySize(AT::new);
 
     AbortTransactionPayload(final TransactionIdentifier transactionId, final byte[] serialized) {
         super(transactionId, serialized);
     }
 
-    public static AbortTransactionPayload create(final TransactionIdentifier transactionId) throws IOException {
-        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
-        transactionId.writeTo(out);
+    public static AbortTransactionPayload create(final TransactionIdentifier transactionId,
+            final int initialSerializedBufferCapacity) {
+        final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
+        try {
+            transactionId.writeTo(out);
+        } catch (IOException e) {
+            // This should never happen
+            LOG.error("Failed to serialize {}", transactionId, e);
+            throw new IllegalStateException("Failed to serialized " + transactionId, e);
+        }
         return new AbortTransactionPayload(transactionId, out.toByteArray());
     }
 
     @Override
-    protected Proxy externalizableProxy(final byte[] serialized) {
-        return new Proxy(serialized);
+    protected AT externalizableProxy(final byte[] serialized) {
+        return new AT(serialized);
+    }
+
+    @Override
+    protected int externalizableProxySize() {
+        return PROXY_SIZE;
     }
 }