2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.ipc
;
20 import java
.util
.Objects
;
22 import org
.apache
.hadoop
.hbase
.net
.Address
;
23 import org
.apache
.hadoop
.hbase
.security
.User
;
24 import org
.apache
.yetus
.audience
.InterfaceAudience
;
27 * This class holds the address and the user ticket, etc. The client connections
28 * to servers are uniquely identified by <remoteAddress, ticket, serviceName>
30 @InterfaceAudience.Private
32 private static final int PRIME
= 16777619;
34 final String serviceName
;
35 final Address address
;
37 public ConnectionId(User ticket
, String serviceName
, Address address
) {
38 this.address
= address
;
40 this.serviceName
= serviceName
;
43 public String
getServiceName() {
44 return this.serviceName
;
47 public Address
getAddress() {
51 public User
getTicket() {
56 public String
toString() {
57 return this.address
.toString() + "/" + this.serviceName
+ "/" + this.ticket
;
61 public boolean equals(Object obj
) {
62 if (obj
instanceof ConnectionId
) {
63 ConnectionId id
= (ConnectionId
) obj
;
64 return address
.equals(id
.address
) &&
65 ((ticket
!= null && ticket
.equals(id
.ticket
)) ||
66 (ticket
== id
.ticket
)) && Objects
.equals(this.serviceName
, id
.serviceName
);
71 @Override // simply use the default Object#hashcode() ?
72 public int hashCode() {
73 return hashCode(ticket
,serviceName
,address
);
76 public static int hashCode(User ticket
, String serviceName
, Address address
) {
77 return (address
.hashCode() +
78 PRIME
* (PRIME
* serviceName
.hashCode() ^
79 (ticket
== null ?
0 : ticket
.hashCode())));