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;
34 // Needed for Externalizable
37 Proxy(final MemberName memberName, final FrontendType clientType) {
38 this.memberName = Preconditions.checkNotNull(memberName);
39 this.clientType = Preconditions.checkNotNull(clientType);
43 public void writeExternal(final ObjectOutput out) throws IOException {
44 memberName.writeTo(out);
45 clientType.writeTo(out);
49 public void readExternal(final ObjectInput in) throws IOException {
50 memberName = MemberName.readFrom(in);
51 clientType = FrontendType.readFrom(in);
54 private Object readResolve() {
55 return new FrontendIdentifier(memberName, clientType);
59 private static final long serialVersionUID = 1L;
60 private final MemberName memberName;
61 private final FrontendType clientType;
63 FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
64 this.clientType = Preconditions.checkNotNull(clientType);
65 this.memberName = Preconditions.checkNotNull(memberName);
68 public static FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
69 return new FrontendIdentifier(memberName, clientType);
72 public static FrontendIdentifier readFrom(final DataInput in) throws IOException {
73 final MemberName memberName = MemberName.readFrom(in);
74 final FrontendType clientType = FrontendType.readFrom(in);
75 return new FrontendIdentifier(memberName, clientType);
79 public void writeTo(final DataOutput out) throws IOException {
80 memberName.writeTo(out);
81 clientType.writeTo(out);
84 public FrontendType getClientType() {
88 public MemberName getMemberName() {
93 public int hashCode() {
94 return Objects.hash(memberName, clientType);
98 public boolean equals(final Object o) {
102 if (!(o instanceof FrontendIdentifier)) {
106 final FrontendIdentifier other = (FrontendIdentifier) o;
107 return memberName.equals(other.memberName) && clientType.equals(other.clientType);
110 public String toPersistentId() {
111 return memberName.getName() + "-frontend-" + clientType.getName();
115 public String toString() {
116 return toPersistentId();
119 private Object writeReplace() {
120 return new Proxy(memberName, clientType);