0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProxyMap.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3
9  * of the License.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #ifndef AsyncComm_ProxyMap_h
30 #define AsyncComm_ProxyMap_h
31 
32 #include <AsyncComm/CommBuf.h>
33 
34 #include <Common/InetAddr.h>
35 #include <Common/SockAddrMap.h>
36 #include <Common/String.h>
37 
38 #include <mutex>
39 
40 namespace Hypertable {
41 
49  public:
51  ProxyAddressInfo(const String &h, InetAddr a) : hostname(h), addr(a) { }
54  };
55 
57  typedef std::unordered_map<String, ProxyAddressInfo> ProxyMapT;
58 
79  class ProxyMap {
80 
81  public:
82 
98  void update_mapping(const String &proxy, const String &hostname,
99  const InetAddr &addr,ProxyMapT &invalidated_map,
100  ProxyMapT &new_map);
101 
128  void update_mappings(String &mappings, ProxyMapT &invalidated_map,
129  ProxyMapT &new_map);
130 
140  void remove_mapping(const String &proxy, ProxyMapT &remove_map);
141 
150  bool get_mapping(const String &proxy, String &hostname, InetAddr &addr);
151 
159  String get_proxy(InetAddr &addr);
160 
164  void get_map(ProxyMapT &map) {
165  map = m_forward_map;
166  }
167 
181 
182  String to_str();
183 
184  private:
185 
198  void invalidate_old_mapping(const String &proxy, const InetAddr &addr,
199  ProxyMapT &invalidated_mappings);
200 
211  void invalidate(const String &proxy, ProxyMapT &invalidated_mappings);
212 
215 
217  ProxyMapT m_forward_map;
218 
221  };
222 
224 }
225 
226 #endif // AsyncComm_ProxyMap_h
static std::mutex mutex
Definition: Logger.cc:43
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
bool get_mapping(const String &proxy, String &hostname, InetAddr &addr)
Returns proxy map data for proxy.
Definition: ProxyMap.cc:108
void get_map(ProxyMapT &map)
Returns the forward map (proxy name to ProxyAddressInfo)
Definition: ProxyMap.h:164
CommBufPtr create_update_message()
Creates a proxy map update message.
Definition: ProxyMap.cc:127
String get_proxy(InetAddr &addr)
Returns proxy name for addr.
Definition: ProxyMap.cc:118
std::mutex m_mutex
Mutex for serializing concurrent access
Definition: ProxyMap.h:214
Encapsulate an internet address.
Definition: InetAddr.h:66
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Holds address and hostname associated with a proxy name.
Definition: ProxyMap.h:48
void invalidate_old_mapping(const String &proxy, const InetAddr &addr, ProxyMapT &invalidated_mappings)
Invalidates (removes) mapping, if changed, from forward and reverse maps.
Definition: ProxyMap.cc:142
std::unordered_map< String, ProxyAddressInfo > ProxyMapT
Forward mapping hash type from proxy name to ProxyAddressInfo.
Definition: ProxyMap.h:57
SockAddrMap< String > m_reverse_map
Reverse map from IP address to proxy name.
Definition: ProxyMap.h:220
Declarations for SockAddrMap.
Hypertable definitions
void remove_mapping(const String &proxy, ProxyMapT &remove_map)
Removes a mapping.
Definition: ProxyMap.cc:100
void update_mappings(String &mappings, ProxyMapT &invalidated_map, ProxyMapT &new_map)
Update mappings from proxy map update message string.
Definition: ProxyMap.cc:55
void invalidate(const String &proxy, ProxyMapT &invalidated_mappings)
Invalidates (removes) mapping from forward and reverse maps.
Definition: ProxyMap.cc:167
Declarations for CommBuf.
ProxyAddressInfo(const String &h, InetAddr a)
Definition: ProxyMap.h:51
Internet address wrapper classes and utility functions.
ProxyMapT m_forward_map
Forward map from proxy name to ProxyAddressInfo.
Definition: ProxyMap.h:217
void update_mapping(const String &proxy, const String &hostname, const InetAddr &addr, ProxyMapT &invalidated_map, ProxyMapT &new_map)
Updates a proxy name mapping.
Definition: ProxyMap.cc:38
A String class based on std::string.
Maps a set of proxy names to their associated IP addresses.
Definition: ProxyMap.h:79