Created
September 19, 2011 19:47
-
-
Save apetresc/1227393 to your computer and use it in GitHub Desktop.
SplitSentence bolt in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SplitSentence implements IRichBolt { | |
private OutputCollector collector; | |
@Override | |
public void declareOutputFields(OutputFieldsDeclarer declarer) { | |
declarer.declare(new Fields("word")); | |
} | |
@Override | |
public void prepare(Map stormConf, TopologyContext context, | |
OutputCollector collector) { | |
this.collector = collector; | |
} | |
@Override | |
public void execute(Tuple input) { | |
String val = input.getString(0); | |
for (String word : val.split(" ")) { | |
collector.emit(input, new Values(word)); | |
} | |
collector.ack(input); | |
} | |
@Override | |
public void cleanup() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment