當前位置: 首頁>>代碼示例>>Java>>正文


Java Tuple.getLongByField方法代碼示例

本文整理匯總了Java中backtype.storm.tuple.Tuple.getLongByField方法的典型用法代碼示例。如果您正苦於以下問題:Java Tuple.getLongByField方法的具體用法?Java Tuple.getLongByField怎麽用?Java Tuple.getLongByField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在backtype.storm.tuple.Tuple的用法示例。


在下文中一共展示了Tuple.getLongByField方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple tuple) {
	String subreddit = tuple.getStringByField("subreddit");
	String storyId = tuple.getStringByField("storyid");
	String storyURL = tuple.getStringByField("storyurl");
	String storyTitle = tuple.getStringByField("storytitle");
	String commentId = tuple.getStringByField("commentid");
	String comment = tuple.getStringByField("comment");
	long timestamp = tuple.getLongByField("timestamp");
	
	LOG.info("Received {}:{}:{}:{}:{}:[{}]", subreddit, storyId, storyURL, storyTitle, commentId, comment);
	
	String[] tokens = comment.split("\\s+");
	int sentimentScore = 0;
	for (String t  : tokens) {
		if (t == null || t.isEmpty()) {
			continue;
		}
		Long value = sentimentData.get(t);
		if (value != null) {
			sentimentScore += value;
		}
	}
	collector.emit(tuple, new Values(subreddit, storyId, storyURL, storyTitle, 
			commentId, comment, sentimentScore, timestamp));
	LOG.info("Emit {}:{}:{}:{}:{}:{}:[{}]", subreddit, sentimentScore, storyId, storyURL, 
			storyTitle, commentId, comment);
	
	collector.ack(tuple);
}
 
開發者ID:pathbreak,項目名稱:reddit-sentiment-storm,代碼行數:30,代碼來源:SentimentCalculatorBolt.java

示例2: execute

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple tuple) {
	String subreddit = tuple.getStringByField("subreddit");
	String storyId = tuple.getStringByField("storyid");
	String storyURL = tuple.getStringByField("storyurl");
	String storyTitle = tuple.getStringByField("storytitle");
	String commentId = tuple.getStringByField("commentid");
	String comment = tuple.getStringByField("comment");
	int sentimentScore = tuple.getIntegerByField("score");
	long timestamp = tuple.getLongByField("timestamp");

	LOG.info("Received {}:{}:{}:{}:{}:{}:[{}]", subreddit, sentimentScore, storyId, storyURL, 
			storyTitle, commentId, comment);
	
	collector.ack(tuple);
	
	summary.update(subreddit, storyId, storyURL, storyTitle, commentId,
			comment, sentimentScore, timestamp);
	
	// Publish updated statistics only every 30 secs.
	long curTime = System.currentTimeMillis();
	if (lastPublishedTimestamp == 0 ) {
		// Since messages come one by one to Summarizer, publishing immediately on first message
		// will show just 1 comment and looks odd. Instead, mark now as last published time
		// so that by next publishing window, we'd have received a couple of comments to show meaningful
		// rankings.
		lastPublishedTimestamp = curTime;
		
	} else if (curTime - lastPublishedTimestamp > 30000) {
		
		LOG.info("Publishing statistics to ZK");
		this.publisher.publish(summary);
		lastPublishedTimestamp = curTime;
	}
}
 
開發者ID:pathbreak,項目名稱:reddit-sentiment-storm,代碼行數:35,代碼來源:SummarizerBolt.java

示例3: execute

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple tuple) {
	Long timestamp = tuple.getLongByField("timestamp");
	String channel = CodeEncodeTool.encoding(tuple.getStringByField("channel"));
	String code = tuple.getStringByField("code");
	double num = tuple.getDoubleByField("num");
	double ratio = tuple.getDoubleByField("ratio");
	Map<String, String> tags = new HashMap<String, String>();
	tags.put("code", code);
	tags.put("channel", channel);

	JSONObject jsonCount = new JSONObject();
	jsonCount.put("metric", tsdbCountMetric);
	jsonCount.put("timestamp", timestamp);
	jsonCount.put("value", num);
	jsonCount.put("tags", tags);
	JSONObject jsonRatio = new JSONObject();
	jsonRatio.put("metric", tsdbRatioMetric);
	jsonRatio.put("timestamp", timestamp);
	jsonRatio.put("value", ratio);
	jsonRatio.put("tags", tags);
	List<JSONObject> jsonBatch = new ArrayList<JSONObject>();
	jsonBatch.add(jsonCount);
	jsonBatch.add(jsonRatio);

	// future : cache date and send by batch
	this.writeTsdb(post, jsonBatch);
}
 
開發者ID:zhai3516,項目名稱:storm-demos,代碼行數:28,代碼來源:WriteOpenTSDBBolt.java


注:本文中的backtype.storm.tuple.Tuple.getLongByField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。