*/
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 static java.util.Objects.requireNonNull;
+
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 java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.WritableIdentifier;
+import org.opendaylight.yangtools.concepts.WritableObjects;
/**
* Globally-unique identifier of a transaction.
- *
- * @author Robert Varga
*/
-@Beta
-public final class TransactionIdentifier implements Identifier, WritableObject {
+public final class TransactionIdentifier implements WritableIdentifier {
private static final class Proxy implements Externalizable {
+ @Serial
private static final long serialVersionUID = 1L;
+
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;
}
transactionId = WritableObjects.readLong(in);
}
+ @Serial
private Object readResolve() {
return new TransactionIdentifier(historyId, transactionId);
}
}
+ @Serial
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));
}
WritableObjects.writeLong(out, transactionId);
}
- public LocalHistoryIdentifier getHistoryId() {
+ public @NonNull LocalHistoryIdentifier getHistoryId() {
return historyId;
}
}
@Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof TransactionIdentifier)) {
- return false;
+ public boolean equals(final Object obj) {
+ return this == obj || obj instanceof TransactionIdentifier other && 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();
}
- final TransactionIdentifier other = (TransactionIdentifier) o;
- return transactionId == other.transactionId && historyId.equals(other.historyId);
+ return shortString;
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(TransactionIdentifier.class).add("history", historyId)
- .add("transaction", transactionId).toString();
+ return toShortString();
}
+ @Serial
private Object writeReplace() {
return new Proxy(historyId, transactionId);
}