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

时间:2025-02-12 14:58:47

代码样例

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

/**     * {@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/devg3-mrs/mrs_07_210013.html