当前位置: 首页>>代码示例>>Java>>正文


Java TransactionalValue.getVal方法代码示例

本文整理汇总了Java中storm.trident.state.TransactionalValue.getVal方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionalValue.getVal方法的具体用法?Java TransactionalValue.getVal怎么用?Java TransactionalValue.getVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在storm.trident.state.TransactionalValue的用法示例。


在下文中一共展示了TransactionalValue.getVal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: multiPut

import storm.trident.state.TransactionalValue; //导入方法依赖的package包/类
@Override
public void multiPut(List<List<Object>> keys, List<TransactionalValue<T>> vals) {
    for (int i = 0; i < keys.size(); i++) {
        TridentTuple keyTuple = (TridentTuple) keys.get(i);
        TransactionalValue transactionalValue = (TransactionalValue) vals.get(i);
        Long txid = transactionalValue.getTxid();
        T key = (T) keyTuple.get(0);
        S3TransactionalOutput output = outputFor(key);
        List tuples = (List) transactionalValue.getVal();
        try {
            output.write(key, tuples, txid);
        } catch (IOException e) {
            LOG.error("Error while writing tuples for key {}", e, key);
        }
    }

}
 
开发者ID:wurstmeister,项目名称:storm-s3,代码行数:18,代码来源:S3MapState.java

示例2: multiPut

import storm.trident.state.TransactionalValue; //导入方法依赖的package包/类
@Override
public void multiPut(List<List<Object>> keys,
		List<TransactionalValue<Long>> vals) {
	// TODO Auto-generated method stub
	CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: entered with keys = %s, vals = %s", keys, vals);
	
	int curIndex = 0;
	for(List<Object> eachKeyList : keys)
	{
		String word = (String)eachKeyList.get(0);
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: key = %s", word);
		
		TransactionalValue<Long> curKeyVal = vals.get(curIndex);
		Long currentTxId = curKeyVal.getTxid();//Get current trxn id from the input argument only - Check the implementation of TransactionalMap:multiPut.
		
		
		/* Transactional State Management behaviour :
		 * Check if word(key) is already present in Redis.
		 * If present
		 *      Check the txId and the wordCount value stored against the key.
		 * 		If the current txId is higher than the stored txId, 
		 * 			Then update the wordCount.
		 *  		Else, ignore the data in the current trxn
		 * If not present
		 *         Add the word as key and (trxId , wordCount) as the value.
		 * 
		 * */
		
		List<String> redisVal = redisOperations.lrange(word);
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: count = %s for word = %s", redisVal, word);
		
		Long redisTxId = -1L;
		Long redisWordCount = 0L;

		boolean redisKeyExists = false;
		if(redisVal != null && redisVal.size() > 0)
		{
			redisTxId = Long.parseLong(redisVal.get(0));
			redisWordCount = Long.parseLong(redisVal.get(1));
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: redisTxId = %d, redisWordCount = %d", redisTxId,redisWordCount);
			redisKeyExists = true;
			

		}
		else
		{
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: no entry in Redis yet for word = %s",word);

		}

		
		
		Long wordCount = curKeyVal.getVal();
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: currentTxId = %d, wordCount = %d", currentTxId, wordCount);
		
		if(currentTxId != redisTxId && currentTxId > redisTxId)//Latest trxn id numbers will always be higher than previous ones.
		{
			Long latestWordCount = redisWordCount + wordCount;
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: latestWordCount = %d", latestWordCount);
			
			
			if(!redisKeyExists) //first time insert happening for a key
			{
				redisOperations.rpush(word, currentTxId+"", latestWordCount+"");
			}
			else//first pop out the old values and insert new values.
			{
				redisOperations.lpop(word, 2);
				redisOperations.rpush(word, currentTxId+"", latestWordCount+"");
				
			}
			
				
		}
		
		curIndex++;	

	}

	
}
 
开发者ID:BinitaBharati,项目名称:storm-trident-example,代码行数:82,代码来源:RedisStoreIBackingMap.java

示例3: multiPut

import storm.trident.state.TransactionalValue; //导入方法依赖的package包/类
@Override
public void multiPut(List<List<Object>> keys,
		List<TransactionalValue<Long>> vals) {
	// TODO Auto-generated method stub
	CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: entered with keys = %s, vals = %s", keys, vals);
	
	int curIndex = 0;
	for(List<Object> eachKeyList : keys)
	{
		String word = (String)eachKeyList.get(0);
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: key = %s", word);
		
		/* Transactional State Management behaviour :
		 * Check if word(key) is already present in Redis.
		 * If present
		 *      Check the txId and the wordCount value stored against the key.
		 * 		If the current txId is higher than the stored txId, 
		 * 			Then update the wordCount.
		 *  		Else, ignore the data in the current trxn
		 * If not present
		 *         Add the word as key and (trxId , wordCount) as the value.
		 * 
		 * */
		
		List<String> redisVal = lrange(word);
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: redisVal = %s", redisVal);
		
		Long redisTxId = -1L;
		Long redisWordCount = 0L;
		Long currentTxId = -1L;	//Get current trxn id from the input argument only - Check the implementation of TransactionalMap:multiPut.

		boolean redisKeyExists = false;
		if(redisVal != null && redisVal.size() > 0)
		{
			redisTxId = Long.parseLong(redisVal.get(0));
			redisWordCount = Long.parseLong(redisVal.get(1));
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: redisTxId = %d, redisWordCount = %d", redisTxId,redisWordCount);
			redisKeyExists = true;
			

		}
		else
		{
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: no entry in Redis yet for word = %s",word);

		}

		
		TransactionalValue<Long> curKeyVal = vals.get(curIndex);
		currentTxId = curKeyVal.getTxid();
		Long wordCount = curKeyVal.getVal();
		CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: currentTxId = %d, wordCount = %d", currentTxId, wordCount);
		
		if(currentTxId != redisTxId && currentTxId > redisTxId)//Latest trxn id numbers will always be higher than previous ones.
		{
			Long latestWordCount = redisWordCount + wordCount;
			CommonUtil.logMessage(logger, Thread.currentThread().getName(), "multiPut: latestWordCount = %d", latestWordCount);
			
			if(!redisKeyExists) //first time insert happening for a key
			{
				rpush(word, currentTxId+"", latestWordCount+"");
			}
			else//first pop out the old values and insert new values.
			{
				lpop(word, 2);
				rpush(word, currentTxId+"", latestWordCount+"");
				
			}
				
		}
		
		curIndex++;	

	}

	
}
 
开发者ID:BinitaBharati,项目名称:storm-trident-example,代码行数:78,代码来源:RedisStoreIBackingMap.java


注:本文中的storm.trident.state.TransactionalValue.getVal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。