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.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import java.util.Objects;
18 import org.opendaylight.yangtools.concepts.Identifier;
21 * A cluster-wide unique identifier of a frontend type located at a cluster member.
23 * @author Robert Varga
26 public final class FrontendIdentifier<T extends FrontendType> implements Identifier {
27 private static final class Proxy<T extends FrontendType> implements Externalizable {
28 private static final long serialVersionUID = 1L;
29 private MemberName memberName;
33 // Needed for Externalizable
36 Proxy(final MemberName memberName, final T clientType) {
37 this.memberName = Preconditions.checkNotNull(memberName);
38 this.clientType = Preconditions.checkNotNull(clientType);
42 public void writeExternal(ObjectOutput out) throws IOException {
43 out.writeObject(memberName);
44 out.writeObject(clientType);
47 @SuppressWarnings("unchecked")
49 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
50 memberName = (MemberName) in.readObject();
51 clientType = (T) in.readObject();
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 T clientType;
63 FrontendIdentifier(final MemberName memberName, final T clientType) {
64 this.clientType = Preconditions.checkNotNull(clientType);
65 this.memberName = Preconditions.checkNotNull(memberName);
68 public static <T extends FrontendType> FrontendIdentifier<T> create(MemberName memberName, final T clientType) {
69 return new FrontendIdentifier<>(memberName, clientType);
72 public T getClientType() {
76 public MemberName getMemberName() {
81 public int hashCode() {
82 return Objects.hash(memberName, clientType);
86 public boolean equals(final Object o) {
90 if (!(o instanceof FrontendIdentifier)) {
94 final FrontendIdentifier<?> other = (FrontendIdentifier<?>) o;
95 return memberName.equals(other.memberName) && clientType.equals(other.clientType);
99 public String toString() {
100 return MoreObjects.toStringHelper(FrontendIdentifier.class).add("member", memberName)
101 .add("clientType", clientType).toString();
104 private Object writeReplace() {
105 return new Proxy<>(memberName, clientType);