X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FTransactionIdentifier.java;h=d2a92ea1913374a2dfa693195f27f1916938d347;hp=6ad94d203b52d4ec3ff19eaec7d4a7d598de84e7;hb=26b290518d362a85311c5b5591e3ef72e0772cf2;hpb=e057b5ff3e8c2fa390ed2346c522128e90be41e8 diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java index 6ad94d203b..d2a92ea191 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java @@ -7,16 +7,16 @@ */ package org.opendaylight.controller.cluster.access.concepts; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.Beta; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import java.io.DataInput; import java.io.DataOutput; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; import org.opendaylight.yangtools.concepts.WritableObjects; @@ -32,12 +32,15 @@ public final class TransactionIdentifier implements WritableIdentifier { private LocalHistoryIdentifier historyId; private long transactionId; + // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to + // be able to create instances via reflection. + @SuppressWarnings("checkstyle:RedundantModifier") public Proxy() { // For Externalizable } Proxy(final LocalHistoryIdentifier historyId, final long transactionId) { - this.historyId = Preconditions.checkNotNull(historyId); + this.historyId = requireNonNull(historyId); this.transactionId = transactionId; } @@ -59,15 +62,16 @@ public final class TransactionIdentifier implements WritableIdentifier { } private static final long serialVersionUID = 1L; - private final LocalHistoryIdentifier historyId; + private final @NonNull LocalHistoryIdentifier historyId; private final long transactionId; + private String shortString; - public TransactionIdentifier(final @Nonnull LocalHistoryIdentifier historyId, final long transactionId) { - this.historyId = Preconditions.checkNotNull(historyId); + public TransactionIdentifier(final @NonNull LocalHistoryIdentifier historyId, final long transactionId) { + this.historyId = requireNonNull(historyId); this.transactionId = transactionId; } - public static TransactionIdentifier readFrom(final DataInput in) throws IOException { + public static @NonNull TransactionIdentifier readFrom(final DataInput in) throws IOException { final LocalHistoryIdentifier historyId = LocalHistoryIdentifier.readFrom(in); return new TransactionIdentifier(historyId, WritableObjects.readLong(in)); } @@ -78,7 +82,7 @@ public final class TransactionIdentifier implements WritableIdentifier { WritableObjects.writeLong(out, transactionId); } - public LocalHistoryIdentifier getHistoryId() { + public @NonNull LocalHistoryIdentifier getHistoryId() { return historyId; } @@ -92,22 +96,33 @@ public final class TransactionIdentifier implements WritableIdentifier { } @Override - public boolean equals(final Object o) { - if (this == o) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (!(o instanceof TransactionIdentifier)) { + if (!(obj instanceof TransactionIdentifier)) { return false; } - final TransactionIdentifier other = (TransactionIdentifier) o; + final TransactionIdentifier other = (TransactionIdentifier) obj; return transactionId == other.transactionId && historyId.equals(other.historyId); } + public String toShortString() { + if (shortString == null) { + String histStr = historyId.getHistoryId() == 0 ? "" : "-chn-" + historyId.getHistoryId(); + shortString = historyId.getClientId().getFrontendId().getMemberName().getName() + "-" + + historyId.getClientId().getFrontendId().getClientType().getName() + "-fe-" + + historyId.getClientId().getGeneration() + histStr + "-txn-" + transactionId + + "-" + historyId.getCookie(); + } + + return shortString; + } + @Override public String toString() { - return MoreObjects.toStringHelper(TransactionIdentifier.class).add("history", historyId) - .add("transaction", transactionId).toString(); + return toShortString(); } private Object writeReplace() {