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 boolean equals(Object obj) {
61 if (obj instanceof ConnectionId) {
62 ConnectionId id = (ConnectionId) obj;
63 return address.equals(id.address) &&
64 ((ticket != null && ticket.equals(id.ticket)) ||
65 (ticket == id.ticket)) &&
66 this.serviceName == id.serviceName;
67 }
68 return false;
69 }
70
71 @Override
72 public int hashCode() {
73 return hashCode(ticket,serviceName,address);
74 }
75
76 public static int hashCode(User ticket, String serviceName, InetSocketAddress address){
77 return (address.hashCode() +
78 PRIME * (PRIME * serviceName.hashCode() ^
79 (ticket == null ? 0 : ticket.hashCode())));
80 }
81 }