Merge "Optimizations, Monitoring and Logging"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / identifiers / TransactionIdentifier.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
9 package org.opendaylight.controller.cluster.datastore.identifiers;
10
11 import com.google.common.base.Preconditions;
12
13 public class TransactionIdentifier {
14     private final String memberName;
15     private final long counter;
16
17
18     public TransactionIdentifier(String memberName, long counter) {
19         this.memberName = Preconditions.checkNotNull(memberName, "memberName should not be null");
20         this.counter = counter;
21     }
22
23     public static Builder builder(){
24         return new Builder();
25     }
26
27     @Override
28     public boolean equals(Object o) {
29         if (this == o) {
30             return true;
31         }
32         if (o == null || getClass() != o.getClass()) {
33             return false;
34         }
35
36         TransactionIdentifier that = (TransactionIdentifier) o;
37
38         if (counter != that.counter) {
39             return false;
40         }
41         if (!memberName.equals(that.memberName)) {
42             return false;
43         }
44
45         return true;
46     }
47
48     @Override
49     public int hashCode() {
50         int result = memberName.hashCode();
51         result = 31 * result + (int) (counter ^ (counter >>> 32));
52         return result;
53     }
54
55     @Override public String toString() {
56         final StringBuilder sb =
57             new StringBuilder();
58         sb.append(memberName).append("-txn-").append(counter);
59         return sb.toString();
60     }
61
62     public static class Builder {
63         private String memberName;
64         private long counter;
65
66         public TransactionIdentifier build(){
67             return new TransactionIdentifier(memberName, counter);
68         }
69
70         public Builder memberName(String memberName){
71             this.memberName = memberName;
72             return this;
73         }
74
75         public Builder counter(long counter){
76             this.counter = counter;
77             return this;
78         }
79     }
80 }