I changed the WordCount class in WordCountTopology as follows:
public static class WordCount extends BaseBasicBolt { Map<String, Integer> counts = new HashMap<String, Integer>(); @Override public void execute(Tuple tuple, BasicOutputCollector collector) { String word = tuple.getString(0); Integer count = counts.get(word); if(count==null) count = 0; count++; counts.put(word, count); OutputStream o; try { o = new FileOutputStream("~/abc.txt", true); o.write(word.getBytes()); o.close(); } catch (IOException e) {
in which I write the word in the file abc.txt .
When I launched WordCountTopology in local mode (which used LocalCluster ), it just works fine. But when working in distributed mode (which used the StormSubmitter.submitTopology() method), the WordCount class WordCount not write the word in abc.txt , as if the execute() method was not executed at all. Can someone give me some idea? Thank you very much!
PS I'm sure my nimbus, supervisor, ui, zookeeper is working fine, and I see the task at 127.0.0.1:8080.
source share