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 com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
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.util.Objects;
19 import org.opendaylight.yangtools.concepts.WritableIdentifier;
22 * A cluster-wide unique identifier of a frontend type located at a cluster member.
24 * @author Robert Varga
27 public final class FrontendIdentifier implements WritableIdentifier {
28 private static final class Proxy implements Externalizable {
29 private static final long serialVersionUID = 1L;
30 private MemberName memberName;
31 private FrontendType clientType;
33 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
34 // be able to create instances via reflection.
35 @SuppressWarnings("checkstyle:RedundantModifier")
37 // Needed for Externalizable
40 Proxy(final MemberName memberName, final FrontendType clientType) {
41 this.memberName = Preconditions.checkNotNull(memberName);
42 this.clientType = Preconditions.checkNotNull(clientType);
46 public void writeExternal(final ObjectOutput out) throws IOException {
47 memberName.writeTo(out);
48 clientType.writeTo(out);
52 public void readExternal(final ObjectInput in) throws IOException {
53 memberName = MemberName.readFrom(in);
54 clientType = FrontendType.readFrom(in);
57 private Object readResolve() {
58 return new FrontendIdentifier(memberName, clientType);
62 private static final long serialVersionUID = 1L;
63 private final MemberName memberName;
64 private final FrontendType clientType;
66 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
67 this.clientType = Preconditions.checkNotNull(clientType);
68 this.memberName = Preconditions.checkNotNull(memberName);
71 public static FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
72 return new FrontendIdentifier(memberName, clientType);
75 public static FrontendIdentifier readFrom(final DataInput in) throws IOException {
76 final MemberName memberName = MemberName.readFrom(in);
77 final FrontendType clientType = FrontendType.readFrom(in);
78 return new FrontendIdentifier(memberName, clientType);
82 public void writeTo(final DataOutput out) throws IOException {
83 memberName.writeTo(out);
84 clientType.writeTo(out);
87 public FrontendType getClientType() {
91 public MemberName getMemberName() {
96 public int hashCode() {
97 return Objects.hash(memberName, clientType);
101 public boolean equals(final Object obj) {
105 if (!(obj instanceof FrontendIdentifier)) {
109 final FrontendIdentifier other = (FrontendIdentifier) obj;
110 return memberName.equals(other.memberName) && clientType.equals(other.clientType);
113 public String toPersistentId() {
114 return memberName.getName() + "-frontend-" + clientType.getName();
118 public String toString() {
119 return toPersistentId();
122 private Object writeReplace() {
123 return new Proxy(memberName, clientType);