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);
59 private Object readResolve() {
60 return new FrontendIdentifier(memberName, clientType);
65 private static final long serialVersionUID = 1L;
67 private final MemberName memberName;
68 private final FrontendType clientType;
70 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
71 this.clientType = requireNonNull(clientType);
72 this.memberName = requireNonNull(memberName);
75 public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
76 return new FrontendIdentifier(memberName, clientType);
79 public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
80 final MemberName memberName = MemberName.readFrom(in);
81 final FrontendType clientType = FrontendType.readFrom(in);
82 return new FrontendIdentifier(memberName, clientType);
86 public void writeTo(final DataOutput out) throws IOException {
87 memberName.writeTo(out);
88 clientType.writeTo(out);
91 public @NonNull FrontendType getClientType() {
95 public @NonNull MemberName getMemberName() {
100 public int hashCode() {
101 return Objects.hash(memberName, clientType);
105 public boolean equals(final Object obj) {
106 return this == obj || obj instanceof FrontendIdentifier other && memberName.equals(other.memberName)
107 && clientType.equals(other.clientType);
110 public @NonNull String toPersistentId() {
111 return memberName.getName() + "-frontend-" + clientType.getName();
115 public String toString() {
116 return toPersistentId();
120 private Object writeReplace() {
121 return new Proxy(memberName, clientType);