X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FTransactionIdentifier.java;h=202b5ce6dc53fbe2b3946727b419f3d928d27b1c;hb=refs%2Fchanges%2F59%2F47459%2F4;hp=2aaf8264aacadf2084f176b9d64b536d7cc76aae;hpb=104ce145c9cd637c9b1caecfe0fe02c4ce4f343c;p=controller.git 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 2aaf8264aa..202b5ce6dc 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 @@ -8,66 +8,80 @@ package org.opendaylight.controller.cluster.access.concepts; 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.opendaylight.yangtools.concepts.Identifier; +import org.opendaylight.yangtools.concepts.WritableIdentifier; +import org.opendaylight.yangtools.concepts.WritableObjects; /** * Globally-unique identifier of a transaction. * - * @param Frontend type - * * @author Robert Varga */ @Beta -public final class TransactionIdentifier implements Identifier { - private static final class Proxy implements Externalizable { +public final class TransactionIdentifier implements WritableIdentifier { + private static final class Proxy implements Externalizable { private static final long serialVersionUID = 1L; - private LocalHistoryIdentifier historyId; + 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) { + Proxy(final LocalHistoryIdentifier historyId, final long transactionId) { this.historyId = Preconditions.checkNotNull(historyId); this.transactionId = transactionId; } @Override public void writeExternal(final ObjectOutput out) throws IOException { - out.writeObject(historyId); - out.writeLong(transactionId); + historyId.writeTo(out); + WritableObjects.writeLong(out, transactionId); } - @SuppressWarnings("unchecked") @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - historyId = (LocalHistoryIdentifier) in.readObject(); - transactionId = in.readLong(); + public void readExternal(final ObjectInput in) throws IOException { + historyId = LocalHistoryIdentifier.readFrom(in); + transactionId = WritableObjects.readLong(in); } private Object readResolve() { - return new TransactionIdentifier<>(historyId, transactionId); + return new TransactionIdentifier(historyId, transactionId); } } private static final long serialVersionUID = 1L; - private final LocalHistoryIdentifier historyId; + private final LocalHistoryIdentifier historyId; private final long transactionId; + private transient String shortString; - public TransactionIdentifier(final @Nonnull LocalHistoryIdentifier historyId, final long transactionId) { + public TransactionIdentifier(@Nonnull final LocalHistoryIdentifier historyId, final long transactionId) { this.historyId = Preconditions.checkNotNull(historyId); this.transactionId = transactionId; } - public LocalHistoryIdentifier getHistoryId() { + public static TransactionIdentifier readFrom(final DataInput in) throws IOException { + final LocalHistoryIdentifier historyId = LocalHistoryIdentifier.readFrom(in); + return new TransactionIdentifier(historyId, WritableObjects.readLong(in)); + } + + @Override + public void writeTo(final DataOutput out) throws IOException { + historyId.writeTo(out); + WritableObjects.writeLong(out, transactionId); + } + + public LocalHistoryIdentifier getHistoryId() { return historyId; } @@ -81,25 +95,35 @@ public final class TransactionIdentifier implements Iden } @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; + } + + return shortString; + } + @Override public String toString() { - return MoreObjects.toStringHelper(TransactionIdentifier.class).add("history", historyId) - .add("transaction", transactionId).toString(); + return toShortString(); } private Object writeReplace() { - return new Proxy<>(historyId, transactionId); + return new Proxy(historyId, transactionId); } }