1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.net.Address;
22 import org.apache.hadoop.hbase.security.User;
23
24
25
26
27
28 @InterfaceAudience.Private
29 public class ConnectionId {
30 private static final int PRIME = 16777619;
31 final User ticket;
32 final String serviceName;
33 final Address address;
34
35 public ConnectionId(User ticket, String serviceName, Address address) {
36 this.address = address;
37 this.ticket = ticket;
38 this.serviceName = serviceName;
39 }
40
41 public String getServiceName() {
42 return this.serviceName;
43 }
44
45 public Address getAddress() {
46 return address;
47 }
48
49 public User getTicket() {
50 return ticket;
51 }
52
53 @Override
54 public String toString() {
55 return this.address + "/" + this.serviceName + "/" + this.ticket;
56 }
57
58 @Override
59 public int hashCode() {
60 final int prime = 31;
61 int result = 1;
62 result = prime * result + ((address == null) ? 0 : address.hashCode());
63 result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
64 result = prime * result + ((ticket == null) ? 0 : ticket.hashCode());
65 return result;
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj == null) {
74 return false;
75 }
76 if (getClass() != obj.getClass()) {
77 return false;
78 }
79 ConnectionId other = (ConnectionId) obj;
80 if (address == null) {
81 if (other.address != null) {
82 return false;
83 }
84 } else if (!address.equals(other.address)) {
85 return false;
86 }
87 if (serviceName == null) {
88 if (other.serviceName != null) {
89 return false;
90 }
91 } else if (!serviceName.equals(other.serviceName)) {
92 return false;
93 }
94 if (ticket == null) {
95 if (other.ticket != null) {
96 return false;
97 }
98 } else if (!ticket.equals(other.ticket)) {
99 return false;
100 }
101 return true;
102 }
103
104 public static int hashCode(User ticket, String serviceName, Address address){
105 return (address.hashCode() +
106 PRIME * (PRIME * serviceName.hashCode() ^
107 (ticket == null ? 0 : ticket.hashCode())));
108 }
109 }