[ 
https://issues.apache.org/jira/browse/GEODE-3991?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16295329#comment-16295329
 ] 

ASF GitHub Bot commented on GEODE-3991:
---------------------------------------

dgkimura closed pull request #166: GEODE-3991: Update callbacks to take region 
by reference
URL: https://github.com/apache/geode-native/pull/166
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/clicache/src/Region.cpp b/clicache/src/Region.cpp
index f4f58671..b498e62b 100644
--- a/clicache/src/Region.cpp
+++ b/clicache/src/Region.cpp
@@ -248,8 +248,8 @@ namespace Apache
           {
             return false;
           }
-          auto out1 = 
m_nativeptr->get_shared_ptr()->getCache().createDataOutput();
-          auto out2 = 
m_nativeptr->get_shared_ptr()->getCache().createDataOutput();
+          auto out1 = 
m_nativeptr->get_conditional_shared_ptr()->getCache().createDataOutput();
+          auto out2 = 
m_nativeptr->get_conditional_shared_ptr()->getCache().createDataOutput();
           val1->toData(*out1);
           val2->toData(*out2);
 
diff --git a/clicache/src/Region.hpp b/clicache/src/Region.hpp
index 072c5584..ec63a0df 100644
--- a/clicache/src/Region.hpp
+++ b/clicache/src/Region.hpp
@@ -26,7 +26,7 @@
 
 #include "IRegion.hpp"
 #include "ISubscriptionService.hpp"
-#include "native_shared_ptr.hpp"
+#include "native_conditional_shared_ptr.hpp"
 
 namespace Apache
 {
@@ -271,9 +271,16 @@ namespace Apache
             gcnew Region<TKey, TValue>( nativeptr );
         }
 
+        inline static IRegion<TKey, TValue>^
+        Create(native::Region* nativeptr)
+        {
+          return __nullptr == nativeptr ? nullptr :
+            gcnew Region<TKey, TValue>(nativeptr);
+        }
+
         std::shared_ptr<native::Region> GetNative()
         {
-          return m_nativeptr->get_shared_ptr();
+          return m_nativeptr->get_conditional_shared_ptr();
         }
 
 
@@ -283,8 +290,13 @@ namespace Apache
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
         inline Region( std::shared_ptr<native::Region> nativeptr )
-                               {
-          m_nativeptr = gcnew native_shared_ptr<native::Region>(nativeptr);
+        {
+          m_nativeptr = gcnew 
native_conditional_shared_ptr<native::Region>(nativeptr);
+        }
+
+        inline Region(native::Region* nativeptr)
+        {
+          m_nativeptr = gcnew 
native_conditional_shared_ptr<native::Region>(nativeptr);
         }
 
         inline std::shared_ptr<apache::geode::client::Serializable> 
get(std::shared_ptr<apache::geode::client::CacheableKey>& key, 
std::shared_ptr<apache::geode::client::Serializable>& callbackArg);
@@ -292,7 +304,7 @@ namespace Apache
         bool AreValuesEqual(std::shared_ptr<apache::geode::client::Cacheable>& 
val1, std::shared_ptr<apache::geode::client::Cacheable>& val2);
         bool isPoolInMultiuserMode();
         
-        native_shared_ptr<native::Region>^ m_nativeptr;
+        native_conditional_shared_ptr<native::Region>^ m_nativeptr;
 
       };
 
diff --git a/clicache/src/impl/CacheLoader.hpp 
b/clicache/src/impl/CacheLoader.hpp
index cc67a3e2..c7c1af73 100644
--- a/clicache/src/impl/CacheLoader.hpp
+++ b/clicache/src/impl/CacheLoader.hpp
@@ -41,10 +41,10 @@ namespace Apache
       public interface class ICacheLoaderProxy
       {
       public:
-        std::shared_ptr<apache::geode::client::Cacheable> load( const 
std::shared_ptr<apache::geode::client::Region>& region,
+        std::shared_ptr<apache::geode::client::Cacheable> 
load(apache::geode::client::Region& region,
           const std::shared_ptr<apache::geode::client::CacheableKey>& key, 
const std::shared_ptr<apache::geode::client::Serializable>& helper );
 
-        void close( const std::shared_ptr<apache::geode::client::Region>& 
region );
+        void close(apache::geode::client::Region& region );
       };
 
       generic<class TKey, class TValue>
@@ -61,10 +61,10 @@ namespace Apache
             m_loader = loader;
           }
 
-          virtual std::shared_ptr<apache::geode::client::Cacheable> load( 
const std::shared_ptr<apache::geode::client::Region>& region,
+          virtual std::shared_ptr<apache::geode::client::Cacheable> load( 
apache::geode::client::Region& region,
             const std::shared_ptr<apache::geode::client::CacheableKey>& key, 
const std::shared_ptr<apache::geode::client::Serializable>& helper )
           {
-            IRegion<TKey, TValue>^ gregion = Region<TKey, 
TValue>::Create(region);
+            IRegion<TKey, TValue>^ gregion = Region<TKey, 
TValue>::Create(&region);
 
             TKey gkey = Serializable::GetManagedValueGeneric<TKey>(key);
 
@@ -73,9 +73,9 @@ namespace Apache
             return 
Serializable::GetUnmanagedValueGeneric<TValue>(m_loader->Load(gregion, gkey, 
ghelper));
           }
 
-          virtual void close( const 
std::shared_ptr<apache::geode::client::Region>& region )
+          virtual void close(apache::geode::client::Region& region )
           {
-            IRegion<TKey, TValue>^ gregion = Region<TKey, 
TValue>::Create(region);
+            IRegion<TKey, TValue>^ gregion = Region<TKey, 
TValue>::Create(&region);
             m_loader->Close(gregion);
           }
       };
diff --git a/clicache/src/impl/ManagedCacheLoader.cpp 
b/clicache/src/impl/ManagedCacheLoader.cpp
index 9d5ba28a..6b331825 100644
--- a/clicache/src/impl/ManagedCacheLoader.cpp
+++ b/clicache/src/impl/ManagedCacheLoader.cpp
@@ -213,7 +213,7 @@ namespace apache
         return NULL;
       }
 
-      std::shared_ptr<Cacheable> ManagedCacheLoaderGeneric::load(const 
std::shared_ptr<Region>& region,
+      std::shared_ptr<Cacheable> ManagedCacheLoaderGeneric::load(Region& 
region,
                                                    const 
std::shared_ptr<CacheableKey>& key, const std::shared_ptr<Serializable>& 
aCallbackArgument)
       {
         try {
@@ -228,7 +228,7 @@ namespace apache
         return nullptr;
       }
 
-      void ManagedCacheLoaderGeneric::close(const std::shared_ptr<Region>& 
region)
+      void ManagedCacheLoaderGeneric::close(Region& region)
       {
         try {
           /*
diff --git a/clicache/src/impl/ManagedCacheLoader.hpp 
b/clicache/src/impl/ManagedCacheLoader.hpp
index 57925a71..09d7defe 100644
--- a/clicache/src/impl/ManagedCacheLoader.hpp
+++ b/clicache/src/impl/ManagedCacheLoader.hpp
@@ -97,7 +97,7 @@ namespace apache
         /// will return null.
         /// </returns>
         /// <seealso cref="Apache.Geode.Client.Region.Get" />
-        virtual std::shared_ptr<Cacheable> load(const std::shared_ptr<Region>& 
region,
+        virtual std::shared_ptr<Cacheable> load(Region& region,
           const std::shared_ptr<CacheableKey>& key, const 
std::shared_ptr<Serializable>& aCallbackArgument);
 
         /// <summary>
@@ -116,7 +116,7 @@ namespace apache
         /// <param name="region">the region pointer</param>
         /// <seealso cref="Apache.Geode.Client.Cache.Close" />
         /// <seealso cref="Apache.Geode.Client.Region.DestroyRegion" />
-        virtual void close(const std::shared_ptr<Region>& region);
+        virtual void close(Region& region);
 
         /*
         /// <summary>
diff --git a/clicache/src/native_conditional_shared_ptr.hpp 
b/clicache/src/native_conditional_shared_ptr.hpp
new file mode 100644
index 00000000..9be6895e
--- /dev/null
+++ b/clicache/src/native_conditional_shared_ptr.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "begin_native.hpp"
+#include <memory>
+#include "end_native.hpp"
+
+namespace Apache
+ {
+   namespace Geode
+   {
+     namespace Client
+     {
+
+       template <class _T>
+       public ref class native_conditional_shared_ptr sealed {
+       private:
+         std::shared_ptr<_T>* owned_ptr;
+         _T* unowned_ptr;
+
+       public:
+         native_conditional_shared_ptr(const std::shared_ptr<_T>& ptr) : 
owned_ptr(new std::shared_ptr<_T>(ptr)), unowned_ptr(__nullptr) {}
+         native_conditional_shared_ptr(_T* ptr) : owned_ptr(__nullptr), 
unowned_ptr(ptr) {}
+
+         ~native_conditional_shared_ptr() {
+           native_conditional_shared_ptr::!native_conditional_shared_ptr();
+         }
+
+         !native_conditional_shared_ptr() {
+           delete owned_ptr;
+         }
+
+         inline _T* get() {
+           return __nullptr == owned_ptr ? unowned_ptr : owned_ptr->get();
+         }
+
+         inline std::shared_ptr<_T> get_conditional_shared_ptr() {
+           return owned_ptr ? *owned_ptr : nullptr;
+         }
+
+       };
+     }
+   }
+ }
\ No newline at end of file
diff --git a/cppcache/include/geode/CacheListener.hpp 
b/cppcache/include/geode/CacheListener.hpp
index d93ec8ab..f550f5de 100644
--- a/cppcache/include/geode/CacheListener.hpp
+++ b/cppcache/include/geode/CacheListener.hpp
@@ -183,7 +183,7 @@ class CPPCACHE_EXPORT CacheListener {
    * @see Region::destroyRegion
    */
 
-  virtual void close(const std::shared_ptr<Region>& region);
+  virtual void close(Region& region);
   /**
    * Called when all the endpoints assosiated with region are down.
    * This will be called when all the endpoints are down for the first time.
@@ -192,7 +192,7 @@ class CPPCACHE_EXPORT CacheListener {
    * to the pool.
    * @param region std::shared_ptr<Region> denotes the assosiated region.
    */
-  virtual void afterRegionDisconnected(const std::shared_ptr<Region>& region);
+  virtual void afterRegionDisconnected(Region& region);
 
  protected:
   /**
diff --git a/cppcache/include/geode/CacheLoader.hpp 
b/cppcache/include/geode/CacheLoader.hpp
index 446dc9de..a3b41eef 100644
--- a/cppcache/include/geode/CacheLoader.hpp
+++ b/cppcache/include/geode/CacheLoader.hpp
@@ -68,7 +68,7 @@ class CPPCACHE_EXPORT CacheLoader  {
    *@see Region::get .
    */
   virtual std::shared_ptr<Cacheable> load(
-      const std::shared_ptr<Region>& rp,
+      Region& rp,
       const std::shared_ptr<CacheableKey>& key,
       const std::shared_ptr<Serializable>& aCallbackArgument) = 0;
 
@@ -87,7 +87,7 @@ class CPPCACHE_EXPORT CacheLoader  {
    * @see Cache::close
    * @see Region::destroyRegion
    */
-  virtual void close(const std::shared_ptr<Region>& rp);
+  virtual void close(Region& rp);
 
   virtual ~CacheLoader();
 
diff --git a/cppcache/include/geode/CacheWriter.hpp 
b/cppcache/include/geode/CacheWriter.hpp
index 3e59f849..8614c7ce 100644
--- a/cppcache/include/geode/CacheWriter.hpp
+++ b/cppcache/include/geode/CacheWriter.hpp
@@ -166,7 +166,7 @@ class CPPCACHE_EXPORT CacheWriter {
    * @see Cache::close
    * @see Region::destroyRegion
    */
-  virtual void close(const std::shared_ptr<Region>& rp);
+  virtual void close(Region& rp);
 
   virtual ~CacheWriter();
 
diff --git a/cppcache/integration-test/TallyLoader.hpp 
b/cppcache/integration-test/TallyLoader.hpp
index d7b0c0c4..ffae462d 100644
--- a/cppcache/integration-test/TallyLoader.hpp
+++ b/cppcache/integration-test/TallyLoader.hpp
@@ -38,7 +38,7 @@ class TallyLoader : virtual public CacheLoader {
   virtual ~TallyLoader() {}
 
   std::shared_ptr<Cacheable> load(
-      const std::shared_ptr<Region>& rp,
+      Region& rp,
       const std::shared_ptr<CacheableKey>& key,
       const std::shared_ptr<Serializable>& aCallbackArgument) {
     LOGDEBUG("TallyLoader::load invoked for %d.", m_loads);
@@ -48,7 +48,7 @@ class TallyLoader : virtual public CacheLoader {
     return CacheableInt32::create(m_loads++);
   }
 
-  virtual void close(const std::shared_ptr<Region>& region) { 
LOG("TallyLoader::close"); }
+  virtual void close(Region& region) { LOG("TallyLoader::close"); }
 
   int expectLoads(int expected) {
     int tries = 0;
diff --git a/cppcache/integration-test/ThinClientListenerInit.hpp 
b/cppcache/integration-test/ThinClientListenerInit.hpp
index 4ed7e6f0..17da1678 100644
--- a/cppcache/integration-test/ThinClientListenerInit.hpp
+++ b/cppcache/integration-test/ThinClientListenerInit.hpp
@@ -55,7 +55,7 @@ class ThinClientTallyLoader : public TallyLoader {
   virtual ~ThinClientTallyLoader() {}
 
   std::shared_ptr<Cacheable> load(
-      const std::shared_ptr<Region>& rp,
+      Region& rp,
       const std::shared_ptr<CacheableKey>& key,
       const std::shared_ptr<Serializable>& aCallbackArgument) {
     int32_t loadValue = std::dynamic_pointer_cast<CacheableInt32>(
@@ -64,11 +64,11 @@ class ThinClientTallyLoader : public TallyLoader {
     char lstrvalue[32];
     sprintf(lstrvalue, "%i", loadValue);
     auto lreturnValue = CacheableString::create(lstrvalue);
-    if (key && (!rp->getAttributes()->getEndpoints().empty() ||
-                !rp->getAttributes()->getPoolName().empty())) {
+    if (key && (!rp.getAttributes()->getEndpoints().empty() ||
+                !rp.getAttributes()->getPoolName().empty())) {
       LOGDEBUG("Putting the value (%s) for local region clients only ",
                lstrvalue);
-      rp->put(key, lreturnValue);
+      rp.put(key, lreturnValue);
     }
     return lreturnValue;
   }
diff --git a/cppcache/integration-test/ThinClientLocalCacheLoader.hpp 
b/cppcache/integration-test/ThinClientLocalCacheLoader.hpp
index e84a81f4..f3fadc06 100644
--- a/cppcache/integration-test/ThinClientLocalCacheLoader.hpp
+++ b/cppcache/integration-test/ThinClientLocalCacheLoader.hpp
@@ -42,7 +42,7 @@ class ThinClientTallyLoader : public TallyLoader {
   virtual ~ThinClientTallyLoader() {}
 
   std::shared_ptr<Cacheable> load(
-      const std::shared_ptr<Region>& rp,
+      Region& rp,
       const std::shared_ptr<CacheableKey>& key,
       const std::shared_ptr<Serializable>& aCallbackArgument) {
     int32_t loadValue = std::dynamic_pointer_cast<CacheableInt32>(
@@ -51,33 +51,29 @@ class ThinClientTallyLoader : public TallyLoader {
     char lstrvalue[32];
     sprintf(lstrvalue, "%i", loadValue);
    auto lreturnValue = CacheableString::create(lstrvalue);
-   if (key != nullptr && (!rp->getAttributes()->getEndpoints().empty() ||
-                          !rp->getAttributes()->getPoolName().empty())) {
+   if (key != nullptr && (!rp.getAttributes()->getEndpoints().empty() ||
+                          !rp.getAttributes()->getPoolName().empty())) {
      LOGDEBUG("Putting the value (%s) for local region clients only ",
               lstrvalue);
-     rp->put(key, lreturnValue);
+     rp.put(key, lreturnValue);
     }
     return lreturnValue;
   }
 
-  void close(const std::shared_ptr<Region>& region) {
+  void close(Region& region) {
     LOG(" ThinClientTallyLoader::close() called");
-    if (region != nullptr) {
-      LOGINFO(" Region %s is Destroyed = %d ", region->getName().c_str(),
-              region->isDestroyed());
-      ASSERT(region->isDestroyed() == true,
-             "region.isDestroyed should return true");
-      /*
-      if(region.get() != nullptr && region.get()->getCache() != nullptr){
-        LOGINFO(" Cache Name is Closed = %d ",
-      region.get()->getCache()->isClosed());
-      }else{
-        LOGINFO(" regionPtr or cachePtr is nullptr");
-      }
-      */
-    } else {
-      LOGINFO(" region is nullptr");
+    LOGINFO(" Region %s is Destroyed = %d ", region.getName().c_str(),
+            region.isDestroyed());
+    ASSERT(region.isDestroyed() == true,
+           "region.isDestroyed should return true");
+    /*
+    if(region.get() != nullptr && region.get()->getCache() != nullptr){
+      LOGINFO(" Cache Name is Closed = %d ",
+    region.get()->getCache()->isClosed());
+    }else{
+      LOGINFO(" regionPtr or cachePtr is nullptr");
     }
+    */
   }
 };
 
diff --git a/cppcache/integration-test/testThinClientDisconnectionListioner.cpp 
b/cppcache/integration-test/testThinClientDisconnectionListioner.cpp
index b7c0dbc8..c4849ee2 100644
--- a/cppcache/integration-test/testThinClientDisconnectionListioner.cpp
+++ b/cppcache/integration-test/testThinClientDisconnectionListioner.cpp
@@ -34,7 +34,7 @@ const char* locatorsG =
 using namespace apache::geode::client;
 using namespace test;
 class DisconnectCacheListioner : public CacheListener {
-  void afterRegionDisconnected(const std::shared_ptr<Region>& region) {
+  void afterRegionDisconnected(Region& region) {
     LOG("After Region Disconnected event received");
     isDisconnected = true;
   }
diff --git a/cppcache/src/CacheListener.cpp b/cppcache/src/CacheListener.cpp
index ff55208f..679708dd 100644
--- a/cppcache/src/CacheListener.cpp
+++ b/cppcache/src/CacheListener.cpp
@@ -28,7 +28,7 @@ CacheListener::CacheListener() {}
 
 CacheListener::~CacheListener() {}
 
-void CacheListener::close(const std::shared_ptr<Region>& region) {}
+void CacheListener::close(Region& region) {}
 
 void CacheListener::afterCreate(const EntryEvent& event) {}
 
@@ -46,8 +46,7 @@ void CacheListener::afterRegionClear(const RegionEvent& 
event) {}
 
 void CacheListener::afterRegionLive(const RegionEvent& event) {}
 
-void CacheListener::afterRegionDisconnected(
-    const std::shared_ptr<Region>& region) {}
+void CacheListener::afterRegionDisconnected(Region& region) {}
 }  // namespace client
 }  // namespace geode
 }  // namespace apache
diff --git a/cppcache/src/CacheLoader.cpp b/cppcache/src/CacheLoader.cpp
index 4bc9c71f..07607a63 100644
--- a/cppcache/src/CacheLoader.cpp
+++ b/cppcache/src/CacheLoader.cpp
@@ -26,4 +26,4 @@ CacheLoader::CacheLoader() {}
 
 CacheLoader::~CacheLoader() {}
 
-void CacheLoader::close(const std::shared_ptr<Region>& rp) {}
+void CacheLoader::close(Region& rp) {}
diff --git a/cppcache/src/CacheWriter.cpp b/cppcache/src/CacheWriter.cpp
index f8ff46d9..727649a0 100644
--- a/cppcache/src/CacheWriter.cpp
+++ b/cppcache/src/CacheWriter.cpp
@@ -28,7 +28,7 @@ CacheWriter::CacheWriter() {}
 
 CacheWriter::~CacheWriter() {}
 
-void CacheWriter::close(const std::shared_ptr<Region>& region) {}
+void CacheWriter::close(Region& region) {}
 
 bool CacheWriter::beforeUpdate(const EntryEvent& event) { return true; }
 
diff --git a/cppcache/src/LocalRegion.cpp b/cppcache/src/LocalRegion.cpp
index 9396d36b..96bd6a8e 100644
--- a/cppcache/src/LocalRegion.cpp
+++ b/cppcache/src/LocalRegion.cpp
@@ -729,10 +729,10 @@ void LocalRegion::release(bool invokeCallbacks) {
   if (invokeCallbacks) {
     try {
       if (m_loader != nullptr) {
-        m_loader->close(shared_from_this());
+        m_loader->close(*this);
       }
       if (m_writer != nullptr) {
-        m_writer->close(shared_from_this());
+        m_writer->close(*this);
       }
       // TODO:  shouldn't listener also be here instead of
       // during CacheImpl.close()
@@ -907,7 +907,7 @@ GfErrType LocalRegion::getNoThrow(
       isLoaderInvoked = true;
       /*Update the statistics*/
       int64_t sampleStartNanos = startStatOpTime();
-      value = m_loader->load(shared_from_this(), keyPtr, aCallbackArgument);
+      value = m_loader->load(*this, keyPtr, aCallbackArgument);
       updateStatOpTime(m_regionStats->getStat(),
                        m_regionStats->getLoaderCallTimeId(), sampleStartNanos);
       m_regionStats->incLoaderCallsCompleted();
@@ -2718,7 +2718,7 @@ GfErrType LocalRegion::invokeCacheListenerForRegionEvent(
           m_cacheImpl->getCachePerfStats().incListenerCalls();
           if (eventFlags.isCacheClose()) {
             eventStr = "close";
-            m_listener->close(shared_from_this());
+            m_listener->close(*this);
             m_cacheImpl->getCachePerfStats().incListenerCalls();
           }
           break;
@@ -3109,7 +3109,7 @@ void LocalRegion::invokeAfterAllEndPointDisconnected() {
   if (m_listener != nullptr) {
     int64_t sampleStartNanos = startStatOpTime();
     try {
-      m_listener->afterRegionDisconnected(shared_from_this());
+      m_listener->afterRegionDisconnected(*this);
     } catch (const Exception& ex) {
       LOGERROR("Exception in CacheListener::afterRegionDisconnected: %s: %s",
                ex.getName().c_str(), ex.what());


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Implement list jdbc-region-mapping command
> ------------------------------------------
>
>                 Key: GEODE-3991
>                 URL: https://issues.apache.org/jira/browse/GEODE-3991
>             Project: Geode
>          Issue Type: Sub-task
>          Components: docs, regions
>            Reporter: Fred Krone
>            Assignee: Lynn Gallinat
>
> NAME
> list jdbc-mapping
> SYNOPSIS
> List the all the JDBC stores for all regions.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to