本文整理汇总了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);
}
}
}
示例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++;
}
}
示例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++;
}
}