Example #1
0
bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& business_id, bool use_master, const Ice::Current& current) {
  std::ostringstream otem;
  otem << "CacheManageI::loadListCache() key:" << key
       << "\tnamespace_id:" << namespace_id 
       << "\tbusiness_id:" << business_id;
  MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, otem.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
  ProducerManagerClientPtr producer = getProducer();
  if(producer == NULL) {
      return false;
  }
  KeySeq keys;
  keys.push_back(key);
  DataMap data = producer->produce(keys, business_id, use_master, 0);
  if (data.empty()) {
    return true;
  } 
  std::string list_key;
  StrList list_value;
  DataMap::const_iterator iter = data.begin();
  list_key = iter->second;
  for (; iter != data.end(); ++iter) {
    list_value.push_back(iter->first);
  }
  RedisCacheClientPtr redis_client = GetRedisCache(); 
  redis_client->Set(list_key, list_value, namespace_id, business_id);
  return true;
}
Example #2
0
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);
        }
    }
}
Example #3
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;
}
Example #4
0
void MenuCacheManagerI::load(const UserIdSeq& userIds, const Ice::Current& current) {
  MCE_INFO("[MenuCacheManagerI::load] userIds.size = " << userIds.size());
  KeySeq keys;
  for (vector<int>::const_iterator it = userIds.begin(); it != userIds.end(); ++it) {
    string userIdStr = boost::lexical_cast<string>(*it);
    keys.push_back(TripodHelper::getCacheTypeStr(RECENTLY) + SPLITTOR + userIdStr);
    keys.push_back(TripodHelper::getCacheTypeStr(FAVORITE) + SPLITTOR + userIdStr);
  }
  addKeysToLoad(keys);
}
PropertiesManage::KeySeq
PropertiesManage::getKeys() const
{
	KeySeq keys;
	for(unsigned long i = 0; i < props_.size(); i += 2)
	{
		keys.push_back (props_[i]) ;
	}
	return keys;
}
PropertiesManage::KeySeq
PropertiesManage::getKeys(const char* prefix) const
{
	KeySeq keys;
	int prefLen = strlen(prefix);
	for(unsigned long i = 0; i < props_.size(); i += 2)
	{
		if(strncmp(props_[i].c_str(), prefix, prefLen) == 0) 
		{
			keys.push_back (props_[i]) ;
		}
	}
	return keys;
}
Example #7
0
// <KEY_SEQUENCE>
KeySeq *SettingLoader::load_KEY_SEQUENCE(
	const tstringi &i_name, bool i_isInParen, Modifier::Type i_mode)
{
	KeySeq keySeq(i_name);
	while (!isEOL()) {
		Modifier::Type mode;
		Modifier modifier = load_MODIFIER(i_mode, m_defaultKeySeqModifier, &mode);
		keySeq.setMode(mode);
		Token *t = lookToken();
		if (t->isCloseParen() && i_isInParen)
			break;
		else if (t->isOpenParen()) {
			getToken(); // open paren
			KeySeq *ks = load_KEY_SEQUENCE(_T(""), true, i_mode);
			getToken(); // close paren
			keySeq.add(ActionKeySeq(ks));
		} else if (*t == _T("$")) { // <KEYSEQ_NAME>
			getToken();
			t = getToken();
			KeySeq *ks = m_setting->m_keySeqs.searchByName(t->getString());
			if (ks == NULL)
				throw ErrorMessage() << _T("`$") << *t
				<< _T("': unknown keyseq name.");
			if (!ks->isCorrectMode(i_mode))
				throw ErrorMessage()
				<< _T("`$") << *t
				<< _T("': Some of R-, IL-, IC-, NL-, CL-, SL-, KL-, MAX-, MIN-, MMAX-, MMIN-, T-, TS-, M0...M9- and L0...L9- are used in the keyseq.  They are prohibited in this context.");
			keySeq.setMode(ks->getMode());
			keySeq.add(ActionKeySeq(ks));
		} else if (*t == _T("&")) { // <FUNCTION_NAME>
			getToken();
			t = getToken();

			// search function
			ActionFunction af(createFunctionData(t->getString()), modifier);
			if (af.m_functionData == NULL)
				throw ErrorMessage() << _T("`&") << *t
				<< _T("': unknown function name.");
			af.m_functionData->load(this);
			keySeq.add(af);
		} else { // <KEYSEQ_MODIFIED_KEY_NAME>
			ModifiedKey mkey;
			mkey.m_modifier = modifier;
			mkey.m_key = load_KEY_NAME();
			keySeq.add(ActionKey(mkey));
		}
	}
	return m_setting->m_keySeqs.add(keySeq);
}
Example #8
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;
}
Example #9
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);
    }
  }
}
Example #10
0
bool CacheManagerClient::LoadListCache(const std::string& key, const std::string& namespace_id, const std::string& biz_id, bool use_master) {
  CacheManagerConfigClientPtr config = getConfig();
  if(config == NULL) {
      TRIPOD_WARN("CacheManagerClient::LoadListCache config is NULL, namespaceId " + namespace_id + " businessId " + biz_id);
      MCE_WARN("CacheManagerClient::LoadListCache config is NULL, namespaceId " + namespace_id + " businessId " + biz_id);
      return false;
  }
  
  KeySeq keys;
  keys.push_back(key);

  std::map<CacheManagerPrx, KeySeq> prx_map = config->getPrxToKeysMap(keys);
  std::map<CacheManagerPrx, KeySeq>::const_iterator iter = prx_map.begin();
  for (; iter != prx_map.end(); ++iter) {
    const KeySeq& seq = iter->second;
    BOOST_FOREACH(const std::string& k, seq) {
      iter->first->loadListCache(k, namespace_id, biz_id, use_master);
    }   
  }
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);
    }
  }
}
Example #12
0
// <DEFINE_SUBSTITUTE>
void SettingLoader::load_DEFINE_SUBSTITUTE()
{
	typedef std::list<ModifiedKey> AssignedKeys;
	AssignedKeys assignedKeys;
	do {
		ModifiedKey mkey;
		mkey.m_modifier =
			load_MODIFIER(Modifier::Type_ASSIGN, m_defaultAssignModifier);
		mkey.m_key = load_KEY_NAME();
		assignedKeys.push_back(mkey);
	} while (!(*lookToken() == _T("=>") || *lookToken() == _T("=")));
	getToken();

	KeySeq *keySeq = load_KEY_SEQUENCE(_T(""), false, Modifier::Type_ASSIGN);
	ModifiedKey mkey = keySeq->getFirstModifiedKey();
	if (!mkey.m_key)
		throw ErrorMessage() << _T("no key is specified for substitute.");

	for (AssignedKeys::iterator i = assignedKeys.begin();
			i != assignedKeys.end(); ++ i)
		m_setting->m_keyboard.addSubstitute(*i, mkey);
}
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();
}
Example #14
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;
}