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 java.io.DataInput;
13 import java.io.DataOutput;
14 import java.io.IOException;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.concepts.WritableIdentifier;
17 import org.opendaylight.yangtools.concepts.WritableObjects;
20 * Globally-unique identifier of a transaction.
22 public final class TransactionIdentifier implements WritableIdentifier {
24 private static final long serialVersionUID = 1L;
26 private final @NonNull LocalHistoryIdentifier historyId;
27 private final long transactionId;
28 private String shortString;
30 public TransactionIdentifier(final @NonNull LocalHistoryIdentifier historyId, final long transactionId) {
31 this.historyId = requireNonNull(historyId);
32 this.transactionId = transactionId;
35 public static @NonNull TransactionIdentifier readFrom(final DataInput in) throws IOException {
36 final LocalHistoryIdentifier historyId = LocalHistoryIdentifier.readFrom(in);
37 return new TransactionIdentifier(historyId, WritableObjects.readLong(in));
41 public void writeTo(final DataOutput out) throws IOException {
42 historyId.writeTo(out);
43 WritableObjects.writeLong(out, transactionId);
46 public @NonNull LocalHistoryIdentifier getHistoryId() {
50 public long getTransactionId() {
55 public int hashCode() {
56 return historyId.hashCode() * 31 + Long.hashCode(transactionId);
60 public boolean equals(final Object obj) {
61 return this == obj || obj instanceof TransactionIdentifier other && transactionId == other.transactionId
62 && historyId.equals(other.historyId);
65 public String toShortString() {
66 if (shortString == null) {
67 String histStr = historyId.getHistoryId() == 0 ? "" : "-chn-" + historyId.getHistoryId();
68 shortString = historyId.getClientId().getFrontendId().getMemberName().getName() + "-"
69 + historyId.getClientId().getFrontendId().getClientType().getName() + "-fe-"
70 + historyId.getClientId().getGeneration() + histStr + "-txn-" + transactionId
71 + "-" + historyId.getCookie();
78 public String toString() {
79 return toShortString();
83 private Object writeReplace() {