Created
August 1, 2011 07:22
-
-
Save nathanmarz/1117720 to your computer and use it in GitHub Desktop.
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 class WordCount implements IBasicBolt { | |
private Map<String, Integer> _counts = new HashMap<String, Integer>(); | |
public void prepare(Map conf, TopologyContext context) { | |
} | |
public void execute(Tuple tuple, BasicOutputCollector collector) { | |
String word = tuple.getString(0); | |
int count; | |
if(_counts.containsKey(word)) { | |
count = _counts.get(word); | |
} else { | |
count = 0; | |
} | |
count++; | |
_counts.put(word, count); | |
collector.emit(new Values(word, count)); | |
} | |
public void cleanup() { | |
} | |
public void declareOutputFields(OutputFieldsDeclarer declarer) { | |
declarer.declare(new Fields("word", "count")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment