Remove old unversioned proxies
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / HI.java
index a0d4795ac67d899cb659f1e2ebff158f3fa27fd7..ab4d884eee7a19f3fc9d748613790743cc738ec1 100644 (file)
@@ -10,10 +10,23 @@ package org.opendaylight.controller.cluster.access.concepts;
 import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.opendaylight.yangtools.concepts.WritableObjects;
+
 /**
  * Serialization proxy for {@link LocalHistoryIdentifier}.
+ *
+ * @implNote
+ *     cookie is currently required only for module-based sharding, which is implemented as part of normal
+ *     DataBroker interfaces. For DOMDataTreeProducer cookie will always be zero, hence we may end up not needing
+ *     cookie at all.
+ *     We use WritableObjects.writeLongs() to output historyId and cookie (in that order). If we end up not needing
+ *     the cookie at all, we can switch to writeLong() and use zero flags for compatibility.
  */
-final class HI implements LocalHistoryIdentifier.SerialForm {
+final class HI implements Externalizable {
     @java.io.Serial
     private static final long serialVersionUID = 1L;
 
@@ -29,17 +42,22 @@ final class HI implements LocalHistoryIdentifier.SerialForm {
     }
 
     @Override
-    public LocalHistoryIdentifier identifier() {
-        return verifyNotNull(identifier);
+    public void writeExternal(final ObjectOutput out) throws IOException {
+        identifier.getClientId().writeTo(out);
+        WritableObjects.writeLongs(out, identifier.getHistoryId(), identifier.getCookie());
     }
 
     @Override
-    public void setIdentifier(final LocalHistoryIdentifier identifier) {
-        this.identifier = requireNonNull(identifier);
+    public void readExternal(final ObjectInput in) throws IOException {
+        final var clientId = ClientIdentifier.readFrom(in);
+        final byte header = WritableObjects.readLongHeader(in);
+        final var historyId = WritableObjects.readFirstLong(in, header);
+        final var cookie = WritableObjects.readSecondLong(in, header);
+        identifier = new LocalHistoryIdentifier(clientId, historyId, cookie);
     }
 
-    @Override
-    public Object readResolve() {
-        return identifier();
+    @java.io.Serial
+    private Object readResolve() {
+        return verifyNotNull(identifier);
     }
 }