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.base.MoreObjects;
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 org.opendaylight.yangtools.concepts.Identifier;
21 * Globally-unique identifier of a local history.
23 * @author Robert Varga
25 public final class LocalHistoryIdentifier implements Identifier, WritableObject {
26 private static final class Proxy implements Externalizable {
27 private static final long serialVersionUID = 1L;
28 private ClientIdentifier clientId;
29 private long historyId;
35 Proxy(final ClientIdentifier frontendId, final long historyId) {
36 this.clientId = Preconditions.checkNotNull(frontendId);
37 this.historyId = historyId;
41 public void writeExternal(final ObjectOutput out) throws IOException {
42 clientId.writeTo(out);
43 WritableObjects.writeLong(out, historyId);
47 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
48 clientId = ClientIdentifier.readFrom(in);
49 historyId = WritableObjects.readLong(in);
52 private Object readResolve() {
53 return new LocalHistoryIdentifier(clientId, historyId);
57 private static final long serialVersionUID = 1L;
58 private final ClientIdentifier clientId;
59 private final long historyId;
61 public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId) {
62 this.clientId = Preconditions.checkNotNull(frontendId);
63 this.historyId = historyId;
66 public static LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
67 final ClientIdentifier clientId = ClientIdentifier.readFrom(in);
68 return new LocalHistoryIdentifier(clientId, WritableObjects.readLong(in));
72 public void writeTo(final DataOutput out) throws IOException {
73 clientId.writeTo(out);
74 WritableObjects.writeLong(out, historyId);
77 public ClientIdentifier getClientId() {
81 public long getHistoryId() {
86 public int hashCode() {
87 return clientId.hashCode() * 31 + Long.hashCode(historyId);
91 public boolean equals(final Object o) {
95 if (!(o instanceof LocalHistoryIdentifier)) {
99 final LocalHistoryIdentifier other = (LocalHistoryIdentifier) o;
100 return historyId == other.historyId && clientId.equals(other.clientId);
104 public String toString() {
105 return MoreObjects.toStringHelper(LocalHistoryIdentifier.class).add("client", clientId)
106 .add("history", Long.toUnsignedString(historyId)).toString();
109 private Object writeReplace() {
110 return new Proxy(clientId, historyId);