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/04/03 22:22:59 UTC
[geode-native] branch develop updated: GEODE-4912: Return value for
DistributedSystem::create (#246)
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 cddcacd GEODE-4912: Return value for DistributedSystem::create (#246)
cddcacd is described below
commit cddcacdb21d9e49546ec8f4082db882522e6608b
Author: M. Oleske <mo...@users.noreply.github.com>
AuthorDate: Tue Apr 3 15:22:57 2018 -0700
GEODE-4912: Return value for DistributedSystem::create (#246)
---
README.md | 2 +
clicache/src/DistributedSystem.cpp | 25 ++--
clicache/src/DistributedSystem.hpp | 6 +-
cppcache/include/geode/DistributedSystem.hpp | 37 ++----
cppcache/src/Cache.cpp | 3 +-
cppcache/src/CacheImpl.cpp | 170 ++++++++++++---------------
cppcache/src/CacheImpl.hpp | 10 +-
cppcache/src/DistributedSystem.cpp | 152 ++++--------------------
cppcache/src/DistributedSystemImpl.cpp | 114 ++++++++++++++++--
cppcache/src/DistributedSystemImpl.hpp | 22 +++-
10 files changed, 258 insertions(+), 283 deletions(-)
diff --git a/README.md b/README.md
index 2233b0e..3e63a8e 100644
--- a/README.md
+++ b/README.md
@@ -46,3 +46,5 @@ for both object code and source code.
The following provides more details on the included cryptographic software:
* Apache Geode links to and uses [OpenSSL](https://www.openssl.org/) ciphers.
+
+
diff --git a/clicache/src/DistributedSystem.cpp b/clicache/src/DistributedSystem.cpp
index 7dd1859..9e99b33 100644
--- a/clicache/src/DistributedSystem.cpp
+++ b/clicache/src/DistributedSystem.cpp
@@ -135,13 +135,14 @@ namespace Apache
// TODO AppDomain should we be able to create a DS directly?
_GF_MG_EXCEPTION_TRY2
- auto nativeptr = native::DistributedSystem::create(marshal_as<std::string>(name),
+ auto nativeDistributedSystem = native::DistributedSystem::create(marshal_as<std::string>(name),
config->GetNative());
- nativeptr->connect(cache->GetNative().get());
+ nativeDistributedSystem.connect(cache->GetNative().get());
ManagedPostConnect(cache);
- return gcnew DistributedSystem(std::move(nativeptr));
+ return gcnew DistributedSystem(std::unique_ptr<native::DistributedSystem>(
+ new native::DistributedSystem(std::move(nativeDistributedSystem))));
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -153,8 +154,8 @@ namespace Apache
Serializable::UnregisterNativesGeneric();
DistributedSystem::UnregisterBuiltinManagedTypes(cache);
- m_nativeptr->get()->disconnect();
- GC::KeepAlive(m_nativeptr);
+ m_nativeDistributedSystem->get()->disconnect();
+ GC::KeepAlive(m_nativeDistributedSystem);
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -439,7 +440,7 @@ namespace Apache
_GF_MG_EXCEPTION_TRY2
return Apache::Geode::Client::SystemProperties::Create(
- &(m_nativeptr->get()->getSystemProperties()));
+ &(m_nativeDistributedSystem->get()->getSystemProperties()));
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -448,11 +449,11 @@ namespace Apache
{
try
{
- return marshal_as<String^>(m_nativeptr->get()->getName().c_str());
+ return marshal_as<String^>(m_nativeDistributedSystem->get()->getName());
}
finally
{
- GC::KeepAlive(m_nativeptr);
+ GC::KeepAlive(m_nativeDistributedSystem);
}
}
@@ -470,14 +471,14 @@ namespace Apache
return instance;
}
- DistributedSystem::DistributedSystem(std::unique_ptr<native::DistributedSystem> nativeptr)
+ DistributedSystem::DistributedSystem(std::unique_ptr<native::DistributedSystem> nativeDistributedSystem)
{
- m_nativeptr = gcnew native_conditional_unique_ptr<native::DistributedSystem>(std::move(nativeptr));
+ m_nativeDistributedSystem = gcnew native_conditional_unique_ptr<native::DistributedSystem>(std::move(nativeDistributedSystem));
}
- DistributedSystem::DistributedSystem(native::DistributedSystem* nativeptr)
+ DistributedSystem::DistributedSystem(native::DistributedSystem* nativeDistributedSystem)
{
- m_nativeptr = gcnew native_conditional_unique_ptr<native::DistributedSystem>(nativeptr);
+ m_nativeDistributedSystem = gcnew native_conditional_unique_ptr<native::DistributedSystem>(nativeDistributedSystem);
}
DistributedSystem::~DistributedSystem()
diff --git a/clicache/src/DistributedSystem.hpp b/clicache/src/DistributedSystem.hpp
index 78a71f3..c186550 100644
--- a/clicache/src/DistributedSystem.hpp
+++ b/clicache/src/DistributedSystem.hpp
@@ -122,7 +122,7 @@ namespace Apache
/// </returns>
static DistributedSystem^ Create(native::DistributedSystem* nativeptr);
- DistributedSystem(std::unique_ptr<native::DistributedSystem> nativeptr);
+ DistributedSystem(std::unique_ptr<native::DistributedSystem> nativeDistributedSystem);
delegate void cliCallback(apache::geode::client::Cache& cache);
@@ -147,7 +147,7 @@ namespace Apache
native::DistributedSystem& GetNative()
{
- return *(m_nativeptr->get());
+ return *(m_nativeDistributedSystem->get());
}
private:
@@ -169,7 +169,7 @@ namespace Apache
/// </summary>
~DistributedSystem();
- native_conditional_unique_ptr<native::DistributedSystem>^ m_nativeptr;
+ native_conditional_unique_ptr<native::DistributedSystem>^ m_nativeDistributedSystem;
/// <summary>
diff --git a/cppcache/include/geode/DistributedSystem.hpp b/cppcache/include/geode/DistributedSystem.hpp
index 393bc14..87346fa 100644
--- a/cppcache/include/geode/DistributedSystem.hpp
+++ b/cppcache/include/geode/DistributedSystem.hpp
@@ -56,6 +56,13 @@ class _GEODE_EXPORT DistributedSystem {
* @brief public methods
*/
public:
+ DistributedSystem() = delete;
+ ~DistributedSystem() noexcept;
+ DistributedSystem(const DistributedSystem&) = delete;
+ DistributedSystem& operator=(const DistributedSystem&) = delete;
+ DistributedSystem(DistributedSystem&&);
+ DistributedSystem& operator=(DistributedSystem&&) = delete;
+
/**
* Initializes the Native Client system to be able to connect to the
* Geode Java servers. If the name string is empty, then the default
@@ -63,8 +70,9 @@ class _GEODE_EXPORT DistributedSystem {
* @throws IllegalStateException if GFCPP variable is not set and
* product installation directory cannot be determined
**/
- static std::unique_ptr<DistributedSystem> create(
- const std::string& name, const std::shared_ptr<Properties>& configPtr = nullptr);
+ static DistributedSystem create(
+ const std::string& name,
+ const std::shared_ptr<Properties>& configPtr = nullptr);
/**
* @brief connects from the distributed system
@@ -87,16 +95,9 @@ class _GEODE_EXPORT DistributedSystem {
/** Returns the name that identifies the distributed system instance
* @return name
*/
- virtual const std::string& getName() const;
+ const std::string& getName() const;
- statistics::StatisticsManager* getStatisticsManager() const {
- return m_statisticsManager.get();
- }
-
- /**
- * @brief destructor
- */
- virtual ~DistributedSystem();
+ statistics::StatisticsManager* getStatisticsManager() const;
protected:
/**
@@ -106,19 +107,7 @@ class _GEODE_EXPORT DistributedSystem {
std::unique_ptr<SystemProperties> sysProps);
private:
- std::string m_name;
- bool m_connected;
- std::unique_ptr<statistics::StatisticsManager> m_statisticsManager;
- std::unique_ptr<SystemProperties> m_sysProps;
-
- public:
- DistributedSystemImpl* m_impl;
-
- private:
- DistributedSystem(const DistributedSystem&);
- const DistributedSystem& operator=(const DistributedSystem&);
-
- void logSystemInformation() const;
+ std::unique_ptr<DistributedSystemImpl> m_impl;
friend class CacheRegionHelper;
friend class DistributedSystemImpl;
diff --git a/cppcache/src/Cache.cpp b/cppcache/src/Cache.cpp
index 3315f43..681645e 100644
--- a/cppcache/src/Cache.cpp
+++ b/cppcache/src/Cache.cpp
@@ -137,8 +137,9 @@ TypeRegistry& Cache::getTypeRegistry() { return *(m_typeRegistry.get()); }
Cache::Cache(std::shared_ptr<Properties> dsProp, bool ignorePdxUnreadFields,
bool readPdxSerialized,
const std::shared_ptr<AuthInitialize>& authInitialize) {
+ auto distributedSystem = DistributedSystem::create(DEFAULT_DS_NAME, dsProp);
m_cacheImpl = std::unique_ptr<CacheImpl>(
- new CacheImpl(this, DistributedSystem::create(DEFAULT_DS_NAME, dsProp),
+ new CacheImpl(this, std::move(distributedSystem),
ignorePdxUnreadFields, readPdxSerialized, authInitialize));
m_cacheImpl->getDistributedSystem().connect(this);
m_typeRegistry =
diff --git a/cppcache/src/CacheImpl.cpp b/cppcache/src/CacheImpl.cpp
index 06852db..f119f8f 100644
--- a/cppcache/src/CacheImpl.cpp
+++ b/cppcache/src/CacheImpl.cpp
@@ -15,7 +15,6 @@
* limitations under the License.
*/
#include <string>
-#include <string>
#include <ace/OS.h>
#include <geode/CacheStatistics.hpp>
@@ -46,15 +45,15 @@
using namespace apache::geode::client;
-CacheImpl::CacheImpl(Cache* c, std::unique_ptr<DistributedSystem> sys,
- bool iPUF, bool readPdxSerialized,
+CacheImpl::CacheImpl(Cache* c, DistributedSystem&& distributedSystem, bool iPUF,
+ bool readPdxSerialized,
const std::shared_ptr<AuthInitialize>& authInitialize)
: m_defaultPool(nullptr),
m_ignorePdxUnreadFields(iPUF),
m_readPdxSerialized(readPdxSerialized),
m_closed(false),
m_initialized(false),
- m_distributedSystem(std::move(sys)),
+ m_distributedSystem(std::move(distributedSystem)),
m_cache(c),
m_cond(m_mutex),
m_attributes(nullptr),
@@ -70,15 +69,15 @@ CacheImpl::CacheImpl(Cache* c, std::unique_ptr<DistributedSystem> sys,
m_pdxTypeRegistry(nullptr),
m_expiryTaskManager(
std::unique_ptr<ExpiryTaskManager>(new ExpiryTaskManager())),
- m_clientProxyMembershipIDFactory(m_distributedSystem->getName()),
+ m_clientProxyMembershipIDFactory(m_distributedSystem.getName()),
m_threadPool(new ThreadPool(
- m_distributedSystem->getSystemProperties().threadPoolSize())),
+ m_distributedSystem.getSystemProperties().threadPoolSize())),
m_authInitialize(authInitialize) {
m_cacheTXManager = std::shared_ptr<InternalCacheTransactionManager2PC>(
new InternalCacheTransactionManager2PCImpl(this));
m_regions = new MapOfRegionWithLock();
- auto& prop = m_distributedSystem->getSystemProperties();
+ auto& prop = m_distributedSystem.getSystemProperties();
if (prop.heapLRULimitEnabled()) {
m_evictionControllerPtr =
new EvictionController(prop.heapLRULimit(), prop.heapLRUDelta(), this);
@@ -105,7 +104,7 @@ void CacheImpl::initServices() {
m_tcrConnectionManager->init();
m_remoteQueryServicePtr = std::make_shared<RemoteQueryService>(this);
// StartAdminRegion
- auto& prop = m_distributedSystem->getSystemProperties();
+ auto& prop = m_distributedSystem.getSystemProperties();
if (prop.statisticsEnabled()) {
m_adminRegion = AdminRegion::create(this);
}
@@ -148,7 +147,8 @@ CacheImpl::RegionKind CacheImpl::getRegionKind(
regionKind = THINCLIENT_REGION;
}
} else if (!regionAttributes.getPoolName().empty()) {
- auto pPtr = getCache()->getPoolManager().find(regionAttributes.getPoolName());
+ auto pPtr =
+ getCache()->getPoolManager().find(regionAttributes.getPoolName());
if ((pPtr != nullptr && (pPtr->getSubscriptionRedundancy() > 0 ||
pPtr->getSubscriptionEnabled())) ||
m_tcrConnectionManager->isDurable()) {
@@ -171,6 +171,7 @@ int CacheImpl::removeRegion(const char* name) {
MapOfRegionGuard guard(m_regions->mutex());
return m_regions->unbind(name);
}
+
std::shared_ptr<QueryService> CacheImpl::getQueryService(bool noInit) {
if (m_defaultPool != nullptr) {
if (m_defaultPool->isDestroyed()) {
@@ -188,19 +189,20 @@ std::shared_ptr<QueryService> CacheImpl::getQueryService(bool noInit) {
}
return m_remoteQueryServicePtr;
}
- std::shared_ptr<QueryService> CacheImpl::getQueryService(const char* poolName) {
- if (poolName == nullptr || strlen(poolName) == 0) {
- throw IllegalArgumentException("PoolName is nullptr or not defined..");
- }
- auto pool = getCache()->getPoolManager().find(poolName);
-
- if (pool != nullptr) {
- if (pool->isDestroyed()) {
- throw IllegalStateException("Pool has been destroyed.");
- }
- return pool->getQueryService();
- } else {
- throw IllegalArgumentException("Pool not found..");
+
+std::shared_ptr<QueryService> CacheImpl::getQueryService(const char* poolName) {
+ if (poolName == nullptr || strlen(poolName) == 0) {
+ throw IllegalArgumentException("PoolName is nullptr or not defined..");
+ }
+ auto pool = getCache()->getPoolManager().find(poolName);
+
+ if (pool != nullptr) {
+ if (pool->isDestroyed()) {
+ throw IllegalStateException("Pool has been destroyed.");
+ }
+ return pool->getQueryService();
+ } else {
+ throw IllegalArgumentException("Pool not found..");
}
}
@@ -215,7 +217,7 @@ CacheImpl::~CacheImpl() {
}
const std::string& CacheImpl::getName() const {
- return m_distributedSystem->getName();
+ return m_distributedSystem.getName();
}
bool CacheImpl::isClosed() const { return m_closed; }
@@ -226,8 +228,8 @@ void CacheImpl::setAttributes(const std::shared_ptr<CacheAttributes>& attrs) {
}
}
-DistributedSystem& CacheImpl::getDistributedSystem() const {
- return *m_distributedSystem;
+DistributedSystem& CacheImpl::getDistributedSystem() {
+ return m_distributedSystem;
}
void CacheImpl::sendNotificationCloseMsgs() {
@@ -281,12 +283,12 @@ void CacheImpl::close(bool keepalive) {
++q) {
// TODO: remove dynamic_cast here by having RegionInternal in the regions
// map
- auto rImpl =
- std::dynamic_pointer_cast<RegionInternal>((*q).int_id_);
- if (rImpl != nullptr) {
- rImpl->destroyRegionNoThrow(
- nullptr, false, CacheEventFlags::LOCAL | CacheEventFlags::CACHE_CLOSE);
- }
+ auto rImpl = std::dynamic_pointer_cast<RegionInternal>((*q).int_id_);
+ if (rImpl != nullptr) {
+ rImpl->destroyRegionNoThrow(
+ nullptr, false,
+ CacheEventFlags::LOCAL | CacheEventFlags::CACHE_CLOSE);
+ }
}
if (m_evictionControllerPtr != nullptr) {
@@ -325,8 +327,7 @@ void CacheImpl::close(bool keepalive) {
bool CacheImpl::isCacheDestroyPending() const { return m_destroyPending; }
void CacheImpl::validateRegionAttributes(
- const std::string& name,
- const RegionAttributes regionAttributes) const {
+ const std::string& name, const RegionAttributes regionAttributes) const {
auto&& kind = getRegionKind(regionAttributes);
if (regionAttributes.m_clientNotificationEnabled && kind == CPP_REGION) {
throw UnsupportedOperationException(
@@ -338,17 +339,16 @@ void CacheImpl::validateRegionAttributes(
// We'll pass a nullptr loader function pointer and let the region.get method to
// do a load using a real C++ loader, instead of passing a member function
// pointer here
-void CacheImpl::createRegion(
- std::string name,
- RegionAttributes regionAttributes,
- std::shared_ptr<Region>& regionPtr) {
+void CacheImpl::createRegion(std::string name,
+ RegionAttributes regionAttributes,
+ std::shared_ptr<Region>& regionPtr) {
{
ACE_Guard<ACE_Thread_Mutex> _guard(m_initDoneLock);
if (!m_initDone) {
if (regionAttributes.getPoolName().empty()) {
m_tcrConnectionManager->init();
m_remoteQueryServicePtr = std::make_shared<RemoteQueryService>(this);
- auto& prop = m_distributedSystem->getSystemProperties();
+ auto& prop = m_distributedSystem.getSystemProperties();
if (prop.statisticsEnabled()) {
m_adminRegion = AdminRegion::create(this);
}
@@ -379,10 +379,10 @@ void CacheImpl::createRegion(
"\" region exists in local cache");
}
- auto csptr = std::make_shared<CacheStatistics>();
+ auto cacheStatistics = std::make_shared<CacheStatistics>();
try {
rpImpl = createRegion_internal(name, nullptr, regionAttributes,
- csptr, false);
+ cacheStatistics, false);
} catch (const AuthenticationFailedException&) {
throw;
} catch (const AuthenticationRequiredException&) {
@@ -397,20 +397,22 @@ void CacheImpl::createRegion(
throw UnknownException("Cache::createRegion: Failed to create Region \"" +
name + "\" due to unknown exception.");
}
+
if (rpImpl == nullptr) {
throw RegionCreationFailedException(
"Cache::createRegion: Failed to create Region \"" + name + "\"");
}
+
regionPtr = rpImpl;
rpImpl->addDisMessToQueue();
// Instantiate a PersistenceManager object if DiskPolicy is overflow
if (regionAttributes.getDiskPolicy() == DiskPolicyType::OVERFLOWS) {
- auto pmPtr = regionAttributes.getPersistenceManager();
+ auto pmPtr = regionAttributes.getPersistenceManager();
if (pmPtr == nullptr) {
throw NullPointerException(
"PersistenceManager could not be instantiated");
}
- auto props = regionAttributes.getPersistenceProperties();
+ auto props = regionAttributes.getPersistenceProperties();
pmPtr->init(regionPtr, props);
rpImpl->setPersistenceManager(pmPtr);
}
@@ -421,7 +423,7 @@ void CacheImpl::createRegion(
// When region is created, added that region name in client meta data
// service to fetch its
// metadata for single hop.
- auto& props = m_distributedSystem->getSystemProperties();
+ auto& props = m_distributedSystem.getSystemProperties();
if (!props.isGridClient()) {
const auto& poolName = regionAttributes.getPoolName();
if (!poolName.empty()) {
@@ -445,8 +447,6 @@ void CacheImpl::createRegion(
// schedule the root region expiry if regionExpiry enabled.
rpImpl->setRegionExpiryTask();
rpImpl->releaseReadLock();
- // LOGFINE( "Returning from CacheImpl::createRegion call for Region %s",
- // regionPtr->getFullPath() );
}
/**
@@ -502,9 +502,8 @@ void CacheImpl::getRegion(const std::string& path,
std::shared_ptr<RegionInternal> CacheImpl::createRegion_internal(
const std::string& name, const std::shared_ptr<RegionInternal>& rootRegion,
- const RegionAttributes& attrs, const std::shared_ptr<CacheStatistics>& csptr,
- bool shared) {
-
+ const RegionAttributes& attrs,
+ const std::shared_ptr<CacheStatistics>& csptr, bool shared) {
std::shared_ptr<RegionInternal> rptr = nullptr;
RegionKind regionKind = getRegionKind(attrs);
const auto& poolName = attrs.getPoolName();
@@ -512,12 +511,6 @@ std::shared_ptr<RegionInternal> CacheImpl::createRegion_internal(
const std::string cacheEndpoints =
m_attributes ? m_attributes->getEndpoints() : "";
- /*if(m_defaultPool != nullptr && (poolName == nullptr || strlen(poolName) ==
- 0))
- {
- attrs->setPoolName(m_defaultPool->getName());
- }*/
-
if (!poolName.empty()) {
auto pool = getCache()->getPoolManager().find(poolName);
if (pool != nullptr && !pool->isDestroyed()) {
@@ -580,7 +573,7 @@ void CacheImpl::rootRegions(std::vector<std::shared_ptr<Region>>& regions) {
regions.reserve(static_cast<int32_t>(m_regions->current_size()));
for (MapOfRegionWithLock::iterator q = m_regions->begin();
q != m_regions->end(); ++q) {
- if ((*q).int_id_->isDestroyed() == false) {
+ if (!(*q).int_id_->isDestroyed()) {
regions.push_back((*q).int_id_);
}
}
@@ -592,7 +585,7 @@ EvictionController* CacheImpl::getEvictionController() {
void CacheImpl::readyForEvents() {
bool autoReadyForEvents =
- m_distributedSystem->getSystemProperties().autoReadyForEvents();
+ m_distributedSystem.getSystemProperties().autoReadyForEvents();
bool isDurable = m_tcrConnectionManager->isDurable();
if (!isDurable && autoReadyForEvents) {
@@ -700,64 +693,55 @@ RegionFactory CacheImpl::createRegionFactory(RegionShortcut preDefinedRegion) {
std::map<std::string, RegionAttributes> CacheImpl::getRegionShortcut() {
std::map<std::string, RegionAttributes> preDefined;
- {
- // PROXY
- auto regAttr_PROXY = RegionAttributes();
- regAttr_PROXY.setCachingEnabled(false);
- preDefined["PROXY"] = regAttr_PROXY;
- }
+ // PROXY
+ auto regAttr_PROXY = RegionAttributes();
+ regAttr_PROXY.setCachingEnabled(false);
+ preDefined["PROXY"] = regAttr_PROXY;
- {
- // CACHING_PROXY
- auto regAttr_CACHING_PROXY = RegionAttributes();
- regAttr_CACHING_PROXY.setCachingEnabled(true);
- preDefined["CACHING_PROXY"] = regAttr_CACHING_PROXY;
- }
+ // CACHING_PROXY
+ auto regAttr_CACHING_PROXY = RegionAttributes();
+ regAttr_CACHING_PROXY.setCachingEnabled(true);
+ preDefined["CACHING_PROXY"] = regAttr_CACHING_PROXY;
- {
- // CACHING_PROXY_ENTRY_LRU
- auto regAttr_CACHING_PROXY_LRU = RegionAttributes();
- regAttr_CACHING_PROXY_LRU.setCachingEnabled(true);
- regAttr_CACHING_PROXY_LRU.setLruEntriesLimit(DEFAULT_LRU_MAXIMUM_ENTRIES);
- preDefined["CACHING_PROXY_ENTRY_LRU"] = regAttr_CACHING_PROXY_LRU;
- }
+ // CACHING_PROXY_ENTRY_LRU
+ auto regAttr_CACHING_PROXY_LRU = RegionAttributes();
+ regAttr_CACHING_PROXY_LRU.setCachingEnabled(true);
+ regAttr_CACHING_PROXY_LRU.setLruEntriesLimit(DEFAULT_LRU_MAXIMUM_ENTRIES);
+ preDefined["CACHING_PROXY_ENTRY_LRU"] = regAttr_CACHING_PROXY_LRU;
- {
- // LOCAL
- auto regAttr_LOCAL = RegionAttributes();
- preDefined["LOCAL"] = regAttr_LOCAL;
- }
+ // LOCAL
+ auto regAttr_LOCAL = RegionAttributes();
+ preDefined["LOCAL"] = regAttr_LOCAL;
- {
- // LOCAL_ENTRY_LRU
- auto regAttr_LOCAL_LRU = RegionAttributes();
- regAttr_LOCAL_LRU.setLruEntriesLimit(DEFAULT_LRU_MAXIMUM_ENTRIES);
- preDefined["LOCAL_ENTRY_LRU"] = regAttr_LOCAL_LRU;
- }
+ // LOCAL_ENTRY_LRU
+ auto regAttr_LOCAL_LRU = RegionAttributes();
+ regAttr_LOCAL_LRU.setLruEntriesLimit(DEFAULT_LRU_MAXIMUM_ENTRIES);
+ preDefined["LOCAL_ENTRY_LRU"] = regAttr_LOCAL_LRU;
return preDefined;
}
std::shared_ptr<PdxTypeRegistry> CacheImpl::getPdxTypeRegistry() const {
return m_pdxTypeRegistry;
- }
+}
std::shared_ptr<SerializationRegistry> CacheImpl::getSerializationRegistry()
- const {
- return m_serializationRegistry;
+ const {
+ return m_serializationRegistry;
}
ThreadPool* CacheImpl::getThreadPool() { return m_threadPool; }
std::shared_ptr<CacheTransactionManager>
CacheImpl::getCacheTransactionManager() {
return m_cacheTXManager;
-} std::shared_ptr<MemberListForVersionStamp> CacheImpl::getMemberListForVersionStamp() {
+}
+
+std::shared_ptr<MemberListForVersionStamp>
+CacheImpl::getMemberListForVersionStamp() {
static auto versionStampMemIdList =
new std::shared_ptr<MemberListForVersionStamp>(
new MemberListForVersionStamp());
return *versionStampMemIdList;
}
-void CacheImpl::setCache(Cache* cache) {
- m_cache = cache;
-}
+void CacheImpl::setCache(Cache* cache) { m_cache = cache; }
diff --git a/cppcache/src/CacheImpl.hpp b/cppcache/src/CacheImpl.hpp
index 21bd643..d0d9203 100644
--- a/cppcache/src/CacheImpl.hpp
+++ b/cppcache/src/CacheImpl.hpp
@@ -142,7 +142,7 @@ class _GEODE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
* Returns the distributed system that this cache was
* {@link CacheFactory::create created} with.
*/
- DistributedSystem& getDistributedSystem() const;
+ DistributedSystem& getDistributedSystem();
/**
* Terminates this object cache and releases all the local resources.
@@ -214,7 +214,7 @@ class _GEODE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
/**
* @brief constructors
*/
- CacheImpl(Cache* c, std::unique_ptr<DistributedSystem> sys,
+ CacheImpl(Cache* c, DistributedSystem&& distributedSystem,
bool ignorePdxUnreadFields, bool readPdxSerialized,
const std::shared_ptr<AuthInitialize>& authInitialize);
@@ -268,7 +268,9 @@ class _GEODE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
}
void setPdxReadSerialized(bool val) { m_readPdxSerialized = val; }
+
bool getPdxReadSerialized() { return m_readPdxSerialized; }
+
bool isCacheDestroyPending() const;
static std::map<std::string, RegionAttributes> getRegionShortcut();
@@ -337,7 +339,7 @@ class _GEODE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
bool m_closed;
bool m_initialized;
- std::unique_ptr<DistributedSystem> m_distributedSystem;
+ DistributedSystem m_distributedSystem;
ClientProxyMembershipIDFactory m_clientProxyMembershipIDFactory;
MapOfRegionWithLock* m_regions;
Cache* m_cache;
@@ -362,7 +364,7 @@ class _GEODE_EXPORT CacheImpl : private NonCopyable, private NonAssignable {
friend class CacheFactory;
friend class Cache;
- friend class DistributedSystem;
+ friend class DistributedSystemImpl;
};
} // namespace client
} // namespace geode
diff --git a/cppcache/src/DistributedSystem.cpp b/cppcache/src/DistributedSystem.cpp
index 3851fec..b3c385b 100644
--- a/cppcache/src/DistributedSystem.cpp
+++ b/cppcache/src/DistributedSystem.cpp
@@ -25,21 +25,13 @@
#include <geode/SystemProperties.hpp>
#include <geode/DataOutput.hpp>
-#include "config.h"
-#include "version.h"
-
#include "CppCacheLibrary.hpp"
#include "Utils.hpp"
#include "util/Log.hpp"
-#include "statistics/StatisticsManager.hpp"
#include "ExpiryTaskManager.hpp"
#include "CacheImpl.hpp"
#include "TcrMessage.hpp"
#include "DistributedSystemImpl.hpp"
-#include "RegionStats.hpp"
-#include "PoolStatistics.hpp"
-#include "CacheRegionHelper.hpp"
-#include "DiffieHellman.hpp"
namespace apache {
namespace geode {
@@ -47,56 +39,18 @@ namespace client {
using namespace apache::geode::statistics;
-DistributedSystem::DistributedSystem(
- const std::string& name,
- std::unique_ptr<SystemProperties> sysProps)
- : m_name(name),
- m_statisticsManager(nullptr),
- m_sysProps(std::move(sysProps)),
- m_connected(false) {
- LOGDEBUG("DistributedSystem::DistributedSystem");
- if (!m_sysProps->securityClientDhAlgo().empty()) {
- DiffieHellman::initOpenSSLFuncPtrs();
- }
-}
-DistributedSystem::~DistributedSystem() {}
-
-void DistributedSystem::logSystemInformation() const {
- std::string gfcpp = CppCacheLibrary::getProductDir();
- LOGCONFIG("Using Geode Native Client Product Directory: %s", gfcpp.c_str());
-
- // Add version information, source revision, current directory etc.
- LOGCONFIG("Product version: %s",
- PRODUCT_VENDOR " " PRODUCT_NAME " " PRODUCT_VERSION
- " (" PRODUCT_BITS ") " PRODUCT_BUILDDATE);
- LOGCONFIG("Source revision: %s", PRODUCT_SOURCE_REVISION);
- LOGCONFIG("Source repository: %s", PRODUCT_SOURCE_REPOSITORY);
-
- ACE_utsname u;
- ACE_OS::uname(&u);
- LOGCONFIG(
- "Running on: SystemName=%s Machine=%s Host=%s Release=%s Version=%s",
- u.sysname, u.machine, u.nodename, u.release, u.version);
-
-#ifdef _WIN32
- const uint32_t pathMax = _MAX_PATH;
-#else
- const uint32_t pathMax = PATH_MAX;
-#endif
- ACE_TCHAR cwd[pathMax + 1];
- (void)ACE_OS::getcwd(cwd, pathMax);
- LOGCONFIG("Current directory: %s", cwd);
- LOGCONFIG("Current value of PATH: %s", ACE_OS::getenv("PATH"));
-#ifndef _WIN32
- const char* ld_libpath = ACE_OS::getenv("LD_LIBRARY_PATH");
- LOGCONFIG("Current library path: %s",
- ld_libpath == nullptr ? "nullptr" : ld_libpath);
-#endif
- // Log the Geode system properties
- m_sysProps->logSettings();
+DistributedSystem::DistributedSystem(const std::string& name,
+ std::unique_ptr<SystemProperties> sysProps)
+ : m_impl(new DistributedSystemImpl(name, this, std::move(sysProps))) {}
+
+DistributedSystem::DistributedSystem(DistributedSystem&& moved)
+ : m_impl(std::move(moved.m_impl)) {
+ m_impl->m_implementee = this;
}
-std::unique_ptr<DistributedSystem> DistributedSystem::create(
+DistributedSystem::~DistributedSystem() noexcept = default;
+
+DistributedSystem DistributedSystem::create(
const std::string& _name, const std::shared_ptr<Properties>& configPtr) {
// TODO global - Refactory out the static initialization
// Trigger other library initialization.
@@ -133,7 +87,7 @@ std::unique_ptr<DistributedSystem> DistributedSystem::create(
}
try {
- std::string gfcpp = CppCacheLibrary::getProductDir();
+ CppCacheLibrary::getProductDir();
} catch (const Exception&) {
LOGERROR(
"Unable to determine Product Directory. Please set the "
@@ -141,94 +95,28 @@ std::unique_ptr<DistributedSystem> DistributedSystem::create(
throw;
}
- auto distributedSystem = std::unique_ptr<DistributedSystem>(
- new DistributedSystem(name, std::move(sysProps)));
- if (!distributedSystem) {
- throw NullPointerException("DistributedSystem::connect: new failed");
- }
- distributedSystem->m_impl =
- new DistributedSystemImpl(name.c_str(), distributedSystem.get());
+ auto distributedSystem = DistributedSystem(name, std::move(sysProps));
- distributedSystem->logSystemInformation();
LOGCONFIG("Starting the Geode Native Client");
return distributedSystem;
}
-void DistributedSystem::connect(Cache* cache) {
- if (m_connected == true) {
- throw AlreadyConnectedException(
- "DistributedSystem::connect: already connected, call getInstance to "
- "get it");
- }
-
- try {
- m_impl->connect();
- } catch (const apache::geode::client::Exception& e) {
- LOGERROR("Exception caught during client initialization: %s", e.what());
- std::string msg = "DistributedSystem::connect: caught exception: ";
- msg.append(e.what());
- throw NotConnectedException(msg.c_str());
- } catch (const std::exception& e) {
- LOGERROR("Exception caught during client initialization: %s", e.what());
- std::string msg = "DistributedSystem::connect: caught exception: ";
- msg.append(e.what());
- throw NotConnectedException(msg.c_str());
- } catch (...) {
- LOGERROR("Unknown exception caught during client initialization");
- throw NotConnectedException(
- "DistributedSystem::connect: caught unknown exception");
- }
+void DistributedSystem::connect(Cache* cache) { m_impl->connect(cache); }
- auto cacheImpl = CacheRegionHelper::getCacheImpl(cache);
- try {
- m_statisticsManager =
- std::unique_ptr<StatisticsManager>(new StatisticsManager(
- m_sysProps->statisticsArchiveFile().c_str(),
- m_sysProps->statisticsSampleInterval(),
- m_sysProps->statisticsEnabled(), cacheImpl,
- m_sysProps->durableClientId().c_str(), m_sysProps->durableTimeout(),
- m_sysProps->statsFileSizeLimit(),
- m_sysProps->statsDiskSpaceLimit()));
- cacheImpl->m_cacheStats =
- new CachePerfStats(getStatisticsManager()->getStatisticsFactory());
- }
- catch (const NullPointerException&) {
- Log::close();
- throw;
- }
+void DistributedSystem::disconnect() { m_impl->disconnect(); }
- m_connected = true;
+SystemProperties& DistributedSystem::getSystemProperties() const {
+ return m_impl->getSystemProperties();
}
-void DistributedSystem::disconnect() {
- if (!m_connected) {
- throw NotConnectedException(
- "DistributedSystem::disconnect: connect "
- "not called");
- }
-
- if (m_impl) {
- m_impl->disconnect();
- delete m_impl;
- m_impl = nullptr;
- }
-
- LOGFINEST("Deleted DistributedSystemImpl");
-
- LOGCONFIG("Stopped the Geode Native Client");
-
- // TODO global - log stays global so lets move this
- Log::close();
-
- m_connected = false;
+const std::string& DistributedSystem::getName() const {
+ return m_impl->getName();
}
-SystemProperties& DistributedSystem::getSystemProperties() const {
- return *m_sysProps;
+statistics::StatisticsManager* DistributedSystem::getStatisticsManager() const {
+ return m_impl->getStatisticsManager();
}
-const std::string& DistributedSystem::getName() const { return m_name; }
-
} // namespace client
} // namespace geode
} // namespace apache
diff --git a/cppcache/src/DistributedSystemImpl.cpp b/cppcache/src/DistributedSystemImpl.cpp
index cc6f573..de47a8c 100644
--- a/cppcache/src/DistributedSystemImpl.cpp
+++ b/cppcache/src/DistributedSystemImpl.cpp
@@ -18,7 +18,16 @@
#include <geode/SystemProperties.hpp>
#include "DistributedSystemImpl.hpp"
+#include "config.h"
+#include "version.h"
#include "util/Log.hpp"
+#include "statistics/StatisticsManager.hpp"
+#include "CppCacheLibrary.hpp"
+#include "RegionStats.hpp"
+#include "PoolStatistics.hpp"
+#include "CacheRegionHelper.hpp"
+#include "DiffieHellman.hpp"
+#include "CacheImpl.hpp"
namespace apache {
namespace geode {
@@ -28,28 +37,112 @@ volatile bool DistributedSystemImpl::m_isCliCallbackSet = false;
std::map<int, CliCallbackMethod> DistributedSystemImpl::m_cliCallbackMap;
ACE_Recursive_Thread_Mutex DistributedSystemImpl::m_cliCallbackLock;
-DistributedSystemImpl::DistributedSystemImpl(const char* name,
- DistributedSystem* implementee)
- : m_name(name == 0 ? "" : name), m_implementee(implementee) {
+DistributedSystemImpl::DistributedSystemImpl(
+ std::string name, DistributedSystem* implementee,
+ std::unique_ptr<SystemProperties> sysProps)
+ : m_name(name),
+ m_implementee(implementee),
+ m_statisticsManager(nullptr),
+ m_sysProps(std::move(sysProps)),
+ m_connected(false) {
+ if (!m_sysProps->securityClientDhAlgo().empty()) {
+ DiffieHellman::initOpenSSLFuncPtrs();
+ }
+ logSystemInformation();
}
DistributedSystemImpl::~DistributedSystemImpl() {
LOGFINE("Destroyed DistributedSystemImpl");
}
-void DistributedSystemImpl::connect() {}
+void DistributedSystemImpl::connect(Cache* cache) {
+ if (m_connected == true) {
+ throw AlreadyConnectedException(
+ "DistributedSystem::connect: already connected, call getInstance to "
+ "get it");
+ }
+
+ auto cacheImpl = CacheRegionHelper::getCacheImpl(cache);
+ try {
+ m_statisticsManager =
+ std::unique_ptr<StatisticsManager>(new StatisticsManager(
+ m_sysProps->statisticsArchiveFile().c_str(),
+ m_sysProps->statisticsSampleInterval(),
+ m_sysProps->statisticsEnabled(), cacheImpl,
+ m_sysProps->durableClientId().c_str(), m_sysProps->durableTimeout(),
+ m_sysProps->statsFileSizeLimit(),
+ m_sysProps->statsDiskSpaceLimit()));
+ cacheImpl->m_cacheStats =
+ new CachePerfStats(getStatisticsManager()->getStatisticsFactory());
+ } catch (const NullPointerException&) {
+ Log::close();
+ throw;
+ }
+
+ m_connected = true;
+}
+
+void DistributedSystemImpl::logSystemInformation() const {
+ auto productDir = CppCacheLibrary::getProductDir();
+ LOGCONFIG("Using Geode Native Client Product Directory: " + productDir);
+
+ // Add version information, source revision, current directory etc.
+ LOGCONFIG("Product version: %s",
+ PRODUCT_VENDOR " " PRODUCT_NAME " " PRODUCT_VERSION
+ " (" PRODUCT_BITS ") " PRODUCT_BUILDDATE);
+ LOGCONFIG("Source revision: %s", PRODUCT_SOURCE_REVISION);
+ LOGCONFIG("Source repository: %s", PRODUCT_SOURCE_REPOSITORY);
+
+ ACE_utsname u;
+ ACE_OS::uname(&u);
+ LOGCONFIG(
+ "Running on: SystemName=%s Machine=%s Host=%s Release=%s Version=%s",
+ u.sysname, u.machine, u.nodename, u.release, u.version);
+
+#ifdef _WIN32
+ const uint32_t pathMax = _MAX_PATH;
+#else
+ const uint32_t pathMax = PATH_MAX;
+#endif
+ ACE_TCHAR cwd[pathMax + 1];
+ (void)ACE_OS::getcwd(cwd, pathMax);
+ LOGCONFIG("Current directory: %s", cwd);
+ LOGCONFIG("Current value of PATH: %s", ACE_OS::getenv("PATH"));
+#ifndef _WIN32
+ const char* ld_libpath = ACE_OS::getenv("LD_LIBRARY_PATH");
+ LOGCONFIG("Current library path: %s",
+ ld_libpath == nullptr ? "nullptr" : ld_libpath);
+#endif
+ // Log the Geode system properties
+ m_sysProps->logSettings();
+}
void DistributedSystemImpl::disconnect() {
- LOGFINE("DistributedSystemImpl::disconnect done");
+ if (!m_connected) {
+ throw NotConnectedException(
+ "DistributedSystem::disconnect: connect "
+ "not called");
+ }
+
+ LOGCONFIG("Stopped the Geode Native Client");
+
+ // TODO global - log stays global so lets move this
+ Log::close();
+
+ m_connected = false;
+}
+
+SystemProperties& DistributedSystemImpl::getSystemProperties() const {
+ return *m_sysProps;
}
+const std::string& DistributedSystemImpl::getName() const { return m_name; }
+
void DistributedSystemImpl::CallCliCallBack(Cache& cache) {
ACE_Guard<ACE_Recursive_Thread_Mutex> disconnectGuard(m_cliCallbackLock);
if (m_isCliCallbackSet == true) {
- for (std::map<int, CliCallbackMethod>::iterator iter =
- m_cliCallbackMap.begin();
- iter != m_cliCallbackMap.end(); ++iter) {
- (*iter).second(cache);
+ for (const auto& iter : m_cliCallbackMap) {
+ iter.second(cache);
}
}
}
@@ -63,8 +156,7 @@ void DistributedSystemImpl::registerCliCallback(int appdomainId,
void DistributedSystemImpl::unregisterCliCallback(int appdomainId) {
ACE_Guard<ACE_Recursive_Thread_Mutex> disconnectGuard(m_cliCallbackLock);
- std::map<int, CliCallbackMethod>::iterator iter =
- m_cliCallbackMap.find(appdomainId);
+ auto iter = m_cliCallbackMap.find(appdomainId);
if (iter != m_cliCallbackMap.end()) {
m_cliCallbackMap.erase(iter);
LOGFINE("Removing cliCallback %d", appdomainId);
diff --git a/cppcache/src/DistributedSystemImpl.hpp b/cppcache/src/DistributedSystemImpl.hpp
index a78261a..75abfc6 100644
--- a/cppcache/src/DistributedSystemImpl.hpp
+++ b/cppcache/src/DistributedSystemImpl.hpp
@@ -31,6 +31,7 @@
#include "ace/OS.h"
#include <geode/DistributedSystem.hpp>
#include "DiffieHellman.hpp"
+#include "statistics/StatisticsManager.hpp"
#include <string>
#include <map>
@@ -84,16 +85,28 @@ class _GEODE_EXPORT DistributedSystemImpl {
/** Retrieve the MemberId used to create this Cache. */
virtual void disconnect();
- virtual void connect();
+
+ virtual void connect(Cache* cache);
+
+ void logSystemInformation() const;
+
+ virtual const std::string& getName() const;
+
+ statistics::StatisticsManager* getStatisticsManager() const {
+ return m_statisticsManager.get();
+ }
+
+ SystemProperties& getSystemProperties() const;
+
std::string m_name;
DistributedSystem* m_implementee;
-
DiffieHellman m_dh;
/**
* @brief constructors
*/
- DistributedSystemImpl(const char* name, DistributedSystem* implementee);
+ DistributedSystemImpl(std::string name, DistributedSystem* implementee,
+ std::unique_ptr<SystemProperties> sysProps);
// acquire/release locks
@@ -108,6 +121,9 @@ class _GEODE_EXPORT DistributedSystemImpl {
static ACE_Recursive_Thread_Mutex m_cliCallbackLock;
static volatile bool m_isCliCallbackSet;
static std::map<int, CliCallbackMethod> m_cliCallbackMap;
+ std::unique_ptr<statistics::StatisticsManager> m_statisticsManager;
+ std::unique_ptr<SystemProperties> m_sysProps;
+ bool m_connected;
};
} // namespace client
} // namespace geode
--
To stop receiving notification emails like this one, please contact
jbarrett@apache.org.