Remove ABIVersion.MAGNESIUM
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / FrontendIdentifier.java
index bd16e4b28ec67c611eb573ac3205a18e126b8f66..76aad38da71e4d802b988771b292c7fc34a01dba 100644 (file)
@@ -7,73 +7,51 @@
  */
 package org.opendaylight.controller.cluster.access.concepts;
 
-import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-import java.io.Externalizable;
+import static java.util.Objects.requireNonNull;
+
+import java.io.DataInput;
+import java.io.DataOutput;
 import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.util.Objects;
-import org.opendaylight.yangtools.concepts.Identifier;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.WritableIdentifier;
 
 /**
  * A cluster-wide unique identifier of a frontend type located at a cluster member.
- *
- * @author Robert Varga
  */
-@Beta
-public final class FrontendIdentifier<T extends FrontendType> implements Identifier {
-    private static final class Proxy<T extends FrontendType> implements Externalizable {
-        private static final long serialVersionUID = 1L;
-        private MemberName memberName;
-        private T clientType;
-
-        public Proxy() {
-            // Needed for Externalizable
-        }
-
-        Proxy(final MemberName memberName, final T clientType) {
-            this.memberName = Preconditions.checkNotNull(memberName);
-            this.clientType = Preconditions.checkNotNull(clientType);
-        }
-
-        @Override
-        public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(memberName);
-            out.writeObject(clientType);
-        }
+public final class FrontendIdentifier implements WritableIdentifier {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
 
-        @SuppressWarnings("unchecked")
-        @Override
-        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            memberName = (MemberName) in.readObject();
-            clientType = (T) in.readObject();
-        }
+    private final MemberName memberName;
+    private final FrontendType clientType;
 
-        private Object readResolve() {
-            return new FrontendIdentifier<>(memberName, clientType);
-        }
+    FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
+        this.clientType = requireNonNull(clientType);
+        this.memberName = requireNonNull(memberName);
     }
 
-    private static final long serialVersionUID = 1L;
-    private final MemberName memberName;
-    private final T clientType;
+    public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
+        return new FrontendIdentifier(memberName, clientType);
+    }
 
-    FrontendIdentifier(final MemberName memberName, final T clientType) {
-        this.clientType = Preconditions.checkNotNull(clientType);
-        this.memberName = Preconditions.checkNotNull(memberName);
+    public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
+        final var memberName = MemberName.readFrom(in);
+        final var clientType = FrontendType.readFrom(in);
+        return new FrontendIdentifier(memberName, clientType);
     }
 
-    public static <T extends FrontendType> FrontendIdentifier<T> create(MemberName memberName, final T clientType) {
-        return new FrontendIdentifier<>(memberName, clientType);
+    @Override
+    public void writeTo(final DataOutput out) throws IOException {
+        memberName.writeTo(out);
+        clientType.writeTo(out);
     }
 
-    public T getClientType() {
+    public @NonNull FrontendType getClientType() {
         return clientType;
     }
 
-    public MemberName getMemberName() {
+    public @NonNull MemberName getMemberName() {
         return memberName;
     }
 
@@ -83,25 +61,22 @@ public final class FrontendIdentifier<T extends FrontendType> implements Identif
     }
 
     @Override
-    public boolean equals(final Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (!(o instanceof FrontendIdentifier)) {
-            return false;
-        }
+    public boolean equals(final Object obj) {
+        return this == obj || obj instanceof FrontendIdentifier other && memberName.equals(other.memberName)
+            && clientType.equals(other.clientType);
+    }
 
-        final FrontendIdentifier<?> other = (FrontendIdentifier<?>) o;
-        return memberName.equals(other.memberName) && clientType.equals(other.clientType);
+    public @NonNull String toPersistentId() {
+        return memberName.getName() + "-frontend-" + clientType.getName();
     }
 
     @Override
     public String toString() {
-        return MoreObjects.toStringHelper(FrontendIdentifier.class).add("member", memberName)
-                .add("clientType", clientType).toString();
+        return toPersistentId();
     }
 
+    @java.io.Serial
     private Object writeReplace() {
-        return new Proxy<>(memberName, clientType);
+        return new FI(this);
     }
 }