http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheImpl.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheImpl.cpp b/src/cppcache/src/CacheImpl.cpp index 22b9e24..abfab22 100644 --- a/src/cppcache/src/CacheImpl.cpp +++ b/src/cppcache/src/CacheImpl.cpp @@ -49,7 +49,7 @@ volatile bool CacheImpl::s_networkhop = false; volatile int CacheImpl::s_blacklistBucketTimeout = 0; ACE_Recursive_Thread_Mutex CacheImpl::s_nwHopLock; volatile int8_t CacheImpl::s_serverGroupFlag = 0; -MemberListForVersionStampPtr CacheImpl::s_versionStampMemIdList = NULLPTR; +MemberListForVersionStampPtr CacheImpl::s_versionStampMemIdList = nullptr; #define DEFAULT_LRU_MAXIMUM_ENTRIES 100000 @@ -59,7 +59,7 @@ ExpiryTaskManager* getCacheImplExpiryTaskManager() { CacheImpl::CacheImpl(Cache* c, const char* name, DistributedSystemPtr sys, const char* id_data, bool iPUF, bool readPdxSerialized) - : m_defaultPool(NULLPTR), + : m_defaultPool(nullptr), m_ignorePdxUnreadFields(iPUF), m_readPdxSerialized(readPdxSerialized), m_closed(false), @@ -67,13 +67,13 @@ CacheImpl::CacheImpl(Cache* c, const char* name, DistributedSystemPtr sys, m_distributedSystem(sys), m_implementee(c), m_cond(m_mutex), - m_attributes(NULLPTR), + m_attributes(nullptr), m_evictionControllerPtr(NULL), m_tcrConnectionManager(NULL), - m_remoteQueryServicePtr(NULLPTR), + m_remoteQueryServicePtr(nullptr), m_destroyPending(false), m_initDone(false), - m_adminRegion(NULLPTR) { + m_adminRegion(nullptr) { m_cacheTXManager = InternalCacheTransactionManager2PCPtr( new InternalCacheTransactionManager2PCImpl(c)); @@ -106,7 +106,7 @@ CacheImpl::CacheImpl(Cache* c, const char* name, DistributedSystemPtr sys, CacheImpl::CacheImpl(Cache* c, const char* name, DistributedSystemPtr sys, bool iPUF, bool readPdxSerialized) - : m_defaultPool(NULLPTR), + : m_defaultPool(nullptr), m_ignorePdxUnreadFields(iPUF), m_readPdxSerialized(readPdxSerialized), m_closed(false), @@ -114,13 +114,13 @@ CacheImpl::CacheImpl(Cache* c, const char* name, DistributedSystemPtr sys, m_distributedSystem(sys), m_implementee(c), m_cond(m_mutex), - m_attributes(NULLPTR), + m_attributes(nullptr), m_evictionControllerPtr(NULL), m_tcrConnectionManager(NULL), - m_remoteQueryServicePtr(NULLPTR), + m_remoteQueryServicePtr(nullptr), m_destroyPending(false), m_initDone(false), - m_adminRegion(NULLPTR) { + m_adminRegion(nullptr) { m_cacheTXManager = InternalCacheTransactionManager2PCPtr( new InternalCacheTransactionManager2PCImpl(c)); @@ -155,18 +155,18 @@ void CacheImpl::initServices() { PdxTypeRegistry::init(); CacheImpl::s_versionStampMemIdList = MemberListForVersionStampPtr(new MemberListForVersionStamp()); - if (!m_initDone && m_attributes != NULLPTR && m_attributes->getEndpoints()) { + if (!m_initDone && m_attributes != nullptr && m_attributes->getEndpoints()) { if (PoolManager::getAll().size() > 0 && getCacheMode()) { LOGWARN( "At least one pool has been created so ignoring cache level " "redundancy setting"); } m_tcrConnectionManager->init(); - m_remoteQueryServicePtr = new RemoteQueryService(this); + m_remoteQueryServicePtr = std::make_shared<RemoteQueryService>(this); // StartAdminRegion SystemProperties* prop = DistributedSystem::getSystemProperties(); if (prop && prop->statisticsEnabled()) { - m_adminRegion = new AdminRegion(this); + m_adminRegion = AdminRegion::create(this); } m_initDone = true; } @@ -195,12 +195,13 @@ void CacheImpl::netDown() { m_tcrConnectionManager->netDown(); const HashMapOfPools& pools = PoolManager::getAll(); - PoolPtr currPool = NULLPTR; + PoolPtr currPool = nullptr; for (HashMapOfPools::Iterator itr = pools.begin(); itr != pools.end(); itr++) { currPool = itr.second(); try { - ThinClientPoolHADMPtr poolHADM = dynCast<ThinClientPoolHADMPtr>(currPool); + ThinClientPoolHADMPtr poolHADM = + std::dynamic_pointer_cast<ThinClientPoolHADM>(currPool); poolHADM->netDown(); } catch (const ClassCastException&) { // Expect a ClassCastException for non-HA PoolDMs. @@ -216,7 +217,7 @@ CacheImpl::RegionKind CacheImpl::getRegionKind( RegionKind regionKind = CPP_REGION; const char* endpoints = NULL; - if (m_attributes != NULLPTR && + if (m_attributes != nullptr && (endpoints = m_attributes->getEndpoints()) != NULL && (m_attributes->getRedundancyLevel() > 0 || m_tcrConnectionManager->isDurable())) { @@ -233,7 +234,7 @@ CacheImpl::RegionKind CacheImpl::getRegionKind( } } else if (rattrs->getPoolName()) { PoolPtr pPtr = PoolManager::find(rattrs->getPoolName()); - if ((pPtr != NULLPTR && (pPtr->getSubscriptionRedundancy() > 0 || + if ((pPtr != nullptr && (pPtr->getSubscriptionRedundancy() > 0 || pPtr->getSubscriptionEnabled())) || m_tcrConnectionManager->isDurable()) { regionKind = THINCLIENT_HA_REGION; // As of now ThinClinetHARegion deals @@ -257,16 +258,16 @@ int CacheImpl::removeRegion(const char* name) { } QueryServicePtr CacheImpl::getQueryService(bool noInit) { - if (m_defaultPool != NULLPTR) { + if (m_defaultPool != nullptr) { if (m_defaultPool->isDestroyed()) { throw IllegalStateException("Pool has been destroyed."); } return m_defaultPool->getQueryService(); } - if (m_remoteQueryServicePtr == NULLPTR) { + if (m_remoteQueryServicePtr == nullptr) { m_tcrConnectionManager->init(); - m_remoteQueryServicePtr = new RemoteQueryService(this); + m_remoteQueryServicePtr = std::make_shared<RemoteQueryService>(this); } if (!noInit) { m_remoteQueryServicePtr->init(); @@ -280,7 +281,7 @@ QueryServicePtr CacheImpl::getQueryService(const char* poolName) { } PoolPtr pool = PoolManager::find(poolName); - if (pool != NULLPTR) { + if (pool != nullptr) { if (pool->isDestroyed()) { throw IllegalStateException("Pool has been destroyed."); } @@ -314,7 +315,7 @@ const char* CacheImpl::getName() const { bool CacheImpl::isClosed() const { return m_closed; } void CacheImpl::setAttributes(const CacheAttributesPtr& attrs) { - if (m_attributes == NULLPTR && attrs != NULLPTR) { + if (m_attributes == nullptr && attrs != nullptr) { m_attributes = attrs; } } @@ -331,7 +332,7 @@ void CacheImpl::sendNotificationCloseMsgs() { for (HashMapOfPools::Iterator iter = pools.begin(); iter != pools.end(); ++iter) { ThinClientPoolHADM* pool = - dynamic_cast<ThinClientPoolHADM*>(iter.second().ptr()); + dynamic_cast<ThinClientPoolHADM*>(iter.second().get()); if (pool != NULL) { pool->sendNotificationCloseMsgs(); } @@ -353,15 +354,15 @@ void CacheImpl::close(bool keepalive) { if (m_closed || (!m_initialized)) return; // Close the distribution manager used for queries. - if (m_remoteQueryServicePtr != NULLPTR) { + if (m_remoteQueryServicePtr != nullptr) { m_remoteQueryServicePtr->close(); - m_remoteQueryServicePtr = NULLPTR; + m_remoteQueryServicePtr = nullptr; } // Close AdminRegion - if (m_adminRegion != NULLPTR) { + if (m_adminRegion != nullptr) { m_adminRegion->close(); - m_adminRegion = NULLPTR; + m_adminRegion = nullptr; } // The TCCM gets destroyed when CacheImpl is destroyed, but after that there @@ -380,10 +381,11 @@ void CacheImpl::close(bool keepalive) { ++q) { // TODO: remove dynamic_cast here by having RegionInternal in the regions // map - RegionInternal* rImpl = dynamic_cast<RegionInternal*>((*q).int_id_.ptr()); + RegionInternalPtr rImpl = + std::dynamic_pointer_cast<RegionInternal>((*q).int_id_); if (rImpl != NULL) { rImpl->destroyRegionNoThrow( - NULLPTR, false, + nullptr, false, CacheEventFlags::LOCAL | CacheEventFlags::CACHE_CLOSE); } } @@ -413,7 +415,7 @@ void CacheImpl::close(bool keepalive) { LOGDEBUG("CacheImpl::close( ): destroyed regions."); GF_SAFE_DELETE(m_tcrConnectionManager); - m_cacheTXManager = NULLPTR; + m_cacheTXManager = nullptr; m_closed = true; LOGFINE("Cache closed."); @@ -450,10 +452,10 @@ void CacheImpl::createRegion(const char* name, if (!m_initDone) { if (!(aRegionAttributes->getPoolName())) { m_tcrConnectionManager->init(); - m_remoteQueryServicePtr = new RemoteQueryService(this); + m_remoteQueryServicePtr = std::make_shared<RemoteQueryService>(this); SystemProperties* prop = DistributedSystem::getSystemProperties(); if (prop && prop->statisticsEnabled()) { - m_adminRegion = new AdminRegion(this); + m_adminRegion = AdminRegion::create(this); } } m_initDone = true; @@ -463,7 +465,7 @@ void CacheImpl::createRegion(const char* name, if (m_closed || m_destroyPending) { throw CacheClosedException("Cache::createRegion: cache closed"); } - if (aRegionAttributes == NULLPTR) { + if (aRegionAttributes == nullptr) { throw IllegalArgumentException( "Cache::createRegion: RegionAttributes is null"); } @@ -475,7 +477,7 @@ void CacheImpl::createRegion(const char* name, } validateRegionAttributes(name, aRegionAttributes); - RegionInternal* rpImpl = NULL; + RegionInternalPtr rpImpl = nullptr; { // For multi threading and the operations between bind and find seems to be // hard to be atomic since a regionImpl needs to be valid before it can be @@ -491,7 +493,7 @@ void CacheImpl::createRegion(const char* name, throw RegionExistsException(buffer); } - CacheStatisticsPtr csptr(new CacheStatistics); + auto csptr = std::make_shared<CacheStatistics>(); try { rpImpl = createRegion_internal(namestr.c_str(), NULL, aRegionAttributes, csptr, false); @@ -519,7 +521,7 @@ void CacheImpl::createRegion(const char* name, namestr.c_str()); throw UnknownException(buffer); } - if (rpImpl == NULL) { + if (rpImpl == nullptr) { char buffer[256]; ACE_OS::snprintf(buffer, 256, "Cache::createRegion: Failed to create Region \"%s\"", @@ -531,7 +533,7 @@ void CacheImpl::createRegion(const char* name, // Instantiate a PersistenceManager object if DiskPolicy is overflow if (aRegionAttributes->getDiskPolicy() == DiskPolicyType::OVERFLOWS) { PersistenceManagerPtr pmPtr = aRegionAttributes->getPersistenceManager(); - if (pmPtr == NULLPTR) { + if (pmPtr == nullptr) { throw NullPointerException( "PersistenceManager could not be instantiated"); } @@ -551,10 +553,10 @@ void CacheImpl::createRegion(const char* name, const char* poolName = aRegionAttributes->getPoolName(); if (poolName != NULL) { PoolPtr pool = PoolManager::find(poolName); - if (pool != NULLPTR && !pool->isDestroyed() && + if (pool != nullptr && !pool->isDestroyed() && pool->getPRSingleHopEnabled()) { ThinClientPoolDM* poolDM = - dynamic_cast<ThinClientPoolDM*>(pool.ptr()); + dynamic_cast<ThinClientPoolDM*>(pool.get()); if ((poolDM != NULL) && (poolDM->getClientMetaDataService() != NULL)) { LOGFINE( @@ -591,7 +593,7 @@ void CacheImpl::createRegion(const char* name, void CacheImpl::getRegion(const char* path, RegionPtr& rptr) { TryReadGuard guardCacheDestroy(m_destroyCacheMutex, m_destroyPending); if (m_destroyPending) { - rptr = NULLPTR; + rptr = nullptr; return; } @@ -600,7 +602,7 @@ void CacheImpl::getRegion(const char* path, RegionPtr& rptr) { if (path != NULL) { pathstr = path; } - rptr = NULLPTR; + rptr = nullptr; std::string slash("/"); if ((path == (void*)NULL) || (pathstr == slash) || (pathstr.length() < 1)) { LOGERROR("Cache::getRegion: path [%s] is not valid.", pathstr.c_str()); @@ -621,40 +623,40 @@ void CacheImpl::getRegion(const char* path, RegionPtr& rptr) { return; } std::string remainder = fullname.substr(stepname.length() + 1); - if (region != NULLPTR) { + if (region != nullptr) { rptr = region->getSubregion(remainder.c_str()); } else { - rptr = NULLPTR; + rptr = nullptr; return; // Return null if the parent region was not found. } } } -RegionInternal* CacheImpl::createRegion_internal( - const std::string& name, RegionInternal* rootRegion, +std::shared_ptr<RegionInternal> CacheImpl::createRegion_internal( + const std::string& name, const std::shared_ptr<RegionInternal>& rootRegion, const RegionAttributesPtr& attrs, const CacheStatisticsPtr& csptr, bool shared) { - if (attrs == NULLPTR) { + if (attrs == nullptr) { throw IllegalArgumentException( "createRegion: " "RegionAttributes is null"); } - RegionInternal* rptr = NULL; + RegionInternalPtr rptr = nullptr; RegionKind regionKind = getRegionKind(attrs); const char* poolName = attrs->getPoolName(); const char* regionEndpoints = attrs->getEndpoints(); const char* cacheEndpoints = - m_attributes == NULLPTR ? NULL : m_attributes->getEndpoints(); + m_attributes == nullptr ? NULL : m_attributes->getEndpoints(); - /*if(m_defaultPool != NULLPTR && (poolName == NULL || strlen(poolName) == 0)) + /*if(m_defaultPool != nullptr && (poolName == NULL || strlen(poolName) == 0)) { attrs->setPoolName(m_defaultPool->getName()); }*/ if (poolName != NULL) { PoolPtr pool = PoolManager::find(poolName); - if (pool != NULLPTR && !pool->isDestroyed()) { + if (pool != nullptr && !pool->isDestroyed()) { bool isMultiUserSecureMode = pool->getMultiuserAuthentication(); if (isMultiUserSecureMode && (attrs->getCachingEnabled())) { LOGERROR( @@ -680,31 +682,30 @@ RegionInternal* CacheImpl::createRegion_internal( "specified"); } - DeleteObject<RegionInternal> delrptr(rptr); if (regionKind == THINCLIENT_REGION) { LOGINFO("Creating region %s with region endpoints %s", name.c_str(), attrs->getEndpoints()); - GF_NEW(rptr, - ThinClientRegion(name, this, rootRegion, attrs, csptr, shared)); - ((ThinClientRegion*)rptr)->initTCR(); - delrptr.noDelete(); + auto tmp = std::make_shared<ThinClientRegion>(name, this, rootRegion, attrs, + csptr, shared); + tmp->initTCR(); + rptr = tmp; } else if (regionKind == THINCLIENT_HA_REGION) { LOGINFO("Creating region %s with subscriptions enabled", name.c_str()); - GF_NEW(rptr, - ThinClientHARegion(name, this, rootRegion, attrs, csptr, shared)); - ((ThinClientHARegion*)rptr)->initTCR(); - delrptr.noDelete(); + auto tmp = std::make_shared<ThinClientHARegion>(name, this, rootRegion, + attrs, csptr, shared); + tmp->initTCR(); + rptr = tmp; } else if (regionKind == THINCLIENT_POOL_REGION) { LOGINFO("Creating region %s attached to pool %s", name.c_str(), attrs->getPoolName()); - GF_NEW(rptr, - ThinClientPoolRegion(name, this, rootRegion, attrs, csptr, shared)); - ((ThinClientPoolRegion*)rptr)->initTCR(); - delrptr.noDelete(); + auto tmp = std::make_shared<ThinClientPoolRegion>(name, this, rootRegion, + attrs, csptr, shared); + tmp->initTCR(); + rptr = tmp; } else { LOGINFO("Creating local region %s", name.c_str()); - GF_NEW(rptr, LocalRegion(name, this, rootRegion, attrs, csptr, shared)); - delrptr.noDelete(); + rptr = std::make_shared<LocalRegion>(name, this, rootRegion, attrs, csptr, + shared); } return rptr; } @@ -750,7 +751,7 @@ void CacheImpl::readyForEvents() { const HashMapOfPools& pools = PoolManager::getAll(); if (pools.empty()) throw IllegalStateException("No pools found."); - PoolPtr currPool = NULLPTR; + PoolPtr currPool = nullptr; for (HashMapOfPools::Iterator itr = pools.begin(); itr != pools.end(); itr++) { currPool = itr.second(); @@ -758,7 +759,7 @@ void CacheImpl::readyForEvents() { try { try { ThinClientPoolHADMPtr poolHADM = - dynCast<ThinClientPoolHADMPtr>(currPool); + std::dynamic_pointer_cast<ThinClientPoolHADM>(currPool); poolHADM->readyForEvents(); } catch (const ClassCastException&) { // Expect a ClassCastException for non-HA PoolDMs. @@ -788,7 +789,7 @@ bool CacheImpl::getEndpointStatus(const std::string& endpoint) { ? endpoint : Utils::convertHostToCanonicalForm(endpoint.c_str()); ThinClientPoolDMPtr currPool = - staticCast<ThinClientPoolDMPtr>(pools.begin().second()); + std::static_pointer_cast<GF_UNWRAP_SP(ThinClientPoolDMPtr)>(pools.begin().second()); ACE_Guard<ACE_Recursive_Thread_Mutex> guard(currPool->m_endpointsLock); for (ACE_Map_Manager<std::string, TcrEndpoint*, ACE_Recursive_Thread_Mutex>::iterator itr = @@ -814,7 +815,7 @@ void CacheImpl::processMarker() { q != m_regions->end(); ++q) { if (!(*q).int_id_->isDestroyed()) { ThinClientHARegion* tcrHARegion = - dynamic_cast<ThinClientHARegion*>((*q).int_id_.ptr()); + dynamic_cast<ThinClientHARegion*>((*q).int_id_.get()); if (tcrHARegion != NULL) { TcrMessage* regionMsg = new TcrMessageClientMarker(true); tcrHARegion->receiveNotification(regionMsg); @@ -824,7 +825,7 @@ void CacheImpl::processMarker() { iter != subregions.end(); ++iter) { if (!(*iter)->isDestroyed()) { ThinClientHARegion* subregion = - dynamic_cast<ThinClientHARegion*>((*iter).ptr()); + dynamic_cast<ThinClientHARegion*>((*iter).get()); if (subregion != NULL) { regionMsg = new TcrMessageClientMarker(true); subregion->receiveNotification(regionMsg); @@ -838,10 +839,10 @@ void CacheImpl::processMarker() { int CacheImpl::getPoolSize(const char* poolName) { PoolPtr pool = PoolManager::find(poolName); - if (pool == NULLPTR) { + if (pool == nullptr) { return -1; } else { - ThinClientPoolDM* dm = dynamic_cast<ThinClientPoolDM*>(pool.ptr()); + ThinClientPoolDM* dm = dynamic_cast<ThinClientPoolDM*>(pool.get()); if (dm) { return dm->m_poolSize; } else { @@ -852,8 +853,7 @@ int CacheImpl::getPoolSize(const char* poolName) { RegionFactoryPtr CacheImpl::createRegionFactory( RegionShortcut preDefinedRegion) { - RegionFactoryPtr rfPtr(new RegionFactory(preDefinedRegion)); - return rfPtr; + return std::make_shared<RegionFactory>(preDefinedRegion); } void CacheImpl::setRegionShortcut(AttributesFactoryPtr attrFact, @@ -882,21 +882,21 @@ std::map<std::string, RegionAttributesPtr> CacheImpl::getRegionShortcut() { { // PROXY - RegionAttributesPtr regAttr_PROXY(new RegionAttributes()); + auto regAttr_PROXY = std::make_shared<RegionAttributes>(); regAttr_PROXY->setCachingEnabled(false); preDefined["PROXY"] = regAttr_PROXY; } { // CACHING_PROXY - RegionAttributesPtr regAttr_CACHING_PROXY(new RegionAttributes()); + auto regAttr_CACHING_PROXY = std::make_shared<RegionAttributes>(); regAttr_CACHING_PROXY->setCachingEnabled(true); preDefined["CACHING_PROXY"] = regAttr_CACHING_PROXY; } { // CACHING_PROXY_ENTRY_LRU - RegionAttributesPtr regAttr_CACHING_PROXY_LRU(new RegionAttributes()); + auto regAttr_CACHING_PROXY_LRU = std::make_shared<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; @@ -904,13 +904,13 @@ std::map<std::string, RegionAttributesPtr> CacheImpl::getRegionShortcut() { { // LOCAL - RegionAttributesPtr regAttr_LOCAL(new RegionAttributes()); + auto regAttr_LOCAL = std::make_shared<RegionAttributes>(); preDefined["LOCAL"] = regAttr_LOCAL; } { // LOCAL_ENTRY_LRU - RegionAttributesPtr regAttr_LOCAL_LRU(new RegionAttributes()); + auto regAttr_LOCAL_LRU = std::make_shared<RegionAttributes>(); regAttr_LOCAL_LRU->setLruEntriesLimit(DEFAULT_LRU_MAXIMUM_ENTRIES); preDefined["LOCAL_ENTRY_LRU"] = regAttr_LOCAL_LRU; }
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheImpl.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheImpl.hpp b/src/cppcache/src/CacheImpl.hpp index 84dc954..7ce8550 100644 --- a/src/cppcache/src/CacheImpl.hpp +++ b/src/cppcache/src/CacheImpl.hpp @@ -235,11 +235,11 @@ class CPPCACHE_EXPORT CacheImpl : private NonCopyable, private NonAssignable { QueryServicePtr getQueryService(const char* poolName); - RegionInternal* createRegion_internal(const std::string& name, - RegionInternal* rootRegion, - const RegionAttributesPtr& attrs, - const CacheStatisticsPtr& csptr, - bool shared); + std::shared_ptr<RegionInternal> createRegion_internal( + const std::string& name, + const std::shared_ptr<RegionInternal>& rootRegion, + const RegionAttributesPtr& attrs, const CacheStatisticsPtr& csptr, + bool shared); /** * Send the "client ready" message to the server. @@ -260,7 +260,7 @@ class CPPCACHE_EXPORT CacheImpl : private NonCopyable, private NonAssignable { static inline CacheImpl* getInstance() { return s_instance; }; bool getCacheMode() { - return m_attributes == NULLPTR ? false : m_attributes->m_cacheMode; + return m_attributes == nullptr ? false : m_attributes->m_cacheMode; } bool getPdxIgnoreUnreadFields() { return m_ignorePdxUnreadFields; } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheRegionHelper.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheRegionHelper.hpp b/src/cppcache/src/CacheRegionHelper.hpp index 7d04d55..7e26e1a 100644 --- a/src/cppcache/src/CacheRegionHelper.hpp +++ b/src/cppcache/src/CacheRegionHelper.hpp @@ -40,7 +40,7 @@ class CacheRegionHelper { */ public: inline static CacheImpl* getCacheImpl(const Cache* cache) { - return cache->m_cacheImpl; + return cache->m_cacheImpl.get(); } inline static DistributedSystemImpl* getDistributedSystemImpl() { http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheTransactionManagerImpl.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheTransactionManagerImpl.cpp b/src/cppcache/src/CacheTransactionManagerImpl.cpp index 14d5ca4..bdea6db 100644 --- a/src/cppcache/src/CacheTransactionManagerImpl.cpp +++ b/src/cppcache/src/CacheTransactionManagerImpl.cpp @@ -81,7 +81,7 @@ void CacheTransactionManagerImpl::commit() { if (err != GF_NOERR) { // err = rollback(txState, false); - // noteCommitFailure(txState, NULLPTR); + // noteCommitFailure(txState, nullptr); GfErrTypeThrowException("Error while committing", err); } else { switch (reply.getMessageType()) { @@ -89,7 +89,7 @@ void CacheTransactionManagerImpl::commit() { break; } case TcrMessage::EXCEPTION: { - // noteCommitFailure(txState, NULLPTR); + // noteCommitFailure(txState, nullptr); const char* exceptionMsg = reply.getException(); err = ThinClientRegion::handleServerException( "CacheTransactionManager::commit", exceptionMsg); @@ -97,12 +97,12 @@ void CacheTransactionManagerImpl::commit() { break; } case TcrMessage::COMMIT_ERROR: { - // noteCommitFailure(txState, NULLPTR); + // noteCommitFailure(txState, nullptr); GfErrTypeThrowException("Commit Failed", GF_COMMIT_CONFLICT_EXCEPTION); break; } default: { - // noteCommitFailure(txState, NULLPTR); + // noteCommitFailure(txState, nullptr); LOGERROR("Unknown message type in commit reply %d", reply.getMessageType()); GfErrTypeThrowException("Commit Failed", GF_MSG); @@ -111,12 +111,12 @@ void CacheTransactionManagerImpl::commit() { } } - TXCommitMessagePtr commit = staticCast<TXCommitMessagePtr>(reply.getValue()); + TXCommitMessagePtr commit = std::static_pointer_cast<GF_UNWRAP_SP(TXCommitMessagePtr)>(reply.getValue()); txCleaner.clean(); commit->apply(m_cache); /* - if(m_writer != NULLPTR) + if(m_writer != nullptr) { try { @@ -305,8 +305,8 @@ GfErrType CacheTransactionManagerImpl::rollback(TXState* txState, /* if(err == GF_NOERR && callListener) { // TXCommitMessagePtr commit = - staticCast<TXCommitMessagePtr>(reply.getValue()); - noteRollbackSuccess(txState, NULLPTR); + std::static_pointer_cast<GF_UNWRAP_SP(TXCommitMessagePtr)>(reply.getValue()); + noteRollbackSuccess(txState, nullptr); } */ return err; @@ -330,14 +330,14 @@ TransactionIdPtr CacheTransactionManagerImpl::suspend() { TXState* txState = TSSTXStateWrapper::s_geodeTSSTXState->getTXState(); if (txState == NULL) { LOGFINE("Transaction not in progress. Returning NULL transaction Id."); - return NULLPTR; + return nullptr; } // get the current connection that this transaction is using TcrConnection* conn = TssConnectionWrapper::s_geodeTSSConn->getConnection(); if (conn == NULL) { LOGFINE("Thread local connection is null. Returning NULL transaction Id."); - return NULLPTR; + return nullptr; } // get the endpoint info from the connection @@ -380,8 +380,8 @@ void CacheTransactionManagerImpl::resume(TransactionIdPtr transactionId) { } // get the transaction state of the suspended transaction - TXState* txState = - removeSuspendedTx((static_cast<TXIdPtr>(transactionId))->getId()); + TXState* txState = removeSuspendedTx( + (std::static_pointer_cast<TXId>(transactionId))->getId()); if (txState == NULL) { GfErrTypeThrowException( "Could not get transaction state for the transaction id.", @@ -392,7 +392,8 @@ void CacheTransactionManagerImpl::resume(TransactionIdPtr transactionId) { } bool CacheTransactionManagerImpl::isSuspended(TransactionIdPtr transactionId) { - return isSuspendedTx((static_cast<TXIdPtr>(transactionId))->getId()); + return isSuspendedTx( + (std::static_pointer_cast<TXId>(transactionId))->getId()); } bool CacheTransactionManagerImpl::tryResume(TransactionIdPtr transactionId) { return tryResume(transactionId, true); @@ -406,8 +407,8 @@ bool CacheTransactionManagerImpl::tryResume(TransactionIdPtr transactionId, } // get the transaction state of the suspended transaction - TXState* txState = - removeSuspendedTx((static_cast<TXIdPtr>(transactionId))->getId()); + TXState* txState = removeSuspendedTx( + (std::static_pointer_cast<TXId>(transactionId))->getId()); if (txState == NULL) return false; resumeTxUsingTxState(txState, cancelExpiryTask); @@ -426,7 +427,8 @@ bool CacheTransactionManagerImpl::tryResume(TransactionIdPtr transactionId, // get the transaction state of the suspended transaction TXState* txState = removeSuspendedTxUntil( - (static_cast<TXIdPtr>(transactionId))->getId(), waitTimeInMillisec); + (std::static_pointer_cast<TXId>(transactionId))->getId(), + waitTimeInMillisec); if (txState == NULL) return false; resumeTxUsingTxState(txState); @@ -474,7 +476,7 @@ void CacheTransactionManagerImpl::resumeTxUsingTxState(TXState* txState, } bool CacheTransactionManagerImpl::exists(TransactionIdPtr transactionId) { - return findTx((static_cast<TXIdPtr>(transactionId))->getId()); + return findTx((std::static_pointer_cast<TXId>(transactionId))->getId()); } bool CacheTransactionManagerImpl::exists() { @@ -566,7 +568,7 @@ bool CacheTransactionManagerImpl::isSuspendedTx(int32_t txId) { TransactionIdPtr CacheTransactionManagerImpl::getTransactionId() { TXState* txState = TSSTXStateWrapper::s_geodeTSSTXState->getTXState(); if (txState == NULL) { - return NULLPTR; + return nullptr; } else { return txState->getTransactionId(); } @@ -585,7 +587,7 @@ TransactionWriterPtr CacheTransactionManagerImpl::getWriter() void CacheTransactionManagerImpl::addListener(TransactionListenerPtr aListener) { - if(aListener == NULLPTR) + if(aListener == nullptr) { GfErrTypeThrowException("Trying to add null listener.", GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION); @@ -599,7 +601,7 @@ GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION); void CacheTransactionManagerImpl::removeListener(TransactionListenerPtr aListener) { - if(aListener == NULLPTR) + if(aListener == nullptr) { GfErrTypeThrowException("Trying to remove null listener.", GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION); @@ -614,7 +616,7 @@ void CacheTransactionManagerImpl::noteCommitFailure(TXState* txState, const TXCommitMessagePtr& commitMessage) { VectorOfEntryEvent events; - if(commitMessage!= NULLPTR) + if(commitMessage!= nullptr) { events = commitMessage->getEvents(m_cache); } @@ -625,7 +627,7 @@ TransactionEvent(txState->getTransactionId(), CachePtr(m_cache), events)); m_listeners.end() != iter; iter++) { TransactionListenerPtr listener = -staticCast<TransactionListenerPtr>(*iter); +std::static_pointer_cast<GF_UNWRAP_SP(TransactionListenerPtr)>(*iter); listener->afterFailedCommit(event); } } @@ -634,7 +636,7 @@ void CacheTransactionManagerImpl::noteCommitSuccess(TXState* txState, const TXCommitMessagePtr& commitMessage) { VectorOfEntryEvent events; - if(commitMessage!= NULLPTR) + if(commitMessage!= nullptr) { events = commitMessage->getEvents(m_cache); } @@ -645,7 +647,7 @@ TransactionEvent(txState->getTransactionId(), CachePtr(m_cache), events)); m_listeners.end() != iter; iter++) { TransactionListenerPtr listener = -staticCast<TransactionListenerPtr>(*iter); +std::static_pointer_cast<GF_UNWRAP_SP(TransactionListenerPtr)>(*iter); listener->afterCommit(event); } } @@ -654,7 +656,7 @@ void CacheTransactionManagerImpl::noteRollbackSuccess(TXState* txState, const TXCommitMessagePtr& commitMessage) { VectorOfEntryEvent events; - if(commitMessage!= NULLPTR) + if(commitMessage!= nullptr) { events = commitMessage->getEvents(m_cache); } @@ -665,7 +667,7 @@ TransactionEvent(txState->getTransactionId(), CachePtr(m_cache), events)); m_listeners.end() != iter; iter++) { TransactionListenerPtr listener = -staticCast<TransactionListenerPtr>(*iter); +std::static_pointer_cast<GF_UNWRAP_SP(TransactionListenerPtr)>(*iter); listener->afterRollback(event); } } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheTransactionManagerImpl.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheTransactionManagerImpl.hpp b/src/cppcache/src/CacheTransactionManagerImpl.hpp index e728531..3be1bcb 100644 --- a/src/cppcache/src/CacheTransactionManagerImpl.hpp +++ b/src/cppcache/src/CacheTransactionManagerImpl.hpp @@ -67,11 +67,11 @@ class CacheTransactionManagerImpl // virtual void removeListener(TransactionListenerPtr aListener); inline static int32_t hasher(const SharedBasePtr& p) { - return static_cast<int32_t>(reinterpret_cast<intptr_t>(p.ptr())); + return static_cast<int32_t>(reinterpret_cast<intptr_t>(p.get())); } inline static bool equal_to(const SharedBasePtr& x, const SharedBasePtr& y) { - return x.ptr() == y.ptr(); + return x.get() == y.get(); } TXState* getSuspendedTx(int32_t txId); http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheXmlParser.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheXmlParser.cpp b/src/cppcache/src/CacheXmlParser.cpp index 836f9e9..05a9d9d 100644 --- a/src/cppcache/src/CacheXmlParser.cpp +++ b/src/cppcache/src/CacheXmlParser.cpp @@ -268,7 +268,7 @@ LibraryPersistenceManagerFn CacheXmlParser::managedPersistenceManagerFn = NULL; CacheXmlParser::CacheXmlParser() : m_cacheCreation(NULL), m_nestedRegions(0), - m_config(NULLPTR), + m_config(nullptr), m_parserMessage(""), m_flagCacheXmlException(false), m_flagIllegalStateException(false), @@ -610,7 +610,7 @@ void CacheXmlParser::startPool(const xmlChar** atts) { if (strcmp(name, NAME) == 0) { poolName = value; } else { - setPoolInfo(factory.ptr(), name, value); + setPoolInfo(factory.get(), name, value); } ++attrsCount; } @@ -625,7 +625,7 @@ void CacheXmlParser::startPool(const xmlChar** atts) { PoolXmlCreation* poolxml = new PoolXmlCreation(poolName, factory); _stack.push(poolxml); - _stack.push(factory.ptr()); + _stack.push(factory.get()); } void CacheXmlParser::endPool() { @@ -1215,7 +1215,7 @@ void CacheXmlParser::startPersistenceProperties(const xmlChar** atts) { "XML:Incorrect number of attributes provided for <property>"; throw CacheXmlException(s.c_str()); } else { - if (m_config == NULLPTR) { + if (m_config == nullptr) { m_config = Properties::create(); } } @@ -1672,10 +1672,10 @@ void CacheXmlParser::endPersistenceManager() { _stack.pop(); AttributesFactory* attrsFactory = reinterpret_cast<AttributesFactory*>(_stack.top()); - if (m_config != NULLPTR) { + if (m_config != nullptr) { attrsFactory->setPersistenceManager(libraryName, libraryFunctionName, m_config); - m_config = NULLPTR; + m_config = nullptr; } else { attrsFactory->setPersistenceManager(libraryName, libraryFunctionName); } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheableEnum.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheableEnum.cpp b/src/cppcache/src/CacheableEnum.cpp index 7db7f6c..b08c6ac 100644 --- a/src/cppcache/src/CacheableEnum.cpp +++ b/src/cppcache/src/CacheableEnum.cpp @@ -27,8 +27,8 @@ namespace client { CacheableEnum::~CacheableEnum() {} CacheableEnum::CacheableEnum() - : m_enumClassName(NULLPTR), - m_enumName(NULLPTR), + : m_enumClassName(nullptr), + m_enumName(nullptr), m_ordinal(-1), m_hashcode(0) {} @@ -58,7 +58,7 @@ Serializable* CacheableEnum::fromData(apache::geode::client::DataInput& input) { m_enumClassName = enumVal->getEnumClassName(); m_enumName = enumVal->getEnumName(); m_ordinal = enumVal->getEnumOrdinal(); - return enumVal.ptr(); + return enumVal.get(); } int32_t CacheableEnum::hashcode() const { @@ -67,9 +67,9 @@ int32_t CacheableEnum::hashcode() const { int prime = 31; localHash = prime * localHash + - ((m_enumClassName != NULLPTR ? m_enumClassName->hashcode() : 0)); + ((m_enumClassName != nullptr ? m_enumClassName->hashcode() : 0)); localHash = prime * localHash + - ((m_enumName != NULLPTR ? m_enumName->hashcode() : 0)); + ((m_enumName != nullptr ? m_enumName->hashcode() : 0)); m_hashcode = localHash; } return m_hashcode; @@ -87,11 +87,11 @@ bool CacheableEnum::operator==(const CacheableKey& other) const { if (m_ordinal != otherEnum->m_ordinal) { return false; } - if (m_enumClassName == NULLPTR) { - return (otherEnum->m_enumClassName == NULLPTR); + if (m_enumClassName == nullptr) { + return (otherEnum->m_enumClassName == nullptr); } - if (m_enumName == NULLPTR) { - return (otherEnum->m_enumName == NULLPTR); + if (m_enumName == nullptr) { + return (otherEnum->m_enumName == nullptr); } if (strcmp(m_enumClassName->asChar(), otherEnum->m_enumClassName->asChar()) != 0) { http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheableObjectPartList.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheableObjectPartList.cpp b/src/cppcache/src/CacheableObjectPartList.cpp index 7bec1b2..0ca8deb 100644 --- a/src/cppcache/src/CacheableObjectPartList.cpp +++ b/src/cppcache/src/CacheableObjectPartList.cpp @@ -53,7 +53,7 @@ Serializable* CacheableObjectPartList::fromData(DataInput& input) { "CacheableObjectPartList: " "hasKeys is false and m_keys is also NULL"); } - if (m_resultKeys != NULLPTR) { + if (m_resultKeys != nullptr) { m_resultKeys->push_back(key); } // input.readBoolean(&isException); @@ -66,15 +66,16 @@ Serializable* CacheableObjectPartList::fromData(DataInput& input) { input.advanceCursor(skipLen); // input.readObject(exMsgPtr, true);// Changed input.readNativeString(exMsgPtr); - if (m_exceptions != NULLPTR) { + if (m_exceptions != nullptr) { const char* exMsg = exMsgPtr->asChar(); if (strstr(exMsg, "org.apache.geode.security." "NotAuthorizedException") != NULL) { - ex = new NotAuthorizedException( + ex = std::make_shared<NotAuthorizedException>( "Authorization exception at server:", exMsg); } else { - ex = new CacheServerException("Exception at remote server:", exMsg); + ex = std::make_shared<CacheServerException>( + "Exception at remote server:", exMsg); } m_exceptions->insert(key, ex); } @@ -108,10 +109,10 @@ Serializable* CacheableObjectPartList::fromData(DataInput& input) { } // if value has already been received via notification or put by // another thread, then return that - if (oldValue != NULLPTR && !CacheableToken::isInvalid(oldValue)) { + if (oldValue != nullptr && !CacheableToken::isInvalid(oldValue)) { value = oldValue; } - if (m_values != NULLPTR) { + if (m_values != nullptr) { m_values->insert(key, value); } } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheableObjectPartList.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheableObjectPartList.hpp b/src/cppcache/src/CacheableObjectPartList.hpp index f124b39..fbff1bb 100644 --- a/src/cppcache/src/CacheableObjectPartList.hpp +++ b/src/cppcache/src/CacheableObjectPartList.hpp @@ -64,9 +64,9 @@ class CacheableObjectPartList : public Cacheable { inline CacheableObjectPartList() : m_keys(NULL), m_keysOffset(NULL), - m_values(NULLPTR), - m_exceptions(NULLPTR), - m_resultKeys(NULLPTR), + m_values(nullptr), + m_exceptions(nullptr), + m_resultKeys(nullptr), m_region(NULL), m_updateCountMap(NULL), m_destroyTracker(0), http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheableToken.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheableToken.cpp b/src/cppcache/src/CacheableToken.cpp index 131d405..50de562 100644 --- a/src/cppcache/src/CacheableToken.cpp +++ b/src/cppcache/src/CacheableToken.cpp @@ -27,26 +27,14 @@ using namespace apache::geode::client; //---- statics -CacheableTokenPtr* CacheableToken::invalidToken = 0; -CacheableTokenPtr* CacheableToken::destroyedToken = 0; -CacheableTokenPtr* CacheableToken::overflowedToken = 0; -CacheableTokenPtr* CacheableToken::tombstoneToken = 0; - -void CacheableToken::init() { - if (CacheableToken::invalidToken == 0) { - CacheableToken::invalidToken = new CacheableTokenPtr(); - *CacheableToken::invalidToken = new CacheableToken(CacheableToken::INVALID); - CacheableToken::destroyedToken = new CacheableTokenPtr(); - *CacheableToken::destroyedToken = - new CacheableToken(CacheableToken::DESTROYED); - CacheableToken::overflowedToken = new CacheableTokenPtr(); - *CacheableToken::overflowedToken = - new CacheableToken(CacheableToken::OVERFLOWED); - CacheableToken::tombstoneToken = new CacheableTokenPtr(); - *CacheableToken::tombstoneToken = - new CacheableToken(CacheableToken::TOMBSTONE); - } -} +CacheableTokenPtr CacheableToken::invalidToken = + std::make_shared<CacheableToken>(CacheableToken::INVALID); +CacheableTokenPtr CacheableToken::destroyedToken = + std::make_shared<CacheableToken>(CacheableToken::DESTROYED); +CacheableTokenPtr CacheableToken::overflowedToken = + std::make_shared<CacheableToken>(CacheableToken::OVERFLOWED); +CacheableTokenPtr CacheableToken::tombstoneToken = + std::make_shared<CacheableToken>(CacheableToken::TOMBSTONE); //----- serialization @@ -60,22 +48,7 @@ void CacheableToken::toData(DataOutput& output) const { Serializable* CacheableToken::fromData(DataInput& input) { input.readInt(reinterpret_cast<int32_t*>(&m_value)); - switch (m_value) { - case INVALID: - return invalidToken->ptr(); - case DESTROYED: - return destroyedToken->ptr(); - case OVERFLOWED: - return overflowedToken->ptr(); - case TOMBSTONE: - return tombstoneToken->ptr(); - - default: - GF_D_ASSERT(false); - // we really can't be returning new instances all the time.. - // because we wish to test tokens with pointer identity. - return this; - } + return this; } int32_t CacheableToken::classId() const { return 0; } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CacheableToken.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CacheableToken.hpp b/src/cppcache/src/CacheableToken.hpp index afa1091..b071a80 100644 --- a/src/cppcache/src/CacheableToken.hpp +++ b/src/cppcache/src/CacheableToken.hpp @@ -38,18 +38,16 @@ class CPPCACHE_EXPORT CacheableToken : public Cacheable { TokenType m_value; - static CacheableTokenPtr* invalidToken; - static CacheableTokenPtr* destroyedToken; - static CacheableTokenPtr* overflowedToken; - static CacheableTokenPtr* tombstoneToken; + static CacheableTokenPtr invalidToken; + static CacheableTokenPtr destroyedToken; + static CacheableTokenPtr overflowedToken; + static CacheableTokenPtr tombstoneToken; public: - inline static CacheableTokenPtr& invalid() { return *invalidToken; } - - inline static CacheableTokenPtr& destroyed() { return *destroyedToken; } - - inline static CacheableTokenPtr& overflowed() { return *overflowedToken; } - inline static CacheableTokenPtr& tombstone() { return *tombstoneToken; } + inline static CacheableTokenPtr& invalid() { return invalidToken; } + inline static CacheableTokenPtr& destroyed() { return destroyedToken; } + inline static CacheableTokenPtr& overflowed() { return overflowedToken; } + inline static CacheableTokenPtr& tombstone() { return tombstoneToken; } /** *@brief serialize this object **/ @@ -81,6 +79,8 @@ class CPPCACHE_EXPORT CacheableToken : public Cacheable { virtual ~CacheableToken(); + FRIEND_STD_SHARED_PTR(CacheableToken) + inline bool isInvalid() { return m_value == INVALID; } inline bool isDestroyed() { return m_value == DESTROYED; } @@ -90,26 +90,23 @@ class CPPCACHE_EXPORT CacheableToken : public Cacheable { inline bool isTombstone() { return m_value == TOMBSTONE; } static bool isToken(const CacheablePtr& ptr) { - return (*invalidToken == ptr) || (*destroyedToken == ptr) || - (*overflowedToken == ptr) || (*tombstoneToken == ptr); + return (invalidToken == ptr) || (destroyedToken == ptr) || + (overflowedToken == ptr) || (tombstoneToken == ptr); } - static bool isInvalid(const CacheablePtr& ptr) { - return *invalidToken == ptr; - } + static bool isInvalid(const CacheablePtr& ptr) { return invalidToken == ptr; } static bool isDestroyed(const CacheablePtr& ptr) { - return *destroyedToken == ptr; + return destroyedToken == ptr; } static bool isOverflowed(const CacheablePtr& ptr) { - return *overflowedToken == ptr; + return overflowedToken == ptr; } static bool isTombstone(const CacheablePtr& ptr) { - return *tombstoneToken == ptr; + return tombstoneToken == ptr; } - static void init(); /** * Display this object as 'string', which depend on the implementation in http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CachedDeserializableHelper.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CachedDeserializableHelper.hpp b/src/cppcache/src/CachedDeserializableHelper.hpp index d15ff27..799fcca 100644 --- a/src/cppcache/src/CachedDeserializableHelper.hpp +++ b/src/cppcache/src/CachedDeserializableHelper.hpp @@ -62,7 +62,7 @@ class CachedDeserializableHelper : public Cacheable, int32_t arrayLen; input.readArrayLen(&arrayLen); input.readObject(m_intermediate); - return m_intermediate.ptr(); + return m_intermediate.get(); } /** http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ClientMetadata.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ClientMetadata.cpp b/src/cppcache/src/ClientMetadata.cpp index 89a4242..7bdba2b 100644 --- a/src/cppcache/src/ClientMetadata.cpp +++ b/src/cppcache/src/ClientMetadata.cpp @@ -29,8 +29,8 @@ ClientMetadata::ClientMetadata( int totalNumBuckets, CacheableStringPtr colocatedWith, ThinClientPoolDM* tcrdm, std::vector<FixedPartitionAttributesImplPtr>* fpaSet) - : m_partitionNames(NULLPTR), - m_previousOne(NULLPTR), + : m_partitionNames(nullptr), + m_previousOne(nullptr), m_totalNumBuckets(totalNumBuckets), m_colocatedWith(colocatedWith), m_tcrdm(tcrdm) { @@ -62,8 +62,8 @@ ClientMetadata::ClientMetadata( } ClientMetadata::ClientMetadata(ClientMetadata& other) { - m_partitionNames = NULLPTR; - m_previousOne = NULLPTR; + m_partitionNames = nullptr; + m_previousOne = nullptr; m_totalNumBuckets = other.m_totalNumBuckets; for (int item = 0; item < m_totalNumBuckets; item++) { BucketServerLocationsType empty; @@ -79,10 +79,10 @@ ClientMetadata::ClientMetadata(ClientMetadata& other) { } ClientMetadata::ClientMetadata() - : m_partitionNames(NULLPTR), - m_previousOne(NULLPTR), + : m_partitionNames(nullptr), + m_previousOne(nullptr), m_totalNumBuckets(0), - m_colocatedWith(NULLPTR), + m_colocatedWith(nullptr), m_tcrdm(NULL) {} ClientMetadata::~ClientMetadata() {} @@ -182,10 +182,10 @@ void ClientMetadata::updateBucketServerLocations( bucketServerLocations.begin(); iter != bucketServerLocations.end(); ++iter) { CacheableStringArrayPtr groups = (*iter)->getServerGroups(); - if ((groups != NULLPTR) && (groups->length() > 0)) { + if ((groups != nullptr) && (groups->length() > 0)) { bool added = false; for (int i = 0; i < groups->length(); i++) { - CacheableStringPtr cs = groups[i]; + CacheableStringPtr cs = (*groups)[i]; if (cs->length() > 0) { std::string str = cs->toString(); if ((ACE_OS::strcmp(str.c_str(), serverGroup.c_str()) == 0)) { @@ -208,7 +208,7 @@ void ClientMetadata::updateBucketServerLocations( } } if (!added) { - (*iter)->setServername(NULLPTR); + (*iter)->setServername(nullptr); if ((*iter)->isPrimary()) { primaries.push_back(*iter); } else { @@ -370,7 +370,7 @@ BucketServerLocationPtr ClientMetadata::advisePrimaryServerLocation( return location; } } - return NULLPTR; + return nullptr; } BucketServerLocationPtr ClientMetadata::adviseRandomServerLocation() { @@ -380,10 +380,10 @@ BucketServerLocationPtr ClientMetadata::adviseRandomServerLocation() { checkBucketId(random); std::vector<BucketServerLocationPtr> locations = m_bucketServerLocationsList[random]; - if (locations.size() == 0) return NULLPTR; + if (locations.size() == 0) return nullptr; return locations.at(0); } - return NULLPTR; + return nullptr; } } // namespace client } // namespace geode http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ClientMetadataService.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ClientMetadataService.cpp b/src/cppcache/src/ClientMetadataService.cpp index 310dcc0..eaf93f4 100644 --- a/src/cppcache/src/ClientMetadataService.cpp +++ b/src/cppcache/src/ClientMetadataService.cpp @@ -41,7 +41,7 @@ ClientMetadataService::~ClientMetadataService() { } } -ClientMetadataService::ClientMetadataService(PoolPtr pool) +ClientMetadataService::ClientMetadataService(Pool* pool) /* adongre * CID 28928: Uninitialized scalar field (UNINIT_CTOR) */ @@ -59,7 +59,7 @@ int ClientMetadataService::svc() { LOGINFO("ClientMetadataService started for pool %s", m_pool->getName()); while (m_run) { m_regionQueueSema.acquire(); - ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.ptr()); + ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool); CacheImpl* cache = tcrdm->getConnectionManager().getCacheImpl(); while (true) { std::string* regionFullPath = m_regionQueue->get(); @@ -102,7 +102,7 @@ int ClientMetadataService::svc() { void ClientMetadataService::getClientPRMetadata(const char* regionFullPath) { if (regionFullPath == NULL) return; - ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.ptr()); + ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool); if (tcrdm == NULL) { throw IllegalArgumentException( "ClientMetaData: pool cast to ThinClientPoolDM failed"); @@ -113,7 +113,7 @@ void ClientMetadataService::getClientPRMetadata(const char* regionFullPath) { // this message to server and get metadata from server. TcrMessageReply reply(true, NULL); std::string path(regionFullPath); - ClientMetadataPtr cptr = NULLPTR; + ClientMetadataPtr cptr = nullptr; { ReadGuard guard(m_regionMetadataLock); RegionMetadataMapType::iterator itr = m_regionMetaDataMap.find(path); @@ -122,43 +122,43 @@ void ClientMetadataService::getClientPRMetadata(const char* regionFullPath) { } // cptr = m_regionMetaDataMap[path]; } - ClientMetadataPtr newCptr = NULLPTR; + ClientMetadataPtr newCptr = nullptr; { // ACE_Guard< ACE_Recursive_Thread_Mutex > guard( m_regionMetadataLock ); - if (cptr == NULLPTR) { + if (cptr == nullptr) { TcrMessageGetClientPartitionAttributes request(regionFullPath); GfErrType err = tcrdm->sendSyncRequest(request, reply); if (err == GF_NOERR && reply.getMessageType() == TcrMessage::RESPONSE_CLIENT_PARTITION_ATTRIBUTES) { - cptr = - new ClientMetadata(reply.getNumBuckets(), reply.getColocatedWith(), - tcrdm, reply.getFpaSet()); + cptr = std::make_shared<ClientMetadata>(reply.getNumBuckets(), + reply.getColocatedWith(), tcrdm, + reply.getFpaSet()); if (m_bucketWaitTimeout > 0 && reply.getNumBuckets() > 0) { WriteGuard guard(m_PRbucketStatusLock); m_bucketStatus[regionFullPath] = new PRbuckets(reply.getNumBuckets()); } LOGDEBUG("ClientMetadata buckets %d ", reply.getNumBuckets()); - if (cptr != NULLPTR) { + if (cptr != nullptr) { // m_regionMetaDataMap[regionFullPath] = cptr; } } } } - if (cptr == NULLPTR) { + if (cptr == nullptr) { return; } CacheableStringPtr colocatedWith; - if (cptr != NULLPTR) { + if (cptr != nullptr) { colocatedWith = cptr->getColocatedWith(); } - if (colocatedWith == NULLPTR) { + if (colocatedWith == nullptr) { newCptr = SendClientPRMetadata(regionFullPath, cptr); // now we will get new instance so assign it again - if (newCptr != NULLPTR) { - cptr->setPreviousone(NULLPTR); + if (newCptr != nullptr) { + cptr->setPreviousone(nullptr); newCptr->setPreviousone(cptr); WriteGuard guard(m_regionMetadataLock); m_regionMetaDataMap[path] = newCptr; @@ -171,8 +171,8 @@ void ClientMetadataService::getClientPRMetadata(const char* regionFullPath) { } newCptr = SendClientPRMetadata(colocatedWith->asChar(), cptr); - if (newCptr != NULLPTR) { - cptr->setPreviousone(NULLPTR); + if (newCptr != nullptr) { + cptr->setPreviousone(nullptr); newCptr->setPreviousone(cptr); // now we will get new instance so assign it again WriteGuard guard(m_regionMetadataLock); @@ -185,7 +185,7 @@ void ClientMetadataService::getClientPRMetadata(const char* regionFullPath) { ClientMetadataPtr ClientMetadataService::SendClientPRMetadata( const char* regionPath, ClientMetadataPtr cptr) { - ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.ptr()); + ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool); if (tcrdm == NULL) { throw IllegalArgumentException( "ClientMetaData: pool cast to ThinClientPoolDM failed"); @@ -195,22 +195,22 @@ ClientMetadataPtr ClientMetadataService::SendClientPRMetadata( // send this message to server and get metadata from server. LOGFINE("Now sending GET_CLIENT_PR_METADATA for getting from server: %s", regionPath); - RegionPtr region = NULLPTR; + RegionPtr region = nullptr; GfErrType err = tcrdm->sendSyncRequest(request, reply); if (err == GF_NOERR && reply.getMessageType() == TcrMessage::RESPONSE_CLIENT_PR_METADATA) { tcrdm->getConnectionManager().getCacheImpl()->getRegion(regionPath, region); - if (region != NULLPTR) { - LocalRegion* lregion = dynamic_cast<LocalRegion*>(region.ptr()); + if (region != nullptr) { + LocalRegion* lregion = dynamic_cast<LocalRegion*>(region.get()); lregion->getRegionStats()->incMetaDataRefreshCount(); } std::vector<BucketServerLocationsType>* metadata = reply.getMetadata(); - if (metadata == NULL) return NULLPTR; + if (metadata == NULL) return nullptr; if (metadata->empty()) { delete metadata; - return NULLPTR; + return nullptr; } - ClientMetadata* newCptr = new ClientMetadata(*(cptr.ptr())); + auto newCptr = std::make_shared<ClientMetadata>(*cptr); for (std::vector<BucketServerLocationsType>::iterator iter = metadata->begin(); iter != metadata->end(); ++iter) { @@ -220,10 +220,9 @@ ClientMetadataPtr ClientMetadataService::SendClientPRMetadata( } } delete metadata; - ClientMetadataPtr newCMDPtr(newCptr); - return newCMDPtr; + return newCptr; } - return NULLPTR; + return nullptr; } void ClientMetadataService::getBucketServerLocation( @@ -231,20 +230,20 @@ void ClientMetadataService::getBucketServerLocation( const CacheablePtr& value, const UserDataPtr& aCallbackArgument, bool isPrimary, BucketServerLocationPtr& serverLocation, int8_t& version) { // ACE_Guard< ACE_Recursive_Thread_Mutex > guard( m_regionMetadataLock ); - if (region != NULLPTR) { + if (region != nullptr) { ReadGuard guard(m_regionMetadataLock); LOGDEBUG( "ClientMetadataService::getBucketServerLocation m_regionMetaDataMap " "size is %d", m_regionMetaDataMap.size()); std::string path(region->getFullPath()); - ClientMetadataPtr cptr = NULLPTR; + ClientMetadataPtr cptr = nullptr; RegionMetadataMapType::iterator itr = m_regionMetaDataMap.find(path); if (itr != m_regionMetaDataMap.end()) { cptr = itr->second; } // ClientMetadataPtr cptr = m_regionMetaDataMap[path]; - if (cptr == NULLPTR) { + if (cptr == nullptr) { // serverLocation = BucketServerLocation(); return; } @@ -252,20 +251,20 @@ void ClientMetadataService::getBucketServerLocation( const PartitionResolverPtr& resolver = region->getAttributes()->getPartitionResolver(); - EntryEvent event(region, key, value, NULLPTR, aCallbackArgument, false); + EntryEvent event(region, key, value, nullptr, aCallbackArgument, false); int bucketId = 0; - if (resolver == NULLPTR) { + if (resolver == nullptr) { resolvekey = key; } else { resolvekey = resolver->getRoutingObject(event); - if (resolvekey == NULLPTR) { + if (resolvekey == nullptr) { throw IllegalStateException( "The RoutingObject returned by PartitionResolver is null."); } } FixedPartitionResolverPtr fpResolver( - dynamic_cast<FixedPartitionResolver*>(resolver.ptr())); - if (fpResolver != NULLPTR) { + dynamic_cast<FixedPartitionResolver*>(resolver.get())); + if (fpResolver != nullptr) { const char* partition = fpResolver->getPartitionName(event); if (partition == NULL) { throw IllegalStateException( @@ -293,7 +292,7 @@ void ClientMetadataService::removeBucketServerLocation( m_regionMetaDataMap.begin(); regionMetadataIter != m_regionMetaDataMap.end(); regionMetadataIter++) { ClientMetadataPtr cptr = (*regionMetadataIter).second; - if (cptr != NULLPTR) { + if (cptr != nullptr) { // Yogesh has commented out this as it was causing a SIGV // cptr->removeBucketServerLocation(serverLocation); } @@ -308,7 +307,7 @@ ClientMetadataPtr ClientMetadataService::getClientMetadata( if (regionMetadataIter != m_regionMetaDataMap.end()) { return (*regionMetadataIter).second; } - return NULLPTR; + return nullptr; } /*const PartitionResolverPtr& ClientMetadataService::getResolver(const @@ -326,7 +325,7 @@ ClientMetadataService::getServerLocation(ClientMetadataPtr cptr, int bucketId, bool tryPrimary) { LOGFINE("Inside getServerLocation"); -if (cptr == NULLPTR) { +if (cptr == nullptr) { LOGDEBUG("MetaData does not exist"); return BucketServerLocation(); } @@ -342,7 +341,7 @@ void ClientMetadataService::populateDummyServers(const char* regionName, void ClientMetadataService::enqueueForMetadataRefresh( const char* regionFullPath, int8_t serverGroupFlag) { - ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.ptr()); + ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool); if (tcrdm == NULL) { throw IllegalArgumentException( "ClientMetaData: pool cast to ThinClientPoolDM failed"); @@ -350,7 +349,7 @@ void ClientMetadataService::enqueueForMetadataRefresh( RegionPtr region; tcrdm->getConnectionManager().getCacheImpl()->getRegion(regionFullPath, region); - LocalRegion* lregion = dynamic_cast<LocalRegion*>(region.ptr()); + LocalRegion* lregion = dynamic_cast<LocalRegion*>(region.get()); std::string serverGroup = tcrdm->getServerGroup(); if (serverGroup.length() != 0) { @@ -363,8 +362,8 @@ void ClientMetadataService::enqueueForMetadataRefresh( } } - if (region != NULLPTR) { - ThinClientRegion* tcrRegion = dynamic_cast<ThinClientRegion*>(region.ptr()); + if (region != nullptr) { + ThinClientRegion* tcrRegion = dynamic_cast<ThinClientRegion*>(region.get()); { TryWriteGuard guardRegionMetaDataRefresh( tcrRegion->getMataDataMutex(), tcrRegion->getMetaDataRefreshed()); @@ -386,7 +385,7 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, const RegionPtr& region, bool isPrimary) { // const char* regionFullPath = region->getFullPath(); - ClientMetadataPtr cptr = NULLPTR; + ClientMetadataPtr cptr = nullptr; { ReadGuard guard(m_regionMetadataLock); RegionMetadataMapType::iterator cptrIter = @@ -396,7 +395,7 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, cptr = cptrIter->second; } - if (cptr == NULLPTR || keys == NULL) { + if (cptr == nullptr || keys == NULL) { // enqueueForMetadataRefresh(region->getFullPath()); return NULL; // //serverLocation = BucketServerLocation(); @@ -404,9 +403,9 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, } } // int totalNumberOfBuckets = cptr->getTotalNumBuckets(); - HashMapT<BucketServerLocationPtr, VectorOfCacheableKeyPtr>* result = + auto* result = new HashMapT<BucketServerLocationPtr, VectorOfCacheableKeyPtr>(); - VectorOfCacheableKeyPtr keysWhichLeft(new VectorOfCacheableKey()); + auto keysWhichLeft = std::make_shared<VectorOfCacheableKey>(); std::map<int, BucketServerLocationPtr> buckets; @@ -418,27 +417,27 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, region->getAttributes()->getPartitionResolver(); CacheableKeyPtr resolveKey; - if (resolver == NULLPTR) { + if (resolver == nullptr) { // client has not registered PartitionResolver // Assuming even PR at server side is not using PartitionResolver resolveKey = key; } else { - EntryEvent event(region, key, NULLPTR, NULLPTR, NULLPTR, false); + EntryEvent event(region, key, nullptr, nullptr, nullptr, false); resolveKey = resolver->getRoutingObject(event); } int bucketId = std::abs(resolveKey->hashcode() % cptr->getTotalNumBuckets()); - VectorOfCacheableKeyPtr keyList = NULLPTR; + VectorOfCacheableKeyPtr keyList = nullptr; std::map<int, BucketServerLocationPtr>::iterator bucketsIter = buckets.find(bucketId); if (bucketsIter == buckets.end()) { int8_t version = -1; - // BucketServerLocationPtr serverLocation(new BucketServerLocation()); - BucketServerLocationPtr serverLocation = NULLPTR; + // auto serverLocation = std::make_shared<BucketServerLocation>(); + BucketServerLocationPtr serverLocation = nullptr; cptr->getServerLocation(bucketId, isPrimary, serverLocation, version); - if (serverLocation == NULLPTR) { //:if server not returns all buckets, + if (serverLocation == nullptr) { //:if server not returns all buckets, // need to confiem with PR team about // this why?? keysWhichLeft->push_back(key); @@ -447,7 +446,7 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, keysWhichLeft->push_back(key); continue; } - // if(serverLocation == NULLPTR) + // if(serverLocation == nullptr) // continue;// need to fix buckets[bucketId] = serverLocation; HashMapT<BucketServerLocationPtr, VectorOfCacheableKeyPtr>::Iterator @@ -455,7 +454,7 @@ ClientMetadataService::getServerToFilterMap(const VectorOfCacheableKey* keys, // keyList = (*result)[serverLocation]; if (itrRes == result->end()) { - keyList = new VectorOfCacheableKey(); + keyList = std::make_shared<VectorOfCacheableKey>(); result->insert(serverLocation, keyList); } else { keyList = itrRes.second(); @@ -508,7 +507,7 @@ void ClientMetadataService::markPrimaryBucketForTimeout( false /*look for secondary host*/, serverLocation, version); - if (serverLocation != NULLPTR && serverLocation->isValid()) { + if (serverLocation != nullptr && serverLocation->isValid()) { LOGDEBUG("Server host and port are %s:%d", serverLocation->getServerName().c_str(), serverLocation->getPort()); @@ -532,24 +531,24 @@ ClientMetadataService::groupByBucketOnClientSide(const RegionPtr& region, new HashMapT<CacheableInt32Ptr, CacheableHashSetPtr>(); for (CacheableVector::Iterator itr = (*keySet)->begin(); itr != (*keySet)->end(); ++itr) { - CacheableKeyPtr key = dynCast<CacheableKeyPtr>(*itr); + CacheableKeyPtr key = std::dynamic_pointer_cast<CacheableKey>(*itr); PartitionResolverPtr resolver = region->getAttributes()->getPartitionResolver(); CacheableKeyPtr resolvekey; - EntryEvent event(region, key, NULLPTR, NULLPTR, NULLPTR, false); + EntryEvent event(region, key, nullptr, nullptr, nullptr, false); int bucketId = -1; - if (resolver == NULLPTR) { + if (resolver == nullptr) { resolvekey = key; } else { resolvekey = resolver->getRoutingObject(event); - if (resolvekey == NULLPTR) { + if (resolvekey == nullptr) { throw IllegalStateException( "The RoutingObject returned by PartitionResolver is null."); } } FixedPartitionResolverPtr fpResolver( - dynamic_cast<FixedPartitionResolver*>(resolver.ptr())); - if (fpResolver != NULLPTR) { + dynamic_cast<FixedPartitionResolver*>(resolver.get())); + if (fpResolver != nullptr) { const char* partition = fpResolver->getPartitionName(event); if (partition == NULL) { throw IllegalStateException( @@ -585,7 +584,7 @@ ClientMetadataService::getServerToFilterMapFESHOP( CacheableVectorPtr* routingKeys, const RegionPtr& region, bool isPrimary) { ClientMetadataPtr cptr = getClientMetadata(region->getFullPath()); - if (cptr == NULLPTR /*|| cptr->adviseRandomServerLocation() == NULLPTR*/) { + if (cptr == nullptr /*|| cptr->adviseRandomServerLocation() == nullptr*/) { enqueueForMetadataRefresh(region->getFullPath(), 0); return NULL; } @@ -633,7 +632,8 @@ ClientMetadataService::getServerToFilterMapFESHOP( keys = iter.second(); } HashMapT<CacheableInt32Ptr, CacheableHashSetPtr>::Iterator - bucketToKeysiter = bucketToKeysMap->find(*bucket); + bucketToKeysiter = bucketToKeysMap->find( + std::static_pointer_cast<CacheableInt32>(*bucket)); if (bucketToKeysiter != bucketToKeysMap->end()) { CacheableHashSetPtr bkeys = bucketToKeysiter.second(); for (CacheableHashSet::Iterator itr = bkeys->begin(); @@ -697,7 +697,7 @@ BucketServerLocationPtr ClientMetadataService::findNextServer( int random = randgen(nodeSize); return nodesOfEqualSize.at(random); } - return NULLPTR; + return nullptr; } bool ClientMetadataService::AreBucketSetsEqual( @@ -744,7 +744,7 @@ ClientMetadataService::pruneNodes(ClientMetadataPtr& metadata, for (CacheableHashSet::Iterator bucketId = buckets->begin(); bucketId != buckets->end(); ++bucketId) { - CacheableInt32Ptr bID = *bucketId; + CacheableInt32Ptr bID = std::static_pointer_cast<CacheableInt32>(*bucketId); std::vector<BucketServerLocationPtr> locations = metadata->adviseServerLocations(bID->value()); if (locations.size() == 0) { @@ -809,7 +809,7 @@ ClientMetadataService::pruneNodes(ClientMetadataPtr& metadata, while (!AreBucketSetsEqual(currentBucketSet, buckets)) { BucketServerLocationPtr server = findNextServer(serverToBucketsMap, currentBucketSet); - if (server == NULLPTR) { + if (server == nullptr) { LOGDEBUG( "ClientMetadataService::pruneNodes findNextServer returned no " "server"); @@ -855,7 +855,7 @@ ClientMetadataService::pruneNodes(ClientMetadataPtr& metadata, prunedServerToBucketsMap->begin(); for (CacheableHashSet::Iterator itr = bucketSetWithoutServer->begin(); itr != bucketSetWithoutServer->end(); ++itr) { - CacheableInt32Ptr buckstId = *itr; + CacheableInt32Ptr buckstId = std::static_pointer_cast<CacheableInt32>(*itr); itrRes2.second()->insert(buckstId); } @@ -867,7 +867,7 @@ HashMapT<BucketServerLocationPtr, CacheableHashSetPtr>* ClientMetadataService::groupByServerToAllBuckets(const RegionPtr& region, bool optimizeForWrite) { ClientMetadataPtr cptr = getClientMetadata(region->getFullPath()); - if (cptr == NULLPTR) { + if (cptr == nullptr) { enqueueForMetadataRefresh(region->getFullPath(), false); return NULL; } @@ -889,10 +889,11 @@ ClientMetadataService::groupByServerToBuckets(ClientMetadataPtr& metadata, CacheableHashSetPtr bucketsWithoutServer = CacheableHashSet::create(); for (CacheableHashSet::Iterator itr = bucketSet->begin(); itr != bucketSet->end(); ++itr) { - CacheableInt32Ptr bucketId = *itr; + CacheableInt32Ptr bucketId = + std::static_pointer_cast<CacheableInt32>(*itr); BucketServerLocationPtr serverLocation = metadata->advisePrimaryServerLocation(bucketId->value()); - if (serverLocation == NULLPTR) { + if (serverLocation == nullptr) { bucketsWithoutServer->insert(bucketId); continue; } else if (!serverLocation->isValid()) { @@ -949,7 +950,7 @@ void ClientMetadataService::markPrimaryBucketForTimeoutButLookSecondaryBucket( getBucketServerLocation(region, key, value, aCallbackArgument, true, serverLocation, version); - ClientMetadataPtr cptr = NULLPTR; + ClientMetadataPtr cptr = nullptr; { ReadGuard guard(m_regionMetadataLock); RegionMetadataMapType::iterator cptrIter = @@ -959,7 +960,7 @@ void ClientMetadataService::markPrimaryBucketForTimeoutButLookSecondaryBucket( cptr = cptrIter->second; } - if (cptr == NULLPTR) { + if (cptr == nullptr) { return; } } @@ -994,7 +995,7 @@ bool ClientMetadataService::isBucketMarkedForTimeout(const char* regionFullPath, if (bs != m_bucketStatus.end()) { bool m = bs->second->isBucketTimedOut(bucketid, m_bucketWaitTimeout); if (m == true) { - ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.ptr()); + ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool); CacheImpl* cache = tcrdm->getConnectionManager().getCacheImpl(); cache->setBlackListBucketTimeouts(); } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ClientMetadataService.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ClientMetadataService.hpp b/src/cppcache/src/ClientMetadataService.hpp index 99ddd23..c39a69a 100644 --- a/src/cppcache/src/ClientMetadataService.hpp +++ b/src/cppcache/src/ClientMetadataService.hpp @@ -106,7 +106,7 @@ class ClientMetadataService : public ACE_Task_Base, private NonAssignable { public: ~ClientMetadataService(); - ClientMetadataService(PoolPtr pool); + ClientMetadataService(Pool* pool); inline void start() { m_run = true; @@ -198,7 +198,7 @@ class ClientMetadataService : public ACE_Task_Base, ACE_Semaphore m_regionQueueSema; RegionMetadataMapType m_regionMetaDataMap; volatile bool m_run; - PoolPtr m_pool; + Pool* m_pool; Queue<std::string>* m_regionQueue; ACE_RW_Thread_Mutex m_PRbucketStatusLock; http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ClientProxyMembershipID.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ClientProxyMembershipID.cpp b/src/cppcache/src/ClientProxyMembershipID.cpp index 4e05265..07e6a9b 100644 --- a/src/cppcache/src/ClientProxyMembershipID.cpp +++ b/src/cppcache/src/ClientProxyMembershipID.cpp @@ -376,7 +376,7 @@ Serializable* ClientProxyMembershipID::fromData(DataInput& input) { input.readInt(&dcport); // port input.readInt(&vPID); // pid input.read(&vmKind); // vmkind - CacheableStringArrayPtr aStringArray(CacheableStringArray::create()); + auto aStringArray = CacheableStringArray::create(); aStringArray->fromData(input); input.readObject(dsName); // name input.readObject(uniqueTag); // unique tag @@ -386,7 +386,7 @@ Serializable* ClientProxyMembershipID::fromData(DataInput& input) { readVersion(splitbrain, input); if (vmKind != ClientProxyMembershipID::LONER_DM_TYPE) { - vmViewId = atoi(uniqueTag.ptr()->asChar()); + vmViewId = atoi(uniqueTag.get()->asChar()); initObjectVars(hostname->asChar(), hostAddr, len, true, hostPort, durableClientId->asChar(), durableClntTimeOut, dcport, vPID, vmKind, splitbrain, dsName->asChar(), NULL, vmViewId); @@ -431,7 +431,7 @@ Serializable* ClientProxyMembershipID::readEssentialData(DataInput& input) { input.readObject(uniqueTag); // unique tag } else { input.readObject(vmViewIdstr); - vmViewId = atoi(vmViewIdstr.ptr()->asChar()); + vmViewId = atoi(vmViewIdstr.get()->asChar()); } input.readObject(dsName); // name @@ -461,25 +461,22 @@ void ClientProxyMembershipID::increaseSynchCounter() { ++synch_counter; } // Compares two membershipIds. This is based on the compareTo function // of InternalDistributedMember class of Java. // Any change to the java function should be reflected here as well. -int16_t ClientProxyMembershipID::compareTo(DSMemberForVersionStampPtr other) { - if (other.operator==(this)) { +int16_t ClientProxyMembershipID::compareTo( + const DSMemberForVersionStamp& other) const { + if (this == &other) { return 0; } - if (other.ptr() == NULL) { - throw ClassCastException( - "ClientProxyMembershipID.compare(): comparing with a null value"); - } - ClientProxyMembershipIDPtr otherMember = - dynCast<ClientProxyMembershipIDPtr>(other); + const ClientProxyMembershipID& otherMember = + static_cast<const ClientProxyMembershipID&>(other); uint32_t myPort = getHostPort(); - uint32_t otherPort = otherMember->getHostPort(); + uint32_t otherPort = otherMember.getHostPort(); if (myPort < otherPort) return -1; if (myPort > otherPort) return 1; uint8_t* myAddr = getHostAddr(); - uint8_t* otherAddr = otherMember->getHostAddr(); + uint8_t* otherAddr = otherMember.getHostAddr(); // Discard null cases if (myAddr == NULL && otherAddr == NULL) { if (myPort < otherPort) { @@ -500,11 +497,11 @@ int16_t ClientProxyMembershipID::compareTo(DSMemberForVersionStampPtr other) { } std::string myUniqueTag = getUniqueTag(); - std::string otherUniqueTag = otherMember->getUniqueTag(); + std::string otherUniqueTag = otherMember.getUniqueTag(); if (myUniqueTag.empty() && otherUniqueTag.empty()) { - if (m_vmViewId < otherMember->m_vmViewId) { + if (m_vmViewId < otherMember.m_vmViewId) { return -1; - } else if (m_vmViewId > otherMember->m_vmViewId) { + } else if (m_vmViewId > otherMember.m_vmViewId) { return 1; } // else they're the same, so continue } else if (myUniqueTag.empty()) { http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ClientProxyMembershipID.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ClientProxyMembershipID.hpp b/src/cppcache/src/ClientProxyMembershipID.hpp index 86b7150..347cc52 100644 --- a/src/cppcache/src/ClientProxyMembershipID.hpp +++ b/src/cppcache/src/ClientProxyMembershipID.hpp @@ -85,7 +85,7 @@ class ClientProxyMembershipID : public DSMemberForVersionStamp { uint32_t getHostAddrLen() const { return m_hostAddrLen; } uint32_t getHostPort() const { return m_hostPort; } virtual std::string getHashKey(); - virtual int16_t compareTo(DSMemberForVersionStampPtr); + virtual int16_t compareTo(const DSMemberForVersionStamp&) const; virtual int32_t hashcode() const { uint32_t result = 0; char hostInfo[255] = {0}; @@ -101,19 +101,8 @@ class ClientProxyMembershipID : public DSMemberForVersionStamp { } virtual bool operator==(const CacheableKey& other) const { - CacheableKey& otherCopy = const_cast<CacheableKey&>(other); - DSMemberForVersionStamp& temp = - dynamic_cast<DSMemberForVersionStamp&>(otherCopy); - DSMemberForVersionStampPtr obj = NULLPTR; - obj = DSMemberForVersionStampPtr(&temp); - - DSMemberForVersionStampPtr callerPtr = NULLPTR; - callerPtr = DSMemberForVersionStampPtr(this); - if (callerPtr->compareTo(obj) == 0) { - return true; - } else { - return false; - } + return (this->compareTo( + dynamic_cast<const DSMemberForVersionStamp&>(other)) == 0); } Serializable* readEssentialData(DataInput& input); http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ConcurrentEntriesMap.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ConcurrentEntriesMap.cpp b/src/cppcache/src/ConcurrentEntriesMap.cpp index d988026..b2fd1fc 100644 --- a/src/cppcache/src/ConcurrentEntriesMap.cpp +++ b/src/cppcache/src/ConcurrentEntriesMap.cpp @@ -81,7 +81,7 @@ GfErrType ConcurrentEntriesMap::create(const CacheableKeyPtr& key, GfErrType err = GF_NOERR; if ((err = segmentFor(key)->create(key, newValue, me, oldValue, updateCount, destroyTracker, versionTag)) == GF_NOERR && - oldValue == NULLPTR) { + oldValue == nullptr) { ++m_size; } return err; http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/ConcurrentEntriesMap.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/ConcurrentEntriesMap.hpp b/src/cppcache/src/ConcurrentEntriesMap.hpp index 7bceedd..37691ee 100644 --- a/src/cppcache/src/ConcurrentEntriesMap.hpp +++ b/src/cppcache/src/ConcurrentEntriesMap.hpp @@ -71,7 +71,8 @@ class CPPCACHE_EXPORT ConcurrentEntriesMap : public EntriesMap { */ ConcurrentEntriesMap(EntryFactory* entryFactory, bool concurrencyChecksEnabled, - RegionInternal* region = NULL, uint8_t concurrency = 16); + RegionInternal* region = nullptr, + uint8_t concurrency = 16); /** * Initialize segments with proper EntryFactory. http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CppCacheLibrary.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CppCacheLibrary.cpp b/src/cppcache/src/CppCacheLibrary.cpp index 93c0fec..50cd260 100644 --- a/src/cppcache/src/CppCacheLibrary.cpp +++ b/src/cppcache/src/CppCacheLibrary.cpp @@ -30,7 +30,6 @@ #include "LRUExpMapEntry.hpp" #include <geode/CacheFactory.hpp> #include "SerializationRegistry.hpp" -#include "CacheableToken.hpp" #include <geode/DataOutput.hpp> #include "TcrMessage.hpp" #include "Utils.hpp" @@ -38,15 +37,18 @@ #include <string> -using namespace apache::geode::client; +// called during DLL initialization +void initLibDllEntry(void) { apache::geode::client::CppCacheLibrary::initLib(); } + +extern "C" { +void DllMainGetPath(char* result, int maxLen); +} namespace apache { namespace geode { namespace client { -void gf_log_libinit(); -} // namespace client -} // namespace geode -} // namespace apache + + void gf_log_libinit(); CppCacheLibrary::CppCacheLibrary() { // TODO: This should catch any exceptions, log it, and bail out.. @@ -58,7 +60,6 @@ CppCacheLibrary::CppCacheLibrary() { ExpEntryFactory::init(); LRUExpEntryFactory::init(); CacheFactory::init(); - CacheableToken::init(); SerializationRegistry::init(); // PdxTypeRegistry::init(); // log( "Finished initializing CppCacheLibrary." ); @@ -96,13 +97,6 @@ void CppCacheLibrary::closeLib(void) { // using geode. } -// called during DLL initialization -void initLibDllEntry(void) { CppCacheLibrary::initLib(); } - -extern "C" { -void DllMainGetPath(char* result, int maxLen); -} - // Returns pathname of product's lib directory, adds 'addon' to it if 'addon' is // not null. std::string CppCacheLibrary::getProductLibDir(const char* addon) { @@ -200,3 +194,7 @@ std::string CppCacheLibrary::getProductDir() { } } + +} // namespace client +} // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CqAttributesFactory.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CqAttributesFactory.cpp b/src/cppcache/src/CqAttributesFactory.cpp index f2cdbe0..2c75ca1 100644 --- a/src/cppcache/src/CqAttributesFactory.cpp +++ b/src/cppcache/src/CqAttributesFactory.cpp @@ -21,37 +21,31 @@ using namespace apache::geode::client; CqAttributesFactory::CqAttributesFactory() { - m_cqAttributes = new CqAttributesImpl(); + m_cqAttributes = std::make_shared<CqAttributesImpl>(); } -CqAttributesFactory::CqAttributesFactory(CqAttributesPtr &cqAttributes) { - CqAttributesImpl *cqImpl = new CqAttributesImpl(); - m_cqAttributes = cqImpl; - VectorOfCqListener vl; - CqAttributesImpl *cqAttr = - dynamic_cast<CqAttributesImpl *>(cqAttributes.ptr()); - cqAttr->getCqListeners(vl); - cqImpl->setCqListeners(vl); +CqAttributesFactory::CqAttributesFactory(const CqAttributesPtr &cqAttributes) { + m_cqAttributes = std::make_shared<CqAttributesImpl>(); + CqAttributesImpl::listener_container_type vl; + std::static_pointer_cast<CqAttributesImpl>(cqAttributes)->getCqListeners(vl); + std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes) + ->setCqListeners(vl); } void CqAttributesFactory::addCqListener(const CqListenerPtr &cqListener) { - if (cqListener == NULLPTR) { + if (cqListener == nullptr) { throw IllegalArgumentException("addCqListener parameter was null"); } - CqAttributesImpl *cqImpl = - dynamic_cast<CqAttributesImpl *>(m_cqAttributes.ptr()); - CqListenerPtr listener = dynCast<CqListenerPtr>(cqListener); - cqImpl->addCqListener(listener); + std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes) + ->addCqListener(cqListener); } -void CqAttributesFactory::initCqListeners(VectorOfCqListener &cqListeners) { - CqAttributesImpl *cqImpl = - dynamic_cast<CqAttributesImpl *>(m_cqAttributes.ptr()); - cqImpl->setCqListeners(cqListeners); +void CqAttributesFactory::initCqListeners( + const CqAttributesImpl::listener_container_type &cqListeners) { + std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes) + ->setCqListeners(cqListeners); } CqAttributesPtr CqAttributesFactory::create() { - CqAttributesImpl *cqImpl = - dynamic_cast<CqAttributesImpl *>(m_cqAttributes.ptr()); - CqAttributesPtr ptr(cqImpl->clone()); - return ptr; + return CqAttributesPtr( + std::static_pointer_cast<CqAttributesImpl>(m_cqAttributes)->clone()); } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CqAttributesImpl.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CqAttributesImpl.cpp b/src/cppcache/src/CqAttributesImpl.cpp index c10bb13..53494d4 100644 --- a/src/cppcache/src/CqAttributesImpl.cpp +++ b/src/cppcache/src/CqAttributesImpl.cpp @@ -17,17 +17,13 @@ #include "CqAttributesImpl.hpp" #include <geode/ExceptionTypes.hpp> using namespace apache::geode::client; -void CqAttributesImpl::getCqListeners(VectorOfCqListener& vl) { +void CqAttributesImpl::getCqListeners(listener_container_type& vl) { ACE_Guard<ACE_Recursive_Thread_Mutex> _guard(m_mutex); - vl.clear(); - // vl.reserve(m_cqListeners.size()); vl = m_cqListeners; - // for(size_t i=0; i < m_cqListeners.size(); i++) - // vl[i] = m_cqListeners[i]; } -void CqAttributesImpl::addCqListener(CqListenerPtr& cql) { - if (cql == NULLPTR) { +void CqAttributesImpl::addCqListener(const CqListenerPtr& cql) { + if (cql == nullptr) { throw IllegalArgumentException("addCqListener parameter was null"); } ACE_Guard<ACE_Recursive_Thread_Mutex> _guard(m_mutex); @@ -35,25 +31,27 @@ void CqAttributesImpl::addCqListener(CqListenerPtr& cql) { } CqAttributesImpl* CqAttributesImpl::clone() { - CqAttributesImpl* ptr = new CqAttributesImpl(); - ptr->setCqListeners(m_cqListeners); - return ptr; + auto clone = new CqAttributesImpl(); + clone->setCqListeners(m_cqListeners); + return clone; } -void CqAttributesImpl::setCqListeners(VectorOfCqListener& addedListeners) { +void CqAttributesImpl::setCqListeners( + const listener_container_type& addedListeners) { if (addedListeners.empty() == true) { LOGWARN("setCqListeners parameter had a null element, nothing to be set"); return; } - VectorOfCqListener oldListeners(m_cqListeners); + + decltype(m_cqListeners) oldListeners(m_cqListeners); { ACE_Guard<ACE_Recursive_Thread_Mutex> _guard(m_mutex); m_cqListeners = addedListeners; } if (!oldListeners.empty()) { - for (int32_t i = 0; i < oldListeners.length(); i++) { + for (auto l : oldListeners) { try { - oldListeners[i]->close(); + l->close(); // Handle client side exceptions. } catch (Exception& ex) { LOGWARN("Exception occured while closing CQ Listener %s Error", @@ -64,17 +62,16 @@ void CqAttributesImpl::setCqListeners(VectorOfCqListener& addedListeners) { } } -void CqAttributesImpl::removeCqListener(CqListenerPtr& cql) { - if (cql == NULLPTR) { +void CqAttributesImpl::removeCqListener(const CqListenerPtr& cql) { + if (cql == nullptr) { throw IllegalArgumentException("removeCqListener parameter was null"); } ACE_Guard<ACE_Recursive_Thread_Mutex> _guard(m_mutex); if (!m_cqListeners.empty()) { - for (int32_t i = 0; i < m_cqListeners.size(); i++) { - if (m_cqListeners.at(i) == cql) { - m_cqListeners.erase(i); - } - } + m_cqListeners.erase( + std::remove_if(m_cqListeners.begin(), m_cqListeners.end(), + [cql](CqListenerPtr l) -> bool { return cql == l; }), + m_cqListeners.end()); try { cql->close(); // Handle client side exceptions. http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/CqAttributesImpl.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/CqAttributesImpl.hpp b/src/cppcache/src/CqAttributesImpl.hpp index 0a09258..c32d8fa 100644 --- a/src/cppcache/src/CqAttributesImpl.hpp +++ b/src/cppcache/src/CqAttributesImpl.hpp @@ -49,13 +49,7 @@ namespace client { */ class CPPCACHE_EXPORT CqAttributesImpl : public CqAttributes { public: - /** - * Get the CqListeners set with the CQ. - * Returns all the Listener associated with this CQ. - * @see CqListener - * @return VectorOfCqListener of CqListnerPtr - */ - void getCqListeners(VectorOfCqListener& vl); + void getCqListeners(listener_container_type& vl); /** * Get the CqListener set with the CQ. @@ -65,13 +59,13 @@ class CPPCACHE_EXPORT CqAttributesImpl : public CqAttributes { * @return CqListener Object, returns null if there is no CqListener. */ CqListenerPtr getCqListener(); - void addCqListener(CqListenerPtr& cql); - void setCqListeners(VectorOfCqListener& addedListeners); - void removeCqListener(CqListenerPtr& cql); + void addCqListener(const CqListenerPtr& cql); + void setCqListeners(const listener_container_type& addedListeners); + void removeCqListener(const CqListenerPtr& cql); CqAttributesImpl* clone(); private: - VectorOfCqListener m_cqListeners; + listener_container_type m_cqListeners; bool m_dataPolicyHasBeenSet; ACE_Recursive_Thread_Mutex m_mutex; };
