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 
19 package org.apache.hadoop.mapred.pipes;
20 
21 import java.io.IOException;
22 
23 import org.apache.hadoop.io.Writable;
24 import org.apache.hadoop.io.WritableComparable;
25 import org.apache.hadoop.mapred.InputSplit;
26 import org.apache.hadoop.mapred.JobConf;
27 
28 /**
29  * The abstract description of the downward (from Java to C++) Pipes protocol.
30  * All of these calls are asynchronous and return before the message has been
31  * processed.
32  */
33 interface DownwardProtocol<K extends WritableComparable, V extends Writable> {
34   /**
35    * request authentication
36    * @throws IOException
37    */
authenticate(String digest, String challenge)38   void authenticate(String digest, String challenge) throws IOException;
39 
40   /**
41    * Start communication
42    * @throws IOException
43    */
start()44   void start() throws IOException;
45 
46   /**
47    * Set the JobConf for the task.
48    * @param conf
49    * @throws IOException
50    */
setJobConf(JobConf conf)51   void setJobConf(JobConf conf) throws IOException;
52 
53   /**
54    * Set the input types for Maps.
55    * @param keyType the name of the key's type
56    * @param valueType the name of the value's type
57    * @throws IOException
58    */
setInputTypes(String keyType, String valueType)59   void setInputTypes(String keyType, String valueType) throws IOException;
60 
61   /**
62    * Run a map task in the child.
63    * @param split The input split for this map.
64    * @param numReduces The number of reduces for this job.
65    * @param pipedInput Is the input coming from Java?
66    * @throws IOException
67    */
runMap(InputSplit split, int numReduces, boolean pipedInput)68   void runMap(InputSplit split, int numReduces,
69               boolean pipedInput) throws IOException;
70 
71   /**
72    * For maps with pipedInput, the key/value pairs are sent via this messaage.
73    * @param key The record's key
74    * @param value The record's value
75    * @throws IOException
76    */
mapItem(K key, V value)77   void mapItem(K key, V value) throws IOException;
78 
79   /**
80    * Run a reduce task in the child
81    * @param reduce the index of the reduce (0 .. numReduces - 1)
82    * @param pipedOutput is the output being sent to Java?
83    * @throws IOException
84    */
runReduce(int reduce, boolean pipedOutput)85   void runReduce(int reduce, boolean pipedOutput) throws IOException;
86 
87   /**
88    * The reduce should be given a new key
89    * @param key the new key
90    * @throws IOException
91    */
reduceKey(K key)92   void reduceKey(K key) throws IOException;
93 
94   /**
95    * The reduce should be given a new value
96    * @param value the new value
97    * @throws IOException
98    */
reduceValue(V value)99   void reduceValue(V value) throws IOException;
100 
101   /**
102    * The task has no more input coming, but it should finish processing it's
103    * input.
104    * @throws IOException
105    */
endOfInput()106   void endOfInput() throws IOException;
107 
108   /**
109    * The task should stop as soon as possible, because something has gone wrong.
110    * @throws IOException
111    */
abort()112   void abort() throws IOException;
113 
114   /**
115    * Flush the data through any buffers.
116    */
flush()117   void flush() throws IOException;
118 
119   /**
120    * Close the connection.
121    */
close()122   void close() throws IOException, InterruptedException;
123 }
124