public class TransactionIdentifier {
protected static final String TX_SEPARATOR = "-txn-";
- protected String getMemberName() {
- return memberName;
- }
-
- protected long getCounter() {
- return counter;
- }
-
private final String memberName;
private final long counter;
+ private final long timestamp;
private String stringRepresentation;
public TransactionIdentifier(String memberName, long counter) {
this.memberName = Preconditions.checkNotNull(memberName, "memberName should not be null");
this.counter = counter;
+ this.timestamp = System.currentTimeMillis();
}
public String getChainId() {
return "";
}
+ protected String getMemberName() {
+ return memberName;
+ }
+
+ protected long getCounter() {
+ return counter;
+ }
+
+ protected long getTimestamp() {
+ return timestamp;
+ }
+
public static TransactionIdentifier create(String memberName, long counter) {
return new TransactionIdentifier(memberName, counter);
}
if (counter != that.counter) {
return false;
}
+
+ if (timestamp != that.timestamp) {
+ return false;
+ }
+
if (!memberName.equals(that.memberName)) {
return false;
}
public int hashCode() {
int result = memberName.hashCode();
result = 31 * result + (int) (counter ^ (counter >>> 32));
+ result = 31 * result + (int)(timestamp ^ (timestamp >>> 32));
return result;
}
+
@Override
public String toString() {
if(stringRepresentation == null) {
- stringRepresentation = new StringBuilder(memberName.length() + TX_SEPARATOR.length() + 10).
- append(memberName).append(TX_SEPARATOR).append(counter).toString();
+ stringRepresentation = new StringBuilder(memberName.length() + TX_SEPARATOR.length() + 21).
+ append(memberName).append(TX_SEPARATOR).append(counter).append('-').append(timestamp).toString();
}
return stringRepresentation;
package org.opendaylight.controller.cluster.datastore.identifiers;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
assertTrue(txnId.contains("100"));
assertTrue(txnId.contains("99"));
- assertEquals("member-1-chn-99-txn-100", txnId);
+ assertThat(txnId, startsWith("member-1-chn-99-txn-100-"));
}
}
\ No newline at end of file
package org.opendaylight.controller.cluster.datastore.identifiers;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import org.junit.Test;
public class TransactionChainIdentifierTest {
TransactionIdentifier txId1 = transactionChainIdentifier.newTransactionIdentifier();
- assertEquals("member-1-chn-99-txn-1", txId1.toString());
+ assertThat(txId1.toString(), startsWith("member-1-chn-99-txn-1-"));
TransactionIdentifier txId2 = transactionChainIdentifier.newTransactionIdentifier();
- assertEquals("member-1-chn-99-txn-2", txId2.toString());
+ assertThat(txId2.toString(), startsWith("member-1-chn-99-txn-2-"));
}
}
\ No newline at end of file