2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access.concepts;
10 import static java.util.Objects.requireNonNull;
12 import java.io.DataInput;
13 import java.io.DataOutput;
14 import java.io.Externalizable;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import java.io.Serial;
19 import java.util.Objects;
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.opendaylight.yangtools.concepts.WritableIdentifier;
24 * A cluster-wide unique identifier of a frontend type located at a cluster member.
26 public final class FrontendIdentifier implements WritableIdentifier {
27 private static final class Proxy implements Externalizable {
29 private static final long serialVersionUID = 1L;
31 private MemberName memberName;
32 private FrontendType clientType;
34 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
35 // be able to create instances via reflection.
36 @SuppressWarnings("checkstyle:RedundantModifier")
38 // Needed for Externalizable
41 Proxy(final MemberName memberName, final FrontendType clientType) {
42 this.memberName = requireNonNull(memberName);
43 this.clientType = requireNonNull(clientType);
47 public void writeExternal(final ObjectOutput out) throws IOException {
48 memberName.writeTo(out);
49 clientType.writeTo(out);
53 public void readExternal(final ObjectInput in) throws IOException {
54 memberName = MemberName.readFrom(in);
55 clientType = FrontendType.readFrom(in);
58 private Object readResolve() {
59 return new FrontendIdentifier(memberName, clientType);
64 private static final long serialVersionUID = 1L;
66 private final MemberName memberName;
67 private final FrontendType clientType;
69 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
70 this.clientType = requireNonNull(clientType);
71 this.memberName = requireNonNull(memberName);
74 public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
75 return new FrontendIdentifier(memberName, clientType);
78 public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
79 final MemberName memberName = MemberName.readFrom(in);
80 final FrontendType clientType = FrontendType.readFrom(in);
81 return new FrontendIdentifier(memberName, clientType);
85 public void writeTo(final DataOutput out) throws IOException {
86 memberName.writeTo(out);
87 clientType.writeTo(out);
90 public @NonNull FrontendType getClientType() {
94 public @NonNull MemberName getMemberName() {
99 public int hashCode() {
100 return Objects.hash(memberName, clientType);
104 public boolean equals(final Object obj) {
108 if (!(obj instanceof FrontendIdentifier other)) {
112 return memberName.equals(other.memberName) && clientType.equals(other.clientType);
115 public @NonNull String toPersistentId() {
116 return memberName.getName() + "-frontend-" + clientType.getName();
120 public String toString() {
121 return toPersistentId();
124 private Object writeReplace() {
125 return new Proxy(memberName, clientType);