1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.partition; |
20 | |
|
21 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
22 | |
import org.apache.giraph.graph.VertexValueCombiner; |
23 | |
import org.apache.giraph.utils.VertexIterator; |
24 | |
import org.apache.hadoop.io.Writable; |
25 | |
import org.apache.hadoop.io.WritableComparable; |
26 | |
import org.apache.hadoop.util.Progressable; |
27 | |
|
28 | |
import java.io.DataInput; |
29 | |
import java.io.DataOutput; |
30 | |
import java.io.IOException; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public abstract class BasicPartition<I extends WritableComparable, |
41 | |
V extends Writable, E extends Writable> |
42 | |
implements Partition<I, V, E> { |
43 | |
|
44 | |
private ImmutableClassesGiraphConfiguration<I, V, E> conf; |
45 | |
|
46 | |
private int id; |
47 | |
|
48 | |
private Progressable progressable; |
49 | |
|
50 | |
private VertexValueCombiner<V> vertexValueCombiner; |
51 | |
|
52 | |
@Override |
53 | |
public void initialize(int partitionId, Progressable progressable) { |
54 | 0 | setId(partitionId); |
55 | 0 | setProgressable(progressable); |
56 | 0 | vertexValueCombiner = conf.createVertexValueCombiner(); |
57 | 0 | } |
58 | |
|
59 | |
@Override |
60 | |
public void setConf( |
61 | |
ImmutableClassesGiraphConfiguration<I, V, E> configuration) { |
62 | 0 | conf = configuration; |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public ImmutableClassesGiraphConfiguration<I, V, E> getConf() { |
67 | 0 | return conf; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public int getId() { |
72 | 0 | return id; |
73 | |
} |
74 | |
|
75 | |
@Override |
76 | |
public void setId(int id) { |
77 | 0 | this.id = id; |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
public void progress() { |
82 | 0 | if (progressable != null) { |
83 | 0 | progressable.progress(); |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
@Override |
88 | |
public void setProgressable(Progressable progressable) { |
89 | 0 | this.progressable = progressable; |
90 | 0 | } |
91 | |
|
92 | |
public VertexValueCombiner<V> getVertexValueCombiner() { |
93 | 0 | return vertexValueCombiner; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
public void addPartitionVertices(VertexIterator<I, V, E> vertexIterator) { |
98 | 0 | while (vertexIterator.hasNext()) { |
99 | 0 | vertexIterator.next(); |
100 | |
|
101 | 0 | if (putOrCombine(vertexIterator.getVertex())) { |
102 | 0 | vertexIterator.releaseVertex(); |
103 | |
} |
104 | |
} |
105 | 0 | } |
106 | |
|
107 | |
@Override |
108 | |
public void write(DataOutput output) throws IOException { |
109 | 0 | output.writeInt(id); |
110 | 0 | } |
111 | |
|
112 | |
@Override |
113 | |
public void readFields(DataInput input) throws IOException { |
114 | 0 | id = input.readInt(); |
115 | 0 | } |
116 | |
} |