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 com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import java.io.DataInput;
14 import java.io.DataOutput;
15 import java.io.Externalizable;
16 import java.io.IOException;
17 import java.io.ObjectInput;
18 import java.io.ObjectOutput;
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 interface SerialForm extends Externalizable {
28 @NonNull FrontendIdentifier identifier();
30 void setIdentifier(@NonNull FrontendIdentifier identifier);
36 default void writeExternal(final ObjectOutput out) throws IOException {
37 final var id = identifier();
38 id.memberName.writeTo(out);
39 id.clientType.writeTo(out);
43 default void readExternal(final ObjectInput in) throws IOException {
44 setIdentifier(new FrontendIdentifier(MemberName.readFrom(in), FrontendType.readFrom(in)));
48 @Deprecated(since = "7.0.0", forRemoval = true)
49 private static final class Proxy implements SerialForm {
51 private static final long serialVersionUID = 1L;
53 private FrontendIdentifier identifier;
55 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
56 // be able to create instances via reflection.
57 @SuppressWarnings("checkstyle:RedundantModifier")
59 // Needed for Externalizable
62 Proxy(final FrontendIdentifier identifier) {
63 this.identifier = requireNonNull(identifier);
67 public FrontendIdentifier identifier() {
68 return verifyNotNull(identifier);
72 public void setIdentifier(final FrontendIdentifier identifier) {
73 this.identifier = requireNonNull(identifier);
77 public Object readResolve() {
83 private static final long serialVersionUID = 1L;
85 private final MemberName memberName;
86 private final FrontendType clientType;
88 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
89 this.clientType = requireNonNull(clientType);
90 this.memberName = requireNonNull(memberName);
93 public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
94 return new FrontendIdentifier(memberName, clientType);
97 public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
98 final MemberName memberName = MemberName.readFrom(in);
99 final FrontendType clientType = FrontendType.readFrom(in);
100 return new FrontendIdentifier(memberName, clientType);
104 public void writeTo(final DataOutput out) throws IOException {
105 memberName.writeTo(out);
106 clientType.writeTo(out);
109 public @NonNull FrontendType getClientType() {
113 public @NonNull MemberName getMemberName() {
118 public int hashCode() {
119 return Objects.hash(memberName, clientType);
123 public boolean equals(final Object obj) {
124 return this == obj || obj instanceof FrontendIdentifier other && memberName.equals(other.memberName)
125 && clientType.equals(other.clientType);
128 public @NonNull String toPersistentId() {
129 return memberName.getName() + "-frontend-" + clientType.getName();
133 public String toString() {
134 return toPersistentId();
138 private Object writeReplace() {