Exemple #1
0
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;
}
Exemple #2
0
DataMap TripodClient::getWithMissed(const KeySeq& keys, long expiredTime, bool useMaster, const long timeout) {
    KeySeq missedKeys;
    DataMap res = get(keys, missedKeys, timeout);

    if(!missedKeys.empty()) {
        DataMap missedRes = getMissed(missedKeys, expiredTime, useMaster, timeout);
        res.insert(missedRes.begin(), missedRes.end());
    }
    return res;
}
Exemple #3
0
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;
}
Exemple #4
0
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);
    }
  }
}