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 | * Start communication |
---|
36 | * @throws IOException |
---|
37 | */ |
---|
38 | void start() throws IOException; |
---|
39 | |
---|
40 | /** |
---|
41 | * Set the JobConf for the task. |
---|
42 | * @param conf |
---|
43 | * @throws IOException |
---|
44 | */ |
---|
45 | void setJobConf(JobConf conf) throws IOException; |
---|
46 | |
---|
47 | /** |
---|
48 | * Set the input types for Maps. |
---|
49 | * @param keyType the name of the key's type |
---|
50 | * @param valueType the name of the value's type |
---|
51 | * @throws IOException |
---|
52 | */ |
---|
53 | void setInputTypes(String keyType, String valueType) throws IOException; |
---|
54 | |
---|
55 | /** |
---|
56 | * Run a map task in the child. |
---|
57 | * @param split The input split for this map. |
---|
58 | * @param numReduces The number of reduces for this job. |
---|
59 | * @param pipedInput Is the input coming from Java? |
---|
60 | * @throws IOException |
---|
61 | */ |
---|
62 | void runMap(InputSplit split, int numReduces, |
---|
63 | boolean pipedInput) throws IOException; |
---|
64 | |
---|
65 | /** |
---|
66 | * For maps with pipedInput, the key/value pairs are sent via this messaage. |
---|
67 | * @param key The record's key |
---|
68 | * @param value The record's value |
---|
69 | * @throws IOException |
---|
70 | */ |
---|
71 | void mapItem(K key, V value) throws IOException; |
---|
72 | |
---|
73 | /** |
---|
74 | * Run a reduce task in the child |
---|
75 | * @param reduce the index of the reduce (0 .. numReduces - 1) |
---|
76 | * @param pipedOutput is the output being sent to Java? |
---|
77 | * @throws IOException |
---|
78 | */ |
---|
79 | void runReduce(int reduce, boolean pipedOutput) throws IOException; |
---|
80 | |
---|
81 | /** |
---|
82 | * The reduce should be given a new key |
---|
83 | * @param key the new key |
---|
84 | * @throws IOException |
---|
85 | */ |
---|
86 | void reduceKey(K key) throws IOException; |
---|
87 | |
---|
88 | /** |
---|
89 | * The reduce should be given a new value |
---|
90 | * @param value the new value |
---|
91 | * @throws IOException |
---|
92 | */ |
---|
93 | void reduceValue(V value) throws IOException; |
---|
94 | |
---|
95 | /** |
---|
96 | * The task has no more input coming, but it should finish processing it's |
---|
97 | * input. |
---|
98 | * @throws IOException |
---|
99 | */ |
---|
100 | void endOfInput() throws IOException; |
---|
101 | |
---|
102 | /** |
---|
103 | * The task should stop as soon as possible, because something has gone wrong. |
---|
104 | * @throws IOException |
---|
105 | */ |
---|
106 | void abort() throws IOException; |
---|
107 | |
---|
108 | /** |
---|
109 | * Flush the data through any buffers. |
---|
110 | */ |
---|
111 | void flush() throws IOException; |
---|
112 | |
---|
113 | /** |
---|
114 | * Close the connection. |
---|
115 | */ |
---|
116 | void close() throws IOException, InterruptedException; |
---|
117 | } |
---|