/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hadoop.mapred.pipes;

import java.io.IOException;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

/**
 * The interface for the messages that can come up from the child. All of these
 * calls are asynchronous and return before the message has been processed.
 */
interface UpwardProtocol {
  /**
   * Output a record from the child.
   * @param key the record's key
   * @param value the record's value
   * @throws IOException
   */
  void output(WritableComparable key, Writable value) throws IOException;
  
  /**
   * Map functions where the application has defined a partition function
   * output records along with their partition.
   * @param reduce the reduce to send this record to
   * @param key the record's key
   * @param value the record's value
   * @throws IOException
   */
  void partitionedOutput(int reduce, WritableComparable key, 
                         Writable value) throws IOException;
  
  /**
   * Update the task's status message
   * @param msg the string to display to the user
   * @throws IOException
   */
  void status(String msg) throws IOException;
  
  /**
   * Report making progress (and the current progress)
   * @param progress the current progress (0.0 to 1.0)
   * @throws IOException
   */
  void progress(float progress) throws IOException;
  
  /**
   * Report that the application has finished processing all inputs 
   * successfully.
   * @throws IOException
   */
  void done() throws IOException;
  
  /**
   * Report that the application or more likely communication failed.
   * @param e
   */
  void failed(Throwable e);
}
