This is an automated email from the ASF dual-hosted git repository.
dgkimura 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 5d5ee22 GEODE-3991: Update callbacks to take region by reference
(#166)
5d5ee22 is described below
commit 5d5ee22f85cf7733f32f6b455d1b88e493f69f01
Author: David Kimura <[email protected]>
AuthorDate: Mon Dec 18 09:48:47 2017 -0800
GEODE-3991: Update callbacks to take region by reference (#166)
---
clicache/src/Region.cpp | 4 +-
clicache/src/Region.hpp | 22 ++++++++---
clicache/src/impl/CacheLoader.hpp | 12 +++---
clicache/src/impl/ManagedCacheLoader.cpp | 4 +-
clicache/src/impl/ManagedCacheLoader.hpp | 4 +-
clicache/src/native_conditional_shared_ptr.hpp | 43 ++++++++++++++++++++++
cppcache/include/geode/CacheListener.hpp | 4 +-
cppcache/include/geode/CacheLoader.hpp | 4 +-
cppcache/include/geode/CacheWriter.hpp | 2 +-
cppcache/integration-test/TallyLoader.hpp | 4 +-
.../integration-test/ThinClientListenerInit.hpp | 8 ++--
.../ThinClientLocalCacheLoader.hpp | 36 ++++++++----------
.../testThinClientDisconnectionListioner.cpp | 2 +-
cppcache/src/CacheListener.cpp | 5 +--
cppcache/src/CacheLoader.cpp | 2 +-
cppcache/src/CacheWriter.cpp | 2 +-
cppcache/src/LocalRegion.cpp | 10 ++---
17 files changed, 109 insertions(+), 59 deletions(-)
diff --git a/clicache/src/Region.cpp b/clicache/src/Region.cpp
index 895a24b..909599a 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 072c558..ec63a0d 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 cc67a3e..c7c1af7 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(®ion);
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(®ion);
m_loader->Close(gregion);
}
};
diff --git a/clicache/src/impl/ManagedCacheLoader.cpp
b/clicache/src/impl/ManagedCacheLoader.cpp
index 9d5ba28..6b33182 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 57925a7..09d7def 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 0000000..9be6895
--- /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 d93ec8a..f550f5d 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 446dc9d..a3b41ee 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 3e59f84..8614c7c 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 d7b0c0c..ffae462 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 4ed7e6f..17da167 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 e84a81f..f3fadc0 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 b7c0dbc..c4849ee 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 ff55208..679708d 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 4bc9c71..07607a6 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 f8ff46d..727649a 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 b95b9fe..dbc7cf1 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());
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].