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