本文整理匯總了Java中backtype.storm.tuple.Tuple.getStringByField方法的典型用法代碼示例。如果您正苦於以下問題:Java Tuple.getStringByField方法的具體用法?Java Tuple.getStringByField怎麽用?Java Tuple.getStringByField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類backtype.storm.tuple.Tuple
的用法示例。
在下文中一共展示了Tuple.getStringByField方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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(input.getStringByField("map"),new TypeReference<Map<String, Object>>() {});
this.userexecute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: 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();
}
}
}
示例3: 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("----------------------------------------");
}
示例4: 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);
}
示例5: 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;
}
}
示例6: 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);
}
示例7: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple tuple) {
String tick = tuple.getStringByField("tick");
String[] parts = tick.split(",");
outputCollector.emit(new Values(parts[0], parts[4]));
outputCollector.ack(tuple);
}
示例8: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple tuple) {
// 其中的field就是剛才outputDeclarer中定義的
String timestamp = tuple.getStringByField("timestamp");
String message = tuple.getStringByField("message");
String service = tuple.getStringByField("service");
try {
String[] fields = message.split(ServerConfig.getFieldSeparator());
StringBuilder stringBuilder = new StringBuilder();
for (String field : fields) {
if (field != null) {
String[] pair = field.split(ServerConfig.getPairSeparator(), 2);
stringBuilder.append(pair[1]).append(SPLITTER);
}
}
stringBuilder.append(service);
collector.emit(tuple, new Values(timestamp, stringBuilder.toString()));
collector.ack(tuple);
} catch (ArrayIndexOutOfBoundsException e) {
collector.fail(tuple);
e.printStackTrace();
}
}
示例9: saveMaps
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
private boolean saveMaps(Tuple tuple) {
/**
* this method save the last 5min info to two maps
* hbaseMap : {channel-code : {device:count}}
* openstdb_map : {channel-timestamp-code: [count,total]}
*/
//save hbase map
// TODO: Use stringbuilder
String hbaseRowKey = tuple.getStringByField("channel") + "#" + this.timestamp + "#" + tuple.getStringByField("code");//row-key
String colKey = tuple.getStringByField("device");//column-key : device
String colValue = tuple.getStringByField("count") +"#"+tuple.getStringByField("total")+"#"+tuple.getStringByField("ratio");// value :count # tot
Map<String, String> colMap;//hbase-column-map { "devices":"count#total#ratio"}
if(this.hbaseMap.containsKey(hbaseRowKey))
colMap = this.hbaseMap.get(hbaseRowKey);
else
colMap = new HashMap<String,String>();
colMap.put(colKey, colValue);
//keep top ten devices in hbaseMap,remove the min count device-key
if(colMap.size()>10){
int minCount = 99999999;
String minKey = "imp-min";
for (String key : colMap.keySet()){
int deviceCount = Integer.valueOf(colMap.get(key).split("#")[0]);
if(deviceCount < minCount)
minKey = key;
}
colMap.remove(minKey);
}
this.hbaseMap.put(hbaseRowKey, colMap);
//save opentsdb map
String tsdbKey = tuple.getStringByField("channel") + "#" +tuple.getStringByField("code")
+ "#" + this.timestamp;//key : channel-timestamp-code
long values = Long.valueOf(tuple.getStringByField("count"));// value list :this code count # all code count
if (this.tsdbMap.containsKey(tsdbKey)){
long lastValues = this.tsdbMap.get(tsdbKey);
values += lastValues;//count
}
this.tsdbMap.put(tsdbKey, values);
//save channel total count
String code = tuple.getStringByField("code");
if (code.contains("xx") && code != "9xx"){
String channelKey = tuple.getStringByField("channel");
Long count = this.channelCountMap.get(channelKey);
long value = Integer.valueOf(tuple.getStringByField("count"));
if (count == null){
count = value;
} else {
count += value;
}
this.channelCountMap.put(channelKey, count);
}
return true;
}
示例10: makeDefaultPath
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public static String makeDefaultPath(Tuple tuple, String topologyName) {
String timestamp = tuple.getStringByField("timestamp");
LOG.info("timestamp => {}", timestamp);
DateTime dateTime = new DateTime(timestamp);
String dayPath = dateTime.getDayWithYearAndMonth();
LOG.info("dayPath => {}", dayPath);
String hour = dateTime.getHour();
LOG.info("hour => {}", hour);
String path = Path.SEPARATOR + topologyName + Path.SEPARATOR + dayPath + Path.SEPARATOR + hour;
LOG.info("{}'s HDFS write directory is {}", topologyName, path);
return path;
}