token_metadata: Add get_host_id and friends

This commit is contained in:
Asias He
2015-06-01 14:08:52 +08:00
parent edee90550c
commit 06a792d6be
2 changed files with 27 additions and 39 deletions

View File

@@ -2,6 +2,7 @@
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#include "utils/UUID.hh"
#include "token_metadata.hh"
#include <experimental/optional>
@@ -160,5 +161,25 @@ void token_metadata::update_host_id(const UUID& host_id, inet_address endpoint)
_endpoint_to_host_id_map[endpoint] = host_id;
}
utils::UUID token_metadata::get_host_id(inet_address endpoint) {
assert(_endpoint_to_host_id_map.count(endpoint));
return _endpoint_to_host_id_map.at(endpoint);
}
gms::inet_address token_metadata::get_endpoint_for_host_id(UUID host_id) {
auto beg = _endpoint_to_host_id_map.cbegin();
auto end = _endpoint_to_host_id_map.cend();
auto it = std::find_if(beg, end, [host_id] (auto x) {
return x.second == host_id;
});
assert(it != end);
return (*it).first;
}
const auto& token_metadata::get_endpoint_to_host_id_map_for_reading() {
return _endpoint_to_host_id_map;
}
}

View File

@@ -252,50 +252,17 @@ public:
* @param endpoint
*/
void update_host_id(const UUID& host_id, inet_address endpoint);
#if 0
/** Return the unique host ID for an end-point. */
public UUID getHostId(InetAddress endpoint)
{
lock.readLock().lock();
try
{
return _endpoint_to_host_id_map.get(endpoint);
}
finally
{
lock.readLock().unlock();
}
}
UUID get_host_id(inet_address endpoint);
/** Return the end-point for a unique host ID */
public InetAddress getEndpointForHostId(UUID hostId)
{
lock.readLock().lock();
try
{
return _endpoint_to_host_id_map.inverse().get(hostId);
}
finally
{
lock.readLock().unlock();
}
}
inet_address get_endpoint_for_host_id(UUID host_id);
/** @return a copy of the endpoint-to-id map for read-only operations */
public Map<InetAddress, UUID> getEndpointToHostIdMapForReading()
{
lock.readLock().lock();
try
{
Map<InetAddress, UUID> readMap = new HashMap<InetAddress, UUID>();
readMap.putAll(_endpoint_to_host_id_map);
return readMap;
}
finally
{
lock.readLock().unlock();
}
}
const auto& get_endpoint_to_host_id_map_for_reading();
#if 0
@Deprecated
public void addBootstrapToken(Token token, InetAddress endpoint)