MAPREDUCE服务 MRS-创建Storm Spout:代码样例

时间:2024-06-19 14:14:18

代码样例

下面代码片段在com.huawei.storm.example.common.RandomSentenceSpout类中,作用在于将收到的字符串拆分成单词。

/**  
   * {@inheritDoc}  
   */  
  @Override  
  public void nextTuple()  
  {  
      Utils.sleep(100);  
      String[] sentences =  
          new String[] {"the cow jumped over the moon",   
                        "an apple a day keeps the doctor away",  
                        "four score and seven years ago",   
                        "snow white and the seven dwarfs",   
                        "i am at two with nature"};  
      String sentence = sentences[random.nextInt(sentences.length)];  
      collector.emit(new Values(sentence));  
  }
support.huaweicloud.com/devg-mrs/mrs_06_0275.html