source: proiecte/HadoopJUnit/hadoop-0.20.1/src/mapred/org/apache/hadoop/mapreduce/TaskInputOutputContext.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 3.3 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.mapreduce;
20
21import java.io.IOException;
22
23import org.apache.hadoop.conf.Configuration;
24import org.apache.hadoop.util.Progressable;
25
26/**
27 * A context object that allows input and output from the task. It is only
28 * supplied to the {@link Mapper} or {@link Reducer}.
29 * @param <KEYIN> the input key type for the task
30 * @param <VALUEIN> the input value type for the task
31 * @param <KEYOUT> the output key type for the task
32 * @param <VALUEOUT> the output value type for the task
33 */
34public abstract class TaskInputOutputContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> 
35       extends TaskAttemptContext implements Progressable {
36  private RecordWriter<KEYOUT,VALUEOUT> output;
37  private StatusReporter reporter;
38  private OutputCommitter committer;
39
40  public TaskInputOutputContext(Configuration conf, TaskAttemptID taskid,
41                                RecordWriter<KEYOUT,VALUEOUT> output,
42                                OutputCommitter committer,
43                                StatusReporter reporter) {
44    super(conf, taskid);
45    this.output = output;
46    this.reporter = reporter;
47    this.committer = committer;
48  }
49
50  /**
51   * Advance to the next key, value pair, returning null if at end.
52   * @return the key object that was read into, or null if no more
53   */
54  public abstract 
55  boolean nextKeyValue() throws IOException, InterruptedException;
56 
57  /**
58   * Get the current key.
59   * @return the current key object or null if there isn't one
60   * @throws IOException
61   * @throws InterruptedException
62   */
63  public abstract 
64  KEYIN getCurrentKey() throws IOException, InterruptedException;
65
66  /**
67   * Get the current value.
68   * @return the value object that was read into
69   * @throws IOException
70   * @throws InterruptedException
71   */
72  public abstract VALUEIN getCurrentValue() throws IOException, 
73                                                   InterruptedException;
74
75  /**
76   * Generate an output key/value pair.
77   */
78  public void write(KEYOUT key, VALUEOUT value
79                    ) throws IOException, InterruptedException {
80    output.write(key, value);
81  }
82
83  public Counter getCounter(Enum<?> counterName) {
84    return reporter.getCounter(counterName);
85  }
86
87  public Counter getCounter(String groupName, String counterName) {
88    return reporter.getCounter(groupName, counterName);
89  }
90
91  @Override
92  public void progress() {
93    reporter.progress();
94  }
95
96  @Override
97  public void setStatus(String status) {
98    reporter.setStatus(status);
99  }
100 
101  public OutputCommitter getOutputCommitter() {
102    return committer;
103  }
104}
Note: See TracBrowser for help on using the repository browser.