0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NamespaceCache.cc
Go to the documentation of this file.
1 /*
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 of the
9  * License, or any later version.
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 
22 #include "Common/Compat.h"
23 #include "NamespaceCache.h"
24 
25 using namespace Hypertable;
26 using namespace std;
27 
29  ConnectionManagerPtr &conn_manager, Hyperspace::SessionPtr &hyperspace,
30  ApplicationQueueInterfacePtr &app_queue, NameIdMapperPtr &namemap, Lib::Master::ClientPtr &master_client,
31  TableCachePtr &table_cache, uint32_t default_timeout_ms, Client *client)
32  : m_props(props), m_range_locator(range_locator), m_comm(conn_manager->get_comm()),
33  m_conn_manager(conn_manager), m_hyperspace(hyperspace), m_app_queue(app_queue),
34  m_namemap(namemap), m_master_client(master_client), m_table_cache(table_cache),
35  m_timeout_ms(default_timeout_ms), m_client(client) {
36 
37  HT_ASSERT(m_props && m_range_locator && conn_manager && m_hyperspace &&
39 }
40 
41 NamespacePtr NamespaceCache::get(const string &name) {
42  lock_guard<mutex> lock(m_mutex);
43  string id;
44  bool is_namespace = false;
45  NamespaceMap::iterator it = m_namespace_map.find(name);
46 
47  if (it != m_namespace_map.end()) {
48  return it->second;
49  }
50 
51  if (!m_namemap->name_to_id(name, id, &is_namespace) || !is_namespace)
53 
54  NamespacePtr ns =
55  make_shared<Namespace>(name, id, m_props, m_conn_manager, m_hyperspace,
58  m_client);
59  m_namespace_map.insert(make_pair(name, ns));
60  return ns;
61 }
62 
63 bool NamespaceCache::remove(const string &name) {
64  lock_guard<mutex> lock(m_mutex);
65  bool found = false;
66  NamespaceMap::iterator it = m_namespace_map.find(name);
67 
68  if (it != m_namespace_map.end()) {
69  found = true;
70  m_namespace_map.erase(it);
71  }
72  return found;
73 }
Lib::Master::ClientPtr m_master_client
bool remove(const std::string &name)
ConnectionManagerPtr m_conn_manager
RangeLocatorPtr m_range_locator
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
STL namespace.
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
Definition: Namespace.h:333
std::shared_ptr< Client > ClientPtr
Definition: Client.h:156
#define HT_ASSERT(_e_)
Definition: Logger.h:396
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
NamespaceCache(PropertiesPtr &props, RangeLocatorPtr &range_locator, ConnectionManagerPtr &conn_manager, Hyperspace::SessionPtr &hyperspace, ApplicationQueueInterfacePtr &app_queue, NameIdMapperPtr &namemap, Lib::Master::ClientPtr &master_client, TableCachePtr &table_cache, uint32_t default_timeout_ms, Client *client)
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
Compatibility Macros for C/C++.
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
Hypertable definitions
Hyperspace::SessionPtr m_hyperspace
std::shared_ptr< TableCache > TableCachePtr
Smart pointer to TableCache.
Definition: TableCache.h:103
ApplicationQueueInterfacePtr m_app_queue
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
std::shared_ptr< NameIdMapper > NameIdMapperPtr
Smart pointer to NameIdMapper.
Definition: NameIdMapper.h:121
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
NamespacePtr get(const std::string &name)