Example #1
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 #2
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 #3
0
void
FreezeScript::AssignVisitor::visitDictionary(const DictionaryDataPtr& dest)
{
    Slice::TypePtr type = dest->getType();
    DictionaryDataPtr d = DictionaryDataPtr::dynamicCast(_src);
    if(d && isCompatible(type, _src->getType()))
    {
        DataMap& srcMap = d->getElements();
        DataMap destMap;
        Slice::DictionaryPtr dictType = Slice::DictionaryPtr::dynamicCast(type);
        assert(dictType);
        Slice::TypePtr keyType = dictType->keyType();
        Slice::TypePtr valueType = dictType->valueType();
        string typeName = typeToString(type);
        for(DataMap::const_iterator p = srcMap.begin(); p != srcMap.end(); ++p)
        {
            DataPtr key = _factory->create(keyType, false);
            Destroyer<DataPtr> keyDestroyer(key);
            DataPtr value = _factory->create(valueType, false);
            Destroyer<DataPtr> valueDestroyer(value);

            AssignVisitor keyVisitor(p->first, _factory, _errorReporter, _convert, typeName + " key");
            key->visit(keyVisitor);

            AssignVisitor valueVisitor(p->second, _factory, _errorReporter, _convert, typeName + " value");
            value->visit(valueVisitor);

            DataMap::const_iterator q = destMap.find(key);
            if(q != destMap.end())
            {
                error("duplicate dictionary key in " + typeToString(dictType));
            }
            else
            {
                destMap.insert(DataMap::value_type(key, value));
                keyDestroyer.release();
                valueDestroyer.release();
            }
        }
        DataMap& m = dest->getElements();
        m.swap(destMap);
    }
    else
    {
        typeMismatchError(type, _src->getType());
    }
}
Example #4
0
void
FreezeScript::TransformVisitor::visitDictionary(const DictionaryDataPtr& dest)
{
    Slice::TypePtr type = dest->getType();
    if(_info->doDefaultTransform(type))
    {
        DictionaryDataPtr d = DictionaryDataPtr::dynamicCast(_src);
        if(d && isCompatible(type, _src->getType()))
        {
            DataMap& srcMap = d->getElements();
            DataMap destMap;
            Slice::DictionaryPtr dictType = Slice::DictionaryPtr::dynamicCast(type);
            assert(dictType);
            Slice::TypePtr keyType = dictType->keyType();
            Slice::TypePtr valueType = dictType->valueType();
            string typeName = typeToString(type);
            for(DataMap::const_iterator p = srcMap.begin(); p != srcMap.end(); ++p)
            {
                DataPtr key = _info->getDataFactory()->create(keyType, false);
                Destroyer<DataPtr> keyDestroyer(key);
                DataPtr value = _info->getDataFactory()->create(valueType, false);
                Destroyer<DataPtr> valueDestroyer(value);

                TransformVisitor keyVisitor(p->first, _info, typeName + " key");
                key->visit(keyVisitor);

                try
                {
                    TransformVisitor valueVisitor(p->second, _info, typeName + " value");
                    value->visit(valueVisitor);
                }
                catch(const ClassNotFoundException& ex)
                {
                    //
                    // If transformation of the dictionary value fails because a class
                    // could not be found, then we invoke purgeObjects() to determine
                    // whether we should ignore the situation (and remove the element
                    // from the dictionary) or raise the exception again.
                    //
                    if(!_info->purgeObjects())
                    {
                        throw;
                    }
                    warning("purging element of dictionary " + typeToString(dictType) + " due to missing class type " +
                            ex.id);
                    continue;
                }

                DataMap::const_iterator q = destMap.find(key);
                if(q != destMap.end())
                {
                    warning("duplicate dictionary key in " + typeToString(dictType));
                }
                else
                {
                    destMap.insert(DataMap::value_type(key, value));
                    keyDestroyer.release();
                    valueDestroyer.release();
                }
            }
            DataMap& m = dest->getElements();
            m.swap(destMap);
        }
        else
        {
            typeMismatchError(type, _src->getType());
        }
    }
    _info->executeCustomTransform(dest, _src);
}
Example #5
0
File: t_hash.cpp Project: cvan/ardb
 int Ardb::HashSet(Context& ctx, ValueObject& meta, const Data& field, Data& value)
 {
     DataMap fs;
     fs.insert(DataMap::value_type(field, value));
     return HashMultiSet(ctx, meta, fs);
 }
Example #6
0
/** sqlite3_exec的回调。
*
*  向控制台打印查询的结果。
*
*  @param in data 传递给回调函数的数据。
*  @param in n_columns sqlite3_exec执行结果集中列的数量。
*  @param in col_values sqlite3_exec执行结果集中每一列的数据。
*  @param in col_names sqlite3_exec执行结果集中每一列的名称。
*  @return 状态码。
*/
int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
{
	s_trade trade;
	long time_peroid = 0;
    /*
	for (int i = 0; i < n_columns; i++)
    {
	printf("%s:%s\t", col_names[i], col_values[i]);
    }
	*/
	trade.timestamp = atol(col_values[0]);
	trade.price = atof(col_values[1]);
	trade.amount = atof(col_values[2]);
	
    if(0 == strcmp((const char *)data, "5m")){
		time_peroid = 5*60;
	} else if(0 == strcmp((const char *)data, "15m")){
		time_peroid = 15*60;
	} else if(0 == strcmp((const char *)data, "30m")){
		time_peroid = 30*60;
	} else if(0 == strcmp((const char *)data, "1h")){
		time_peroid = 60*60;
	} else if(0 == strcmp((const char *)data, "4h")){
		time_peroid = 60*60;
	} else if(0 == strcmp((const char *)data, "1d")){
		time_peroid = 60*60*24;
	}
	
	if(0 != time_peroid){
		long time = ((long)(trade.timestamp/time_peroid))*time_peroid;
		DataMap::iterator it = dataMap.find(time);
		if(it==dataMap.end())
		{
			s_history history;
			history.amount = trade.amount;
			history.open = trade.price;
			history.close = trade.price;
			history.high = trade.price;
			history.low = trade.price;
			history.timestamp = time;
			history.open_timestamp = trade.timestamp;
			history.close_timestamp = trade.timestamp;
			dataMap.insert(std::make_pair(time, history));
		} else {
			it->second.amount += trade.amount;
			if(trade.price > it->second.high){
				it->second.high = trade.price;
			}
			if(trade.price < it->second.low){
				it->second.low = trade.price;
			}
			if(trade.timestamp < it->second.open_timestamp){
				it->second.open = trade.price;
				it->second.open_timestamp = trade.timestamp;
			}
			if(trade.timestamp > it->second.close_timestamp){
				it->second.close = trade.price;
				it->second.close_timestamp = trade.timestamp;
			}
		}
	}
	
    return 0;
}