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.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.opendaylight.yangtools.concepts.Identifier;
19 * Globally-unique identifier of a local history.
21 * @param <T> Frontend type
23 * @author Robert Varga
25 public final class LocalHistoryIdentifier<T extends FrontendType> implements Identifier {
26 private static final class Proxy<T extends FrontendType> implements Externalizable {
27 private static final long serialVersionUID = 1L;
28 private ClientIdentifier<T> clientId;
29 private long historyId;
35 Proxy(final ClientIdentifier<T> frontendId, final long historyId) {
36 this.clientId = Preconditions.checkNotNull(frontendId);
37 this.historyId = historyId;
41 public void writeExternal(final ObjectOutput out) throws IOException {
42 out.writeObject(clientId);
43 out.writeLong(historyId);
46 @SuppressWarnings("unchecked")
48 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
49 clientId = (ClientIdentifier<T>) in.readObject();
50 historyId = in.readLong();
53 private Object readResolve() {
54 return new LocalHistoryIdentifier<>(clientId, historyId);
58 private static final long serialVersionUID = 1L;
59 private final ClientIdentifier<T> clientId;
60 private final long historyId;
62 public LocalHistoryIdentifier(final ClientIdentifier<T> frontendId, final long historyId) {
63 this.clientId = Preconditions.checkNotNull(frontendId);
64 this.historyId = historyId;
67 public ClientIdentifier<T> getClienId() {
71 public long getHistoryId() {
76 public int hashCode() {
77 return clientId.hashCode() * 31 + Long.hashCode(historyId);
81 public boolean equals(final Object o) {
85 if (!(o instanceof LocalHistoryIdentifier)) {
89 final LocalHistoryIdentifier<?> other = (LocalHistoryIdentifier<?>) o;
90 return historyId == other.historyId && clientId.equals(other.clientId);
94 public String toString() {
95 return MoreObjects.toStringHelper(LocalHistoryIdentifier.class).add("client", clientId)
96 .add("history", Long.toUnsignedString(historyId)).toString();
99 private Object writeReplace() {
100 return new Proxy<>(clientId, historyId);