KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > mapReduce > MapReduceJob


1 /* Copyright (c) 2005 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.mapReduce;
5
6 import java.io.IOException JavaDoc;
7 import java.io.File JavaDoc;
8
9 /** Specifies a map/reduce job. This names the {@link Mapper}, combiner (if
10  * any), {@link Partitioner}, {@link Reducer}, {@link InputFormat}, and {@link
11  * OutputFormat} implementations to be used. It also indicates the set of
12  * input files, and where the output files should be written.
13  */

14 public class MapReduceJob {
15   private File JavaDoc[] inputFiles;
16   private InputFormat inputFormat;
17   
18   private File JavaDoc outputBase;
19   private OutputFormat outputFormat;
20   
21   private Class JavaDoc mapperClass = DefaultMapper.class;
22   private Class JavaDoc partitionerClass = DefaultPartitioner.class;
23   private Class JavaDoc reducerClass = DefaultReducer.class;
24   private Class JavaDoc combinerClass = null;
25   
26   private int numMapTasks = 10;
27   private int numReduceTasks = 10;
28
29   /** Constructs a map/reduce job.
30    *
31    * @param inputBase the base name for input file enumeration
32    * @param inputFormat the name of the input file format
33    * @param outputBase the base name for output file name generation
34    * @param outputFormat the name of the output file format
35    */

36   public MapReduceJob(File JavaDoc inputBase, String JavaDoc inputFormat,
37                       File JavaDoc outputBase, String JavaDoc outputFormat)
38     throws IOException JavaDoc {
39
40     throw new RuntimeException JavaDoc("not yet implemented");
41   }
42
43   /** Set the {@link Mapper} class. */
44   public void setMapper(Class JavaDoc mapperClass) {
45     if (!Mapper.class.isAssignableFrom(mapperClass))
46       throw new IllegalArgumentException JavaDoc(mapperClass+" not a Mapper");
47     this.mapperClass = mapperClass;
48   }
49
50   /** Set the {@link Reducer} class. */
51   public void setReducer(Class JavaDoc reducerClass) {
52     if (!Reducer.class.isAssignableFrom(reducerClass))
53       throw new IllegalArgumentException JavaDoc(reducerClass+" not a Reducer");
54     this.reducerClass = reducerClass;
55   }
56
57   /** Set the {@link Partitioner} class. */
58   public void setPartitioner(Class JavaDoc partitionerClass) {
59     if (!Partitioner.class.isAssignableFrom(partitionerClass))
60       throw new IllegalArgumentException JavaDoc(partitionerClass+" not a Partitioner");
61     this.partitionerClass = partitionerClass;
62   }
63
64   /** Set the combiner class, if any, to a {@link Reducer}. A combiner can be
65    * specified to optimize the system. This is appropriate when the {@link
66    * Reducer} is commutative and associative. The combiner is used to
67    * partially reduce intermediate values prior to invoking the {@link
68    * Reducer}.
69    */

70   public void setCombiner(Class JavaDoc combinerClass) {
71     if (!Reducer.class.isAssignableFrom(combinerClass))
72       throw new IllegalArgumentException JavaDoc(combinerClass+" not a Reducer");
73     this.combinerClass = combinerClass;
74   }
75
76   /** Set the desired number of map tasks to be executed.*/
77   public void setNumMapTasks(int numMapTasks) {
78     this.numMapTasks = numMapTasks;
79   }
80
81   /** Set the desired number of reduce tasks to be executed.*/
82   public void setNumReduceTasks(int numReduceTasks) {
83     this.numReduceTasks = numReduceTasks;
84   }
85
86 }
87
88
Popular Tags