You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2018/01/08 18:24:14 UTC

[geode-native] branch develop updated: GEODE-3998: Links Cache::Name to DistributeSystem::Name (#178)

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6eb04a9  GEODE-3998: Links Cache::Name to DistributeSystem::Name (#178)
6eb04a9 is described below

commit 6eb04a988354e6384c0dd81a7db085971ecf573c
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Mon Jan 8 10:24:12 2018 -0800

    GEODE-3998: Links Cache::Name to DistributeSystem::Name (#178)
---
 cppcache/include/geode/Cache.hpp        |  4 ++--
 cppcache/include/geode/CacheFactory.hpp |  4 +---
 cppcache/src/Cache.cpp                  | 10 +++++-----
 cppcache/src/CacheFactory.cpp           | 32 +++++++++++++++++++++++++++-----
 cppcache/src/CacheImpl.cpp              | 13 ++++---------
 cppcache/src/CacheImpl.hpp              |  7 +++----
 6 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/cppcache/include/geode/Cache.hpp b/cppcache/include/geode/Cache.hpp
index e654441..dc93c67 100644
--- a/cppcache/include/geode/Cache.hpp
+++ b/cppcache/include/geode/Cache.hpp
@@ -250,8 +250,8 @@ class CPPCACHE_EXPORT Cache : public GeodeCache,
   /**
    * @brief constructors
    */
-  Cache(const std::string& name, std::shared_ptr<Properties> dsProp,
-        bool ignorePdxUnreadFields, bool readPdxSerialized,
+  Cache(std::shared_ptr<Properties> dsProp, bool ignorePdxUnreadFields,
+        bool readPdxSerialized,
         const std::shared_ptr<AuthInitialize>& authInitialize);
 
   std::unique_ptr<CacheImpl> m_cacheImpl;
diff --git a/cppcache/include/geode/CacheFactory.hpp b/cppcache/include/geode/CacheFactory.hpp
index 6be4004..ce3c921 100644
--- a/cppcache/include/geode/CacheFactory.hpp
+++ b/cppcache/include/geode/CacheFactory.hpp
@@ -145,9 +145,7 @@ class CPPCACHE_EXPORT CacheFactory {
   bool pdxReadSerialized;
   std::shared_ptr<AuthInitialize> authInitialize;
 
-  Cache create(
-      const std::string name,
-      const std::shared_ptr<CacheAttributes>& attrs = nullptr) const;
+  Cache create(const std::shared_ptr<CacheAttributes>& attrs) const;
 
   friend class CppCacheLibrary;
   friend class RegionFactory;
diff --git a/cppcache/src/Cache.cpp b/cppcache/src/Cache.cpp
index 1ed20db..1e515a5 100644
--- a/cppcache/src/Cache.cpp
+++ b/cppcache/src/Cache.cpp
@@ -134,12 +134,12 @@ std::shared_ptr<CacheTransactionManager> Cache::getCacheTransactionManager()
 
 TypeRegistry& Cache::getTypeRegistry() { return *(m_typeRegistry.get()); }
 
-Cache::Cache(const std::string& name, std::shared_ptr<Properties> dsProp,
-             bool ignorePdxUnreadFields, bool readPdxSerialized,
+Cache::Cache(std::shared_ptr<Properties> dsProp, bool ignorePdxUnreadFields,
+             bool readPdxSerialized,
              const std::shared_ptr<AuthInitialize>& authInitialize) {
-  m_cacheImpl = std::unique_ptr<CacheImpl>(new CacheImpl(
-      this, name, DistributedSystem::create(DEFAULT_DS_NAME, dsProp),
-      ignorePdxUnreadFields, readPdxSerialized, authInitialize));
+  m_cacheImpl = std::unique_ptr<CacheImpl>(
+      new CacheImpl(this, DistributedSystem::create(DEFAULT_DS_NAME, dsProp),
+                    ignorePdxUnreadFields, readPdxSerialized, authInitialize));
   m_cacheImpl->getDistributedSystem().connect(this);
   m_typeRegistry =
       std::unique_ptr<TypeRegistry>(new TypeRegistry(m_cacheImpl.get()));
diff --git a/cppcache/src/CacheFactory.cpp b/cppcache/src/CacheFactory.cpp
index 8b60322..162caaa 100644
--- a/cppcache/src/CacheFactory.cpp
+++ b/cppcache/src/CacheFactory.cpp
@@ -70,8 +70,31 @@ CacheFactory::CacheFactory(
       dsProp(properties) {}
 
 Cache CacheFactory::create() const {
-  LOGFINE("CacheFactory called DistributedSystem::connect");
-  auto cache = create(DEFAULT_CACHE_NAME, nullptr);
+  auto cache =
+      Cache(dsProp, ignorePdxUnreadFields, pdxReadSerialized, authInitialize);
+
+  try {
+    auto&& cacheXml =
+        cache.getDistributedSystem().getSystemProperties().cacheXMLFile();
+    if (!cacheXml.empty()) {
+      cache.initializeDeclarativeCache(cacheXml);
+    } else {
+      cache.m_cacheImpl->initServices();
+    }
+  } catch (const apache::geode::client::RegionExistsException&) {
+    LOGWARN("Attempt to create existing regions declaratively");
+  } catch (const apache::geode::client::Exception&) {
+    if (!cache.isClosed()) {
+      cache.close();
+    }
+    throw;
+  } catch (...) {
+    if (!cache.isClosed()) {
+      cache.close();
+    }
+    throw apache::geode::client::UnknownException(
+        "Exception thrown in CacheFactory::create");
+  }
 
   auto& cacheImpl = cache.m_cacheImpl;
   const auto& serializationRegistry = cacheImpl->getSerializationRegistry();
@@ -105,9 +128,8 @@ Cache CacheFactory::create() const {
 }
 
 Cache CacheFactory::create(
-    std::string name,
-    const std::shared_ptr<CacheAttributes>& attrs /*= nullptr*/) const {
-  auto cache = Cache(name, dsProp, ignorePdxUnreadFields, pdxReadSerialized,
+    const std::shared_ptr<CacheAttributes>& attrs) const {
+  auto cache = Cache(dsProp, ignorePdxUnreadFields, pdxReadSerialized,
                      authInitialize);
   cache.m_cacheImpl->setAttributes(attrs);
 
diff --git a/cppcache/src/CacheImpl.cpp b/cppcache/src/CacheImpl.cpp
index 6990c8a..fb2c1f1 100644
--- a/cppcache/src/CacheImpl.cpp
+++ b/cppcache/src/CacheImpl.cpp
@@ -46,12 +46,10 @@
 
 using namespace apache::geode::client;
 
-CacheImpl::CacheImpl(Cache* c, const std::string& name,
-                     std::unique_ptr<DistributedSystem> sys, bool iPUF,
-                     bool readPdxSerialized,
+CacheImpl::CacheImpl(Cache* c, std::unique_ptr<DistributedSystem> sys,
+                     bool iPUF, bool readPdxSerialized,
                      const std::shared_ptr<AuthInitialize>& authInitialize)
-    : m_name(name),
-      m_defaultPool(nullptr),
+    : m_defaultPool(nullptr),
       m_ignorePdxUnreadFields(iPUF),
       m_readPdxSerialized(readPdxSerialized),
       m_closed(false),
@@ -217,10 +215,7 @@ CacheImpl::~CacheImpl() {
 }
 
 const std::string& CacheImpl::getName() const {
-  if (m_closed || m_destroyPending) {
-    throw CacheClosedException("Cache::getName: cache closed");
-  }
-  return m_name;
+  return m_distributedSystem->getName();
 }
 
 bool CacheImpl::isClosed() const { return m_closed; }
diff --git a/cppcache/src/CacheImpl.hpp b/cppcache/src/CacheImpl.hpp
index 65fa0d4..cdc362f 100644
--- a/cppcache/src/CacheImpl.hpp
+++ b/cppcache/src/CacheImpl.hpp
@@ -213,9 +213,9 @@ class CPPCACHE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
   /**
    * @brief constructors
    */
-  CacheImpl(Cache* c, const std::string& name,
-            std::unique_ptr<DistributedSystem> sys, bool ignorePdxUnreadFields,
-            bool readPdxSerialized, const std::shared_ptr<AuthInitialize>& authInitialize);
+  CacheImpl(Cache* c, std::unique_ptr<DistributedSystem> sys,
+            bool ignorePdxUnreadFields, bool readPdxSerialized,
+            const std::shared_ptr<AuthInitialize>& authInitialize);
 
   void initServices();
   EvictionController* getEvictionController();
@@ -334,7 +334,6 @@ class CPPCACHE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
 
   void setCache(Cache* cache);
 
-  std::string m_name;
   bool m_closed;
   bool m_initialized;
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].