本文整理匯總了Java中backtype.storm.tuple.Tuple類的典型用法代碼示例。如果您正苦於以下問題:Java Tuple類的具體用法?Java Tuple怎麽用?Java Tuple使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Tuple類屬於backtype.storm.tuple包,在下文中一共展示了Tuple類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public final void execute(Tuple input, BasicOutputCollector collector) {
_collector = collector;
if (isTickTuple(input)) {
tickTupleCase();
} else {
try {
this.rawJson = input.getStringByField("map");
this.json = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
this.userexecute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple tuple) {
this.saveMaps(tuple);
// TODO : Use a independent bolt to instead of this method
// This mechanism may lead to inaccurate if data is sparse
if(this.isNewTimeBucke(this.timestamp)){
logger.info("Crontab time: Emit maps !");
logger.info("Before clean , size is : " + this.tsdbMap.size() + "-" + this.hbaseMap.size() + "-"
+ this.channelCountMap.size());
long start = System.currentTimeMillis();
this.timestamp = System.currentTimeMillis()/1000/this.sendCheckFreq + 1;//save as next send timestamp
this.emitTsdbMap(ChannelTopology.OPENTSDB_STREAM,ChannelTopology.TRANSFER_STREAM,
this.collector, this.tsdbMap, this.channelCountMap);
this.emitHbaseMap(ChannelTopology.HBASE_STREAM, this.collector, this.hbaseMap);
this.channelCountMap.clear();
this.tsdbMap.clear();
this.hbaseMap.clear();
logger.info("After clean , size is : " + this.tsdbMap.size() + "-" + this.hbaseMap.size() + "-"
+ this.channelCountMap.size());
logger.info("clean maps successful cost : " + (System.currentTimeMillis()-start));
}
}
示例3: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//設置日期格式
String nowData = df.format(new Date()); // new Date()為獲取當前係統時間,檢測是否為最新數據
String data = tuple.getString(0);
//訂單號 用戶id 原金額 優惠價 標示字段 下單時間
//id memberid totalprice preprice sendpay createdate
if(data!=null && data.length()>0) {
String[] values = data.split("\t");
if(values.length==6) {
String id = values[0];
String memberid = values[1];
String totalprice = values[2];
String preprice = values[3];
String sendpay = values[4];
String createdate = values[5];
if(StringUtils.isNotEmpty(id)&&StringUtils.isNotEmpty(memberid)&&StringUtils.isNotEmpty(totalprice)) {
if(DateUtils.isValidDate(createdate, nowData)) {
collector.emit(new Values(id,memberid,totalprice,preprice,sendpay,createdate));
}
}
}
}
}
示例4: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
/**
* For each ticker in input stream, calculate the moving average.
*/
@Override
public void execute(Tuple tuple) {
String ticker = tuple.getStringByField("ticker");
String quote = tuple.getStringByField("price");
Double num = Double.parseDouble(quote);
LinkedList<Double> window = (LinkedList)getQuotesForTicker(ticker);
window.add(num);
// Print to System.out for test purposes. In a real implementation this
// would go to a downstream bolt for further processing, or persisted, etc.
System.out.println("----------------------------------------");
System.out.println("moving average for ticker " + ticker + "=" + getAvg(window));
System.out.println("----------------------------------------");
}
示例5: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple tuple) {
long startTime=System.currentTimeMillis();
String globalInfo = tuple.getString(0);
String data = tuple.getString(1);
try {
String workspace_id = get_workspace_id(globalInfo);
//利用redis來進行數據的去重
if(!jedis.sismember(workspace_id+"_unique", globalInfo)) {
//將數據存放進HBase
ImportData.importData(data);
logger.info(globalInfo + ":save into hbase succeed!");
jedis.sadd(workspace_id+"_unique", globalInfo);
_collector.ack(tuple);
}else{
logger.warn(globalInfo+":已經存進數據庫了.");
}
} catch (Exception ex) {
_collector.fail(tuple);
logger.error("store error!"+MySysLogger.formatException(ex));
ex.printStackTrace();
}
long endTime=System.currentTimeMillis();
logger.info(globalInfo+"在StoreBolt的處理時間:"+(endTime-startTime)/1000+"s.");
}
示例6: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
LOGGER.debug("Calculating positive score");
Long id = input.getLong(input.fieldIndex("tweet_id"));
String text = input.getString(input.fieldIndex("tweet_text"));
Set<String> posWords = PositiveWords.getWords();
String[] words = text.split(" ");
int numWords = words.length;
int numPosWords = 0;
for (String word : words) {
if (posWords.contains(word))
numPosWords++;
}
collector.emit(new Values(id, (float) numPosWords / numWords, text));
}
示例7: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
LOGGER.debug("filttering incoming tweets");
String json = input.getString(0);
try {
JsonNode root = mapper.readValue(json, JsonNode.class);
long id;
String text;
if (root.get("lang") != null && "en".equals(root.get("lang").textValue())) {
if (root.get("id") != null && root.get("text") != null) {
id = root.get("id").longValue();
text = root.get("text").textValue();
collector.emit(new Values(id, text));
} else {
LOGGER.debug("tweet id and/ or text was null");
}
} else {
LOGGER.debug("Ignoring non-english tweet");
}
} catch (IOException ex) {
LOGGER.error("IO error while filtering tweets", ex);
LOGGER.trace(null, ex);
}
}
示例8: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
Long id = input.getLong(input.fieldIndex("tweet_id"));
String tweet = input.getString(input.fieldIndex("tweet_text"));
Float pos = input.getFloat(input.fieldIndex("pos_score"));
Float neg = input.getFloat(input.fieldIndex("neg_score"));
String score = input.getString(input.fieldIndex("score"));
HttpPost post = new HttpPost(this.webserver);
String content = String.format(
"{\"id\": \"%d\", " +
"\"text\": \"%s\", " +
"\"pos\": \"%f\", " +
"\"neg\": \"%f\", " +
"\"score\": \"%s\" }",
id, tweet, pos, neg, score);
try {
post.setEntity(new StringEntity(content));
HttpResponse response = client.execute(post);
org.apache.http.util.EntityUtils.consume(response.getEntity());
} catch (Exception ex) {
LOGGER.error("exception thrown while attempting post", ex);
LOGGER.trace(null, ex);
reconnect();
}
}
示例9: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
LOGGER.debug("Calculating negitive score");
Long id = input.getLong(input.fieldIndex("tweet_id"));
String text = input.getString(input.fieldIndex("tweet_text"));
Set<String> negWords = NegativeWords.getWords();
String[] words = text.split(" ");
int numWords = words.length;
int numNegWords = 0;
for (String word : words) {
if (negWords.contains(word))
numNegWords++;
}
collector.emit(new Values(id, (float) numNegWords / numWords, text));
}
示例10: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
//Get the sentence content from the tuple
String sentence = tuple.getString(0);
//An iterator to get each word
BreakIterator boundary=BreakIterator.getWordInstance();
//Give the iterator the sentence
boundary.setText(sentence);
//Find the beginning first word
int start=boundary.first();
//Iterate over each word and emit it to the output stream
for (int end=boundary.next(); end != BreakIterator.DONE; start=end, end=boundary.next()) {
//get the word
String word=sentence.substring(start,end);
//If a word is whitespace characters, replace it with empty
word=word.replaceAll("\\s+","");
//if it's an actual word, emit it
if (!word.equals("")) {
collector.emit(new Values(word));
}
}
}
示例11: convert
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void convert(Object from, BytesArray to) {
Assert.isTrue(from == null || from instanceof Tuple,
String.format("Unexpected object type, expecting [%s], given [%s]", Tuple.class, from.getClass()));
// handle common cases
Tuple tuple = (Tuple) from;
if (tuple == null || tuple.size() == 0) {
to.bytes("{}");
return;
}
Assert.isTrue(tuple.size() == 1, "When using JSON input, only one field is expected");
super.convert(tuple.getValue(0), to);
}
示例12: extractField
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
protected Object extractField(Object target) {
List<String> fieldNames = getFieldNames();
for (int i = 0; i < fieldNames.size(); i++) {
String field = fieldNames.get(i);
if (target instanceof Tuple) {
target = ((Tuple) target).getValueByField(field);
if (target == null) {
return NOT_FOUND;
}
}
else {
return NOT_FOUND;
}
}
return target;
}
示例13: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void execute(Tuple input) {
// cleanup first to make sure the connection to ES is closed before the test suite shuts down
if (done) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Received tuple " + input);
}
if (TestSpout.DONE.equals(input.getValue(0))) {
delegate.cleanup();
done = true;
MultiIndexSpoutStormSuite.COMPONENT_HAS_COMPLETED.decrement();
}
if (!done) {
delegate.execute(input);
}
}
示例14: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void execute(Tuple input) {
LOG.info("About to process tuple[" + input + "]");
String sentence = input.getString(0);
String[] words = sentence.split(" ");
for(String word: words) {
word = word.trim();
if(!word.isEmpty()) {
word = word.toLowerCase();
outputCollector.emit(new Values(word));
}
}
outputCollector.ack(input);
}
示例15: execute
import backtype.storm.tuple.Tuple; //導入依賴的package包/類
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
//Get the word contents from the tuple
String word = tuple.getString(0);
//Have we counted any already?
Integer count = counts.get(word);
if (count == null)
count = 0;
//Increment the count and store it
count++;
counts.put(word, count);
//Emit the word and the current count
//collector.emit(new Values(IGNITE_FIELD, count));
TreeMap<String, Integer> words = new TreeMap<>();
words.put(word,count);
collector.emit(new Values(words));
//Log information
logger.info("Emitting a count of " + count + " for word " + word);
}