This project has retired. For details please refer to its
Attic page.
BasicPartition xref
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 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 setId(partitionId);
55 setProgressable(progressable);
56 vertexValueCombiner = conf.createVertexValueCombiner();
57 }
58
59 @Override
60 public void setConf(
61 ImmutableClassesGiraphConfiguration<I, V, E> configuration) {
62 conf = configuration;
63 }
64
65 @Override
66 public ImmutableClassesGiraphConfiguration<I, V, E> getConf() {
67 return conf;
68 }
69
70 @Override
71 public int getId() {
72 return id;
73 }
74
75 @Override
76 public void setId(int id) {
77 this.id = id;
78 }
79
80 @Override
81 public void progress() {
82 if (progressable != null) {
83 progressable.progress();
84 }
85 }
86
87 @Override
88 public void setProgressable(Progressable progressable) {
89 this.progressable = progressable;
90 }
91
92 public VertexValueCombiner<V> getVertexValueCombiner() {
93 return vertexValueCombiner;
94 }
95
96 @Override
97 public void addPartitionVertices(VertexIterator<I, V, E> vertexIterator) {
98 while (vertexIterator.hasNext()) {
99 vertexIterator.next();
100
101 if (putOrCombine(vertexIterator.getVertex())) {
102 vertexIterator.releaseVertex();
103 }
104 }
105 }
106
107 @Override
108 public void write(DataOutput output) throws IOException {
109 output.writeInt(id);
110 }
111
112 @Override
113 public void readFields(DataInput input) throws IOException {
114 id = input.readInt();
115 }
116 }