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.opendaylight.yangtools.concepts.WritableIdentifier;
23 * A cluster-wide unique identifier of a frontend type located at a cluster member.
25 * @author Robert Varga
28 public final class FrontendIdentifier implements WritableIdentifier {
29 private static final class Proxy implements Externalizable {
30 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);
63 private static final long serialVersionUID = 1L;
64 private final MemberName memberName;
65 private final FrontendType clientType;
67 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
68 this.clientType = requireNonNull(clientType);
69 this.memberName = requireNonNull(memberName);
72 public static FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
73 return new FrontendIdentifier(memberName, clientType);
76 public static FrontendIdentifier readFrom(final DataInput in) throws IOException {
77 final MemberName memberName = MemberName.readFrom(in);
78 final FrontendType clientType = FrontendType.readFrom(in);
79 return new FrontendIdentifier(memberName, clientType);
83 public void writeTo(final DataOutput out) throws IOException {
84 memberName.writeTo(out);
85 clientType.writeTo(out);
88 public FrontendType getClientType() {
92 public MemberName getMemberName() {
97 public int hashCode() {
98 return Objects.hash(memberName, clientType);
102 public boolean equals(final Object obj) {
106 if (!(obj instanceof FrontendIdentifier)) {
110 final FrontendIdentifier other = (FrontendIdentifier) obj;
111 return memberName.equals(other.memberName) && clientType.equals(other.clientType);
114 public String toPersistentId() {
115 return memberName.getName() + "-frontend-" + clientType.getName();
119 public String toString() {
120 return toPersistentId();
123 private Object writeReplace() {
124 return new Proxy(memberName, clientType);