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.base.MoreObjects;
13 import java.io.DataInput;
14 import java.io.DataOutput;
15 import java.io.IOException;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024.ClientGeneration;
18 import org.opendaylight.yangtools.concepts.WritableIdentifier;
19 import org.opendaylight.yangtools.concepts.WritableObjects;
20 import org.opendaylight.yangtools.yang.common.Uint64;
23 * A cluster-wide unique identifier of a frontend instance. This identifier discerns between individual incarnations
24 * of a particular frontend.
26 public final class ClientIdentifier implements WritableIdentifier {
28 private static final long serialVersionUID = 1L;
30 private final @NonNull FrontendIdentifier frontendId;
31 private final long generation;
33 ClientIdentifier(final FrontendIdentifier frontendId, final long generation) {
34 this.frontendId = requireNonNull(frontendId);
35 this.generation = generation;
38 public static @NonNull ClientIdentifier create(final FrontendIdentifier frontendId,
39 final long generation) {
40 return new ClientIdentifier(frontendId, generation);
43 public static @NonNull ClientIdentifier readFrom(final DataInput in) throws IOException {
44 final FrontendIdentifier frontendId = FrontendIdentifier.readFrom(in);
45 return new ClientIdentifier(frontendId, WritableObjects.readLong(in));
49 public void writeTo(final DataOutput out) throws IOException {
50 frontendId.writeTo(out);
51 WritableObjects.writeLong(out, generation);
54 public @NonNull FrontendIdentifier getFrontendId() {
58 public long getGeneration() {
62 public @NonNull ClientGeneration getYangGeneration() {
63 return new ClientGeneration(Uint64.fromLongBits(generation));
67 public int hashCode() {
68 return frontendId.hashCode() * 31 + Long.hashCode(generation);
72 public boolean equals(final Object obj) {
73 return this == obj || obj instanceof ClientIdentifier other && generation == other.generation
74 && frontendId.equals(other.frontendId);
78 public String toString() {
79 return MoreObjects.toStringHelper(ClientIdentifier.class)
80 .add("frontend", frontendId)
81 .add("generation", Long.toUnsignedString(generation))
86 private Object writeReplace() {