Remove use of {String,UUID}Identifier
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / identifiers / ChainedTransactionIdentifier.java
index 1aec854785f05be6fe5a07a4aafac6fc1e855f99..4753437d2501ef535cb7babb9a891bbd64c0d608 100644 (file)
@@ -8,20 +8,39 @@
 package org.opendaylight.controller.cluster.datastore.identifiers;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
 
 /**
  * A TransactionIdentifier which is tied to a backend transaction chain.
  */
 public class ChainedTransactionIdentifier extends TransactionIdentifier {
     private final String chainId;
+    private Supplier<String> stringRepresentation;
 
-    public ChainedTransactionIdentifier(final String memberName, final long counter, final String chainId) {
-        super(memberName, counter);
-        this.chainId = Preconditions.checkNotNull(chainId);
+    public ChainedTransactionIdentifier(final TransactionChainIdentifier chainId, final long txnCounter) {
+        super(chainId.getMemberName(), txnCounter);
+        Preconditions.checkNotNull(chainId);
+        this.chainId = chainId.toString();
+        stringRepresentation = Suppliers.memoize(new Supplier<String>() {
+            @Override
+            public String get() {
+                return new StringBuilder(chainId.toString().length() + TX_SEPARATOR.length() + 21).
+                        append(chainId).append(TX_SEPARATOR).append(getCounter()).append('-').
+                        append(getTimestamp()).toString();
+            }
+        });
     }
 
+
     @Override
     public String getChainId() {
         return chainId;
     }
+
+    @Override
+    public String toString() {
+        return stringRepresentation.get();
+    }
+
 }