001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.mapreduce;
020
021import java.io.IOException;
022import java.util.Iterator;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026
027/**
028 * The context passed to the {@link Reducer}.
029 * @param <KEYIN> the class of the input keys
030 * @param <VALUEIN> the class of the input values
031 * @param <KEYOUT> the class of the output keys
032 * @param <VALUEOUT> the class of the output values
033 */
034@InterfaceAudience.Public
035@InterfaceStability.Evolving
036public interface ReduceContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
037    extends TaskInputOutputContext<KEYIN,VALUEIN,KEYOUT,VALUEOUT> {
038
039  /** Start processing next unique key. */
040  public boolean nextKey() throws IOException,InterruptedException;
041
042  /**
043   * Iterate through the values for the current key, reusing the same value 
044   * object, which is stored in the context.
045   * @return the series of values associated with the current key. All of the 
046   * objects returned directly and indirectly from this method are reused.
047   */
048  public Iterable<VALUEIN> getValues() throws IOException, InterruptedException;
049
050  /**
051   * {@link Iterator} to iterate over values for a given group of records.
052   */
053  interface ValueIterator<VALUEIN> extends MarkableIteratorInterface<VALUEIN> {
054
055    /**
056     * This method is called when the reducer moves from one key to 
057     * another.
058     * @throws IOException
059     */
060    void resetBackupStore() throws IOException;
061  }
062}