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.WritableIdentifier;
19 import org.opendaylight.yangtools.concepts.WritableObjects;
22 * Globally-unique identifier of a local history.
24 * @author Robert Varga
26 public final class LocalHistoryIdentifier implements WritableIdentifier {
27 private static final class Proxy implements Externalizable {
28 private static final long serialVersionUID = 1L;
29 private ClientIdentifier clientId;
30 private long historyId;
36 Proxy(final ClientIdentifier frontendId, final long historyId) {
37 this.clientId = Preconditions.checkNotNull(frontendId);
38 this.historyId = historyId;
42 public void writeExternal(final ObjectOutput out) throws IOException {
43 clientId.writeTo(out);
44 WritableObjects.writeLong(out, historyId);
48 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
49 clientId = ClientIdentifier.readFrom(in);
50 historyId = WritableObjects.readLong(in);
53 private Object readResolve() {
54 return new LocalHistoryIdentifier(clientId, historyId);
58 private static final long serialVersionUID = 1L;
59 private final ClientIdentifier clientId;
60 private final long historyId;
62 public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId) {
63 this.clientId = Preconditions.checkNotNull(frontendId);
64 this.historyId = historyId;
67 public static LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
68 final ClientIdentifier clientId = ClientIdentifier.readFrom(in);
69 return new LocalHistoryIdentifier(clientId, WritableObjects.readLong(in));
73 public void writeTo(final DataOutput out) throws IOException {
74 clientId.writeTo(out);
75 WritableObjects.writeLong(out, historyId);
78 public ClientIdentifier getClientId() {
82 public long getHistoryId() {
87 public int hashCode() {
88 return clientId.hashCode() * 31 + Long.hashCode(historyId);
92 public boolean equals(final Object o) {
96 if (!(o instanceof LocalHistoryIdentifier)) {
100 final LocalHistoryIdentifier other = (LocalHistoryIdentifier) o;
101 return historyId == other.historyId && clientId.equals(other.clientId);
105 public String toString() {
106 return MoreObjects.toStringHelper(LocalHistoryIdentifier.class).add("client", clientId)
107 .add("history", Long.toUnsignedString(historyId)).toString();
110 private Object writeReplace() {
111 return new Proxy(clientId, historyId);