1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.examples;
20
21 import org.apache.giraph.bsp.BspInputSplit;
22 import org.apache.giraph.conf.BooleanConfOption;
23 import org.apache.giraph.conf.LongConfOption;
24 import org.apache.giraph.io.VertexReader;
25 import org.apache.hadoop.io.Writable;
26 import org.apache.hadoop.io.WritableComparable;
27 import org.apache.hadoop.mapreduce.InputSplit;
28 import org.apache.hadoop.mapreduce.TaskAttemptContext;
29
30 import java.io.IOException;
31
32
33
34
35
36
37
38
39 @SuppressWarnings("rawtypes")
40 public abstract class GeneratedVertexReader<
41 I extends WritableComparable, V extends Writable,
42 E extends Writable>
43 extends VertexReader<I, V, E> {
44
45 public static final LongConfOption READER_VERTICES =
46 new LongConfOption("GeneratedVertexReader.reader_vertices", 10,
47 "Vertices produced by this reader");
48
49 public static final BooleanConfOption REVERSE_ID_ORDER =
50 new BooleanConfOption("GeneratedVertexReader.reverseIdOrder", false,
51 "Reverse the order of the vertices?");
52
53 protected long recordsRead = 0;
54
55 protected long totalRecords = 0;
56
57 protected BspInputSplit inputSplit = null;
58
59 protected boolean reverseIdOrder;
60
61
62
63
64 public GeneratedVertexReader() {
65 }
66
67 @Override
68 public final void initialize(InputSplit inputSplit,
69 TaskAttemptContext context) throws IOException {
70 totalRecords = GeneratedVertexReader.READER_VERTICES.get(getConf());
71 reverseIdOrder = GeneratedVertexReader.REVERSE_ID_ORDER.get(getConf());
72 this.inputSplit = (BspInputSplit) inputSplit;
73 }
74
75 @Override
76 public void close() throws IOException {
77 }
78
79 @Override
80 public final float getProgress() throws IOException {
81 return recordsRead * 100.0f / totalRecords;
82 }
83 }