本文整理匯總了Java中backtype.storm.tuple.Tuple.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java Tuple.getString方法的具體用法?Java Tuple.getString怎麽用?Java Tuple.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類backtype.storm.tuple.Tuple
的用法示例。
在下文中一共展示了Tuple.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple tuple) {
// todo 寫注釋
String message = tuple.getString(0);
// to avoid NullPointerException
if (message != null) {
String domain, service, timestamp;
HashMap map = makeMapOfMessage(message);
domain = (String) map.get("domain");
LOG.info("domain name of message {} is {}", tuple.getMessageId(), domain);
timestamp = (String) map.get("time_local");
LOG.info("timestamp of message {} is {}", tuple.getMessageId(), timestamp);
if (domain.endsWith(ServerConfig.getUrlSuffix())) {
service = domain.split("\\.")[0];
collector.emit(tuple, new Values(timestamp, message, service));
collector.ack(tuple);
}
}
}
示例2: 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));
}
}
}
}
}
示例3: 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));
}
示例4: 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));
}
}
}
示例5: 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);
}
示例6: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple input) {
LOG.info("About to process tuple[" + input + "]");
List<Property> properties = new ArrayList<Property>();
TruliaParser tp = new TruliaParser();
// Process tuple by splitting into individual rows
String rssfeed = input.getString(0);
properties = tp.processRSS(rssfeed);
for(Property prop : properties) {
outputCollector.emit(new Values(prop.getTitle(),
prop.getLink(),
prop.getDescription(),
prop.getPubDate(),
prop.getThumbnail()));
}
outputCollector.ack(input);
}
示例7: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
try {
String url = input.getString(0);
if(url.length() > 10) {
collector.emit(new Values(url));
System.out.println(url);
}else{
System.err.println("======>loop back====>"+url);
}
}catch (Exception ex){
logger.error("Generate Url error:"+ex);
ex.printStackTrace();
}
}
示例8: 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));
}
}
}
示例9: 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);
}
}
示例10: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
String valueByField = input.getString(0);
System.out.println("field value "+ valueByField);
String[] split = valueByField.split(",");
PacketDetailDTO tdrPacketDetailDTO = new PacketDetailDTO();
tdrPacketDetailDTO.setPhoneNumber(Long.parseLong(split[0]));
tdrPacketDetailDTO.setBin(Integer.parseInt(split[1]));
tdrPacketDetailDTO.setBout(Integer.parseInt(split[2]));
tdrPacketDetailDTO.setTimestamp(Long.parseLong(split[3]));
collector.emit("tdrstream", new Values(tdrPacketDetailDTO));
}
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:14,代碼來源:ParserBolt.java
示例11: 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(word, count));
}
示例12: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple tuple) {
String sentence = tuple.getString(0);
for (String word : sentence.split("\\s+")) {
collector.emit(new Values(word));
}
collector.ack(tuple);
}
示例13: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple input) {
try {
String result = input.getString(0);
System.out.println(result+"---");
_collector.ack(input);
}catch (Exception ex){
ex.printStackTrace();
}
}
示例14: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple input) {
try {
String result = input.getString(0);
Thread.sleep(30000);
_collector.emit(input, new Values(result));
_collector.ack(input);
}catch (Exception ex){
ex.printStackTrace();
}
}
示例15: execute
import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple input, BasicOutputCollector collector) {
LOGGER.debug("removing stop words");
Long id = input.getLong(input.fieldIndex("tweet_id"));
String text = input.getString(input.fieldIndex("tweet_text"));
List<String> stopWords = StopWords.getWords();
for (String word : stopWords) {
text = text.replaceAll("\\b" + word + "\\b", "");
}
collector.emit(new Values(id, text));
}