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.yangtools.concepts.WritableIdentifier;
18 import org.opendaylight.yangtools.concepts.WritableObjects;
21 * Globally-unique identifier of a local history. This identifier is assigned on the frontend and is composed of
22 * - a {@link ClientIdentifier}, which uniquely identifies a single instantiation of a particular frontend
23 * - an unsigned long, which uniquely identifies the history on the backend
24 * - an unsigned long cookie, assigned by the client and meaningless on the backend, which just reflects it back
26 public final class LocalHistoryIdentifier implements WritableIdentifier {
28 private static final long serialVersionUID = 1L;
30 private final @NonNull ClientIdentifier clientId;
31 private final long historyId;
32 private final long cookie;
34 public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId) {
35 this(frontendId, historyId, 0);
38 public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId, final long cookie) {
39 clientId = requireNonNull(frontendId);
40 this.historyId = historyId;
44 public static @NonNull LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
45 final ClientIdentifier clientId = ClientIdentifier.readFrom(in);
47 final byte header = WritableObjects.readLongHeader(in);
48 return new LocalHistoryIdentifier(clientId, WritableObjects.readFirstLong(in, header),
49 WritableObjects.readSecondLong(in, header));
53 public void writeTo(final DataOutput out) throws IOException {
54 clientId.writeTo(out);
55 WritableObjects.writeLongs(out, historyId, cookie);
58 public @NonNull ClientIdentifier getClientId() {
62 public long getHistoryId() {
66 public long getCookie() {
71 public int hashCode() {
72 int ret = clientId.hashCode();
73 ret = 31 * ret + Long.hashCode(historyId);
74 ret = 31 * ret + Long.hashCode(cookie);
79 public boolean equals(final Object obj) {
83 if (!(obj instanceof LocalHistoryIdentifier other)) {
87 return historyId == other.historyId && cookie == other.cookie && clientId.equals(other.clientId);
91 public String toString() {
92 return MoreObjects.toStringHelper(LocalHistoryIdentifier.class).add("client", clientId)
93 .add("history", Long.toUnsignedString(historyId, 16))
94 .add("cookie", Long.toUnsignedString(cookie, 16)).toString();
98 private Object writeReplace() {