Return shortened string from TransactionIdentifier.toString 14/42314/3
authorTom Pantelis <tpanteli@brocade.com>
Fri, 22 Jul 2016 01:30:36 +0000 (21:30 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 5 Aug 2016 02:46:19 +0000 (02:46 +0000)
For debug logging we need a shortened string for better readability and
grepping. The standard toString is way too long. I changed toString to a
similar compact form that we had before. adding in the frontend generation id
and type, eg

  member-1-datastore-config-fe-1-txn-3
  member-1-datastore-operational-fe-1-chn-2-txn-3

Change-Id: I942eaaa0e8ceedf42eed964f2a2e3a76d8c09806
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java

index 6ad94d2..dac3314 100644 (file)
@@ -8,7 +8,6 @@
 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;
@@ -61,6 +60,7 @@ public final class TransactionIdentifier implements WritableIdentifier {
     private static final long serialVersionUID = 1L;
     private final LocalHistoryIdentifier historyId;
     private final long transactionId;
+    private transient String shortString;
 
     public TransactionIdentifier(final @Nonnull LocalHistoryIdentifier historyId, final long transactionId) {
         this.historyId = Preconditions.checkNotNull(historyId);
@@ -104,10 +104,20 @@ public final class TransactionIdentifier implements WritableIdentifier {
         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() {