Merge "Optimizations, Monitoring and Logging"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / identifiers / ShardTransactionIdentifier.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 ShardTransactionIdentifier {
14     private final String remoteTransactionId;
15
16     public ShardTransactionIdentifier(String remoteTransactionId) {
17         this.remoteTransactionId = Preconditions.checkNotNull(remoteTransactionId, "remoteTransactionId should not be null");
18     }
19
20     public static Builder builder(){
21         return new Builder();
22     }
23
24     @Override
25     public boolean equals(Object o) {
26         if (this == o) {
27             return true;
28         }
29         if (o == null || getClass() != o.getClass()) {
30             return false;
31         }
32
33         ShardTransactionIdentifier that = (ShardTransactionIdentifier) o;
34
35         if (!remoteTransactionId.equals(that.remoteTransactionId)) {
36             return false;
37         }
38
39         return true;
40     }
41
42     @Override
43     public int hashCode() {
44         return remoteTransactionId.hashCode();
45     }
46
47     @Override public String toString() {
48         final StringBuilder sb =
49             new StringBuilder();
50         sb.append("shard-").append(remoteTransactionId);
51         return sb.toString();
52     }
53
54     public static class Builder {
55         private String remoteTransactionId;
56
57         public Builder remoteTransactionId(String remoteTransactionId){
58             this.remoteTransactionId = remoteTransactionId;
59             return this;
60         }
61
62         public ShardTransactionIdentifier build(){
63             return new ShardTransactionIdentifier(remoteTransactionId);
64         }
65
66     }
67 }