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 com.google.common.annotations.Beta;
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 * @author Robert Varga
29 public final class FrontendIdentifier implements WritableIdentifier {
30 private static final class Proxy implements Externalizable {
31 private static final long serialVersionUID = 1L;
32 private MemberName memberName;
33 private FrontendType clientType;
35 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
36 // be able to create instances via reflection.
37 @SuppressWarnings("checkstyle:RedundantModifier")
39 // Needed for Externalizable
42 Proxy(final MemberName memberName, final FrontendType clientType) {
43 this.memberName = requireNonNull(memberName);
44 this.clientType = requireNonNull(clientType);
48 public void writeExternal(final ObjectOutput out) throws IOException {
49 memberName.writeTo(out);
50 clientType.writeTo(out);
54 public void readExternal(final ObjectInput in) throws IOException {
55 memberName = MemberName.readFrom(in);
56 clientType = FrontendType.readFrom(in);
59 private Object readResolve() {
60 return new FrontendIdentifier(memberName, clientType);
64 private static final long serialVersionUID = 1L;
65 private final MemberName memberName;
66 private final FrontendType clientType;
68 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
69 this.clientType = requireNonNull(clientType);
70 this.memberName = requireNonNull(memberName);
73 public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
74 return new FrontendIdentifier(memberName, clientType);
77 public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
78 final MemberName memberName = MemberName.readFrom(in);
79 final FrontendType clientType = FrontendType.readFrom(in);
80 return new FrontendIdentifier(memberName, clientType);
84 public void writeTo(final DataOutput out) throws IOException {
85 memberName.writeTo(out);
86 clientType.writeTo(out);
89 public @NonNull FrontendType getClientType() {
93 public @NonNull MemberName getMemberName() {
98 public int hashCode() {
99 return Objects.hash(memberName, clientType);
103 public boolean equals(final Object obj) {
107 if (!(obj instanceof FrontendIdentifier)) {
111 final FrontendIdentifier other = (FrontendIdentifier) obj;
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);