Revision 49218
Added by Claudio Atzori over 6 years ago
MindistSearchMapper.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
5 | 7 |
import org.apache.hadoop.io.Text; |
6 | 8 |
import org.apache.hadoop.mapreduce.Mapper; |
7 | 9 |
|
... | ... | |
10 | 12 |
*/ |
11 | 13 |
public class MindistSearchMapper extends Mapper<Text, VertexWritable, Text, VertexWritable> { |
12 | 14 |
|
15 |
private static final Log log = LogFactory.getLog(MindistSearchMapper.class); |
|
16 |
|
|
17 |
private boolean debug = false; |
|
18 |
|
|
13 | 19 |
@Override |
20 |
protected void setup(Mapper.Context context) throws IOException, InterruptedException { |
|
21 |
super.setup(context); |
|
22 |
|
|
23 |
debug = context.getConfiguration().getBoolean("mindist_DEBUG", false); |
|
24 |
log.info("debug mode: " + debug); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
14 | 28 |
protected void map(Text key, VertexWritable value, Context context) throws IOException, InterruptedException { |
15 | 29 |
|
16 |
context.write(key, value);
|
|
30 |
emit(key, value, context);
|
|
17 | 31 |
if (value.isActivated()) { |
18 |
VertexWritable writable = new VertexWritable();
|
|
19 |
for (Text neighborVertex : value.getEdges()) {
|
|
20 |
if (!neighborVertex.toString().equals(value.getVertexId().toString())) {
|
|
21 |
writable.setVertexId(value.getVertexId());
|
|
22 |
writable.setEdges(null);
|
|
23 |
context.write(neighborVertex, writable);
|
|
32 |
VertexWritable vertex = new VertexWritable();
|
|
33 |
for (Text edge : value.getEdges()) {
|
|
34 |
if (!edge.toString().equals(value.getVertexId().toString())) {
|
|
35 |
vertex.setVertexId(value.getVertexId());
|
|
36 |
vertex.setEdges(null);
|
|
37 |
emit(edge, vertex, context);
|
|
24 | 38 |
} |
25 | 39 |
} |
26 | 40 |
} |
27 | 41 |
} |
28 | 42 |
|
43 |
private void emit(final Text key, final VertexWritable vertex, final Context context) throws IOException, InterruptedException { |
|
44 |
context.write(key, vertex); |
|
45 |
if (debug) { |
|
46 |
log.info(vertex.toJSON()); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
29 | 50 |
} |
Also available in: Unified diff
skip weird cases in CC algo