bool CacheManagerI::load(const KeySeq& keys, const std::string& namespaceId, const std::string& businessId, long expiredTime, bool useMaster, const Ice::Current& current) { std::ostringstream os; os<<"Key : "; for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) { os<<*it<<" "; } os<<" namespaceId :"<<namespaceId; os<<" businessId :"<<businessId; os<<" expiredTime :"<<expiredTime; os<<" useMaster :"<<useMaster; MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO); ProducerManagerClientPtr producer = getProducer(); if(producer == NULL) { return false; } bool sucFlag = true; KeySeq inputKeys(keys.begin(), keys.end()); KeySeq lockedKeys; KeySeq failedLockedKeys; DataMap res; while(true) { xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, inputKeys, lockedKeys, failedLockedKeys); if(!lockedKeys.empty()) { DataMap singleRes = producer->produce(keys, businessId, useMaster, 1000); if(!singleRes.empty()) { res.insert(singleRes.begin(), singleRes.end()); } CacheClientPtr cache = getCache(); if(cache != NULL) { for(DataMap::const_iterator it = singleRes.begin(); it != singleRes.end(); ++it) { sucFlag &= cache->set(it->first, it->second, namespaceId, businessId, expiredTime, 1000); } } if(failedLockedKeys.empty()) { break; } } inputKeys.swap(failedLockedKeys); lockedKeys.clear(); failedLockedKeys.clear(); } return sucFlag; }
void TripodClient::getMissedKeys(const DataMap& res, const KeySeq& keys, KeySeq& missedKeys) { for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) { if(res.find(*it) == res.end()) { missedKeys.push_back(*it); } } }
bool CacheManagerI::deleteCache(const KeySeq& keys, const std::string& namespaceId, const std::string& businessId, const Ice::Current& current) { std::ostringstream os; os<<"Key : "; for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) { os<<*it<<" "; } os<<" namespaceId :"<<namespaceId; os<<" businessId :"<<businessId; MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO); CacheClientPtr cache = getCache(); if(cache == NULL) { return false; } bool sucFlag = true; KeySeq inputKeys(keys.begin(), keys.end()); KeySeq lockedKeys; KeySeq failedLockedKeys; DataMap res; while(true) { xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, inputKeys, lockedKeys, failedLockedKeys); if(!lockedKeys.empty()) { for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) { sucFlag &= cache->remove(*it, namespaceId, businessId, 1000); } if(failedLockedKeys.empty()) { break; } } inputKeys.swap(failedLockedKeys); lockedKeys.clear(); failedLockedKeys.clear(); } return sucFlag; }
void ReloadFromTripodThread::run() { while (true) { KeySeq keysToReload; { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mutex_); if (this->keysToReload_.empty()) { mutex_.wait(); } keysToReload.insert(keysToReload.end(), this->keysToReload_.begin(), this->keysToReload_.end()); } if (!keysToReload.empty()) { this->tripodClient_->load(keysToReload, 2000, true); } } }
void ReloadFromTripodThread::run() { while (true) { KeySeq keysToReload; { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mutex_); if (this->keysToReload_.empty()) { mutex_.wait(); } keysToReload.insert(keysToReload.end(), this->keysToReload_.begin(), this->keysToReload_.end()); this->keysToReload_.clear(); } if (!keysToReload.empty()) { sleep(10); //MCE_INFO("[ReloadFromTripodThread::run] load keys.size = " << keysToReload.size()); this->tripodClient_->load(keysToReload, 2000, true); //刪除掉ObjectCache相应的内容,因为TripodCache已经是最新的了 vector<long> userIds = MenuCacheManagerI::convertStringSeq2LongSeq(keysToReload); ServiceI::instance().getObjectCache()->removeObjects(objCacheCategory_, userIds); } } }
void ReloadFromTripodThread::add(const KeySeq& keys) { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mutex_); this->keysToReload_.insert(this->keysToReload_.begin(), keys.begin(), keys.end()); mutex_.notify(); }