title: mapreduce count example
body: <p>My question is about <code>mapreduce programming in java</code>. </p>
  
  <p>Suppose I have the WordCount.java example, a standard <code>mapreduce program</code>. I want the map function to collect some information, and return to the reduce function maps formed like: <code>&lt;slaveNode_id,some_info_collected&gt;</code>,</p>
  
  <p>so that <code>I can know what slave node collected what data</code>.. Any idea how?? </p>
  
  <pre><code>public class WordCount {
  
      public static class Map extends MapReduceBase implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
  
        public void map(LongWritable key, Text value, OutputCollector&lt;Text, IntWritable&gt; output, Reporter reporter) throws IOException {
          String line = value.toString();
          StringTokenizer tokenizer = new StringTokenizer(line);
          while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            output.collect(word, one);
          }
        }
      }
  
      public static class Reduce extends MapReduceBase implements Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
        public void reduce(Text key, Iterator&lt;IntWritable&gt; values, OutputCollector&lt;Text, IntWritable&gt; output, Reporter reporter) throws IOException {
          int sum = 0;
          while (values.hasNext()) {
            sum += values.next().get();
          }
          output.collect(key, new IntWritable(sum));
        }
      }
  
      public static void main(String[] args) throws Exception {
        JobConf conf = new JobConf(WordCount.class);
        conf.setJobName("wordcount");
  
        conf.setOutputKeyClass(Text.class);
        conf.setOutputValueClass(IntWritable.class);
  
        conf.setMapperClass(Map.class);
        conf.setCombinerClass(Reduce.class);
        conf.setReducerClass(Reduce.class);
  
        conf.setInputFormat(TextInputFormat.class);
        conf.setOutputFormat(TextOutputFormat.class);
  
        FileInputFormat.setInputPaths(conf, new Path(args[0]));
        FileOutputFormat.setOutputPath(conf, new Path(args[1]));
  
        JobClient.runJob(conf);
      }
  }
  </code></pre>
  
  <p>Thank you!!</p>