Improve IdentifiablePayload.toString() implementations 75/100775/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Apr 2022 16:01:13 +0000 (18:01 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Apr 2022 16:42:31 +0000 (18:42 +0200)
We can expose at least the size (and most of the time identity) of the
payload. Let's do that to ease debugging.

JIRA: CONTROLLER-2043
Change-Id: Ia0f1e17ca46de8a9d117d5f8bdb85b246e32be01
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractIdentifiablePayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayload.java

index de9b0bb..0367d15 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore.persisted;
 import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.base.MoreObjects;
 import com.google.common.io.ByteStreams;
 import java.io.DataInput;
 import java.io.Externalizable;
@@ -88,6 +89,11 @@ public abstract class AbstractIdentifiablePayload<T extends Identifier> extends
         return serialized.length;
     }
 
+    @Override
+    public final String toString() {
+        return MoreObjects.toStringHelper(this).add("identifier", identifier).add("size", size()).toString();
+    }
+
     protected final Object writeReplace() {
         return verifyNotNull(externalizableProxy(serialized));
     }
index 3fc636b..6749244 100644 (file)
@@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
 import com.google.common.io.ByteStreams;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.DataInput;
@@ -57,7 +58,7 @@ public abstract class CommitTransactionPayload extends IdentifiablePayload<Trans
     private volatile Entry<TransactionIdentifier, DataTreeCandidateWithVersion> candidate = null;
 
     CommitTransactionPayload() {
-
+        // hidden on purpose
     }
 
     public static @NonNull CommitTransactionPayload create(final TransactionIdentifier transactionId,
@@ -126,6 +127,16 @@ public abstract class CommitTransactionPayload extends IdentifiablePayload<Trans
         return localCandidate;
     }
 
+    @Override
+    public final String toString() {
+        final var helper = MoreObjects.toStringHelper(this);
+        final var localCandidate = candidate;
+        if (localCandidate != null) {
+            helper.add("identifier", candidate.getKey());
+        }
+        return helper.add("size", size()).toString();
+    }
+
     abstract void writeBytes(ObjectOutput out) throws IOException;
 
     abstract DataInput newDataInput();