| 1 | /******************************************************************** |
| 2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Zhanwei Wang |
| 6 | ********************************************************************/ |
| 7 | /******************************************************************** |
| 8 | * 2014 - |
| 9 | * open source under Apache License Version 2.0 |
| 10 | ********************************************************************/ |
| 11 | /** |
| 12 | * Licensed to the Apache Software Foundation (ASF) under one |
| 13 | * or more contributor license agreements. See the NOTICE file |
| 14 | * distributed with this work for additional information |
| 15 | * regarding copyright ownership. The ASF licenses this file |
| 16 | * to you under the Apache License, Version 2.0 (the |
| 17 | * "License"); you may not use this file except in compliance |
| 18 | * with the License. You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
| 27 | */ |
| 28 | #ifndef _HDFS_LIBHDFS3_RPC_RPCCHANNELKEY_H_ |
| 29 | #define _HDFS_LIBHDFS3_RPC_RPCCHANNELKEY_H_ |
| 30 | |
| 31 | #include "client/Token.h" |
| 32 | #include "Hash.h" |
| 33 | #include "RpcAuth.h" |
| 34 | #include "RpcConfig.h" |
| 35 | #include "RpcProtocolInfo.h" |
| 36 | #include "RpcServerInfo.h" |
| 37 | #include <Memory.h> |
| 38 | |
| 39 | namespace Hdfs { |
| 40 | namespace Internal { |
| 41 | |
| 42 | class RpcChannelKey { |
| 43 | public: |
| 44 | RpcChannelKey(const RpcAuth & a, const RpcProtocolInfo & p, |
| 45 | const RpcServerInfo & s, const RpcConfig & c); |
| 46 | |
| 47 | public: |
| 48 | size_t hash_value() const; |
| 49 | |
| 50 | const RpcAuth & getAuth() const { |
| 51 | return auth; |
| 52 | } |
| 53 | |
| 54 | const RpcConfig & getConf() const { |
| 55 | return conf; |
| 56 | } |
| 57 | |
| 58 | const RpcProtocolInfo & getProtocol() const { |
| 59 | return protocol; |
| 60 | } |
| 61 | |
| 62 | const RpcServerInfo & getServer() const { |
| 63 | return server; |
| 64 | } |
| 65 | |
| 66 | bool operator ==(const RpcChannelKey & other) const { |
| 67 | return this->auth == other.auth && this->protocol == other.protocol |
| 68 | && this->server == other.server && this->conf == other.conf |
| 69 | && ((token == NULL && other.token == NULL) |
| 70 | || (token && other.token && *token == *other.token)); |
| 71 | } |
| 72 | |
| 73 | const Token & getToken() const { |
| 74 | assert(token != NULL); |
| 75 | return *token; |
| 76 | } |
| 77 | |
| 78 | bool hasToken() { |
| 79 | return token != NULL; |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | const RpcAuth auth; |
| 84 | const RpcConfig conf; |
| 85 | const RpcProtocolInfo protocol; |
| 86 | const RpcServerInfo server; |
| 87 | shared_ptr<Token> token; |
| 88 | }; |
| 89 | |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | HDFS_HASH_DEFINE(::Hdfs::Internal::RpcChannelKey); |
| 94 | |
| 95 | #endif /* _HDFS_LIBHDFS3_RPC_RPCCHANNELKEY_H_ */ |
| 96 | |