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
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.identifiers;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Supplier;
12 import com.google.common.base.Suppliers;
13
14 /**
15  * A TransactionIdentifier which is tied to a backend transaction chain.
16  */
17 public class ChainedTransactionIdentifier extends TransactionIdentifier {
18     private final String chainId;
19     private Supplier<String> stringRepresentation;
20
21     public ChainedTransactionIdentifier(final TransactionChainIdentifier chainId, final long txnCounter) {
22         super(chainId.getMemberName(), txnCounter);
23         Preconditions.checkNotNull(chainId);
24         this.chainId = chainId.toString();
25         stringRepresentation = Suppliers.memoize(new Supplier<String>() {
26             @Override
27             public String get() {
28                 return new StringBuilder(chainId.toString().length() + TX_SEPARATOR.length() + 21).
29                         append(chainId).append(TX_SEPARATOR).append(getCounter()).append('-').
30                         append(getTimestamp()).toString();
31             }
32         });
33     }
34
35
36     @Override
37     public String getChainId() {
38         return chainId;
39     }
40
41     @Override
42     public String toString() {
43         return stringRepresentation.get();
44     }
45
46 }