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


Java Tuple.getString方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:lovelock,項目名稱:storm-demo,代碼行數:23,代碼來源:CropBolt.java

示例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));
				}
			}
		}
	}
}
 
開發者ID:realxujiang,項目名稱:storm-kafka-examples,代碼行數:27,代碼來源:CheckOrderBolt.java

示例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));
}
 
開發者ID:mayconbordin,項目名稱:erad2016-streamprocessing,代碼行數:19,代碼來源:NegativeSentimentBolt.java

示例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));
        }
    }
}
 
開發者ID:srecon,項目名稱:ignite-book-code-samples,代碼行數:23,代碼來源:SplitSentence.java

示例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);
       
}
 
開發者ID:bucaojit,項目名稱:RealEstate-Streaming,代碼行數:21,代碼來源:PhoenixJDBC.java

示例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);
       
}
 
開發者ID:bucaojit,項目名稱:RealEstate-Streaming,代碼行數:23,代碼來源:RouteBolt.java

示例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();
        }
    }
 
開發者ID:cutoutsy,項目名稱:miner,代碼行數:17,代碼來源:GenerateUrlBolt.java

示例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));
    }
  }
}
 
開發者ID:mbad0la,項目名稱:Get-ENVS,代碼行數:23,代碼來源:SplitSentence.java

示例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);
    }
}
 
開發者ID:mayconbordin,項目名稱:erad2016-streamprocessing,代碼行數:27,代碼來源:TwitterFilterBolt.java

示例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));
}
 
開發者ID:mbad0la,項目名稱:Get-ENVS,代碼行數:15,代碼來源:WordCount.java

示例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);
}
 
開發者ID:yangliguang,項目名稱:preliminary.demo,代碼行數:8,代碼來源:SplitSentenceLocal.java

示例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();
    }
}
 
開發者ID:cutoutsy,項目名稱:miner,代碼行數:10,代碼來源:PrintBolt.java

示例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();
	}
}
 
開發者ID:cutoutsy,項目名稱:miner,代碼行數:11,代碼來源:ParseLoopBolt.java

示例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));
}
 
開發者ID:mayconbordin,項目名稱:erad2016-streamprocessing,代碼行數:15,代碼來源:StemmingBolt.java


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