1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.utils; |
20 | |
|
21 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
22 | |
import org.apache.hadoop.io.WritableComparable; |
23 | |
|
24 | |
import java.io.DataInput; |
25 | |
import java.io.DataOutput; |
26 | |
import java.io.IOException; |
27 | |
|
28 | |
import static org.apache.giraph.utils.ByteUtils.SIZE_OF_BYTE; |
29 | |
import static org.apache.giraph.utils.ByteUtils.SIZE_OF_INT; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | @SuppressWarnings("unchecked") |
38 | 0 | public abstract class AbstractVertexIdData<I extends WritableComparable, T> |
39 | |
implements VertexIdData<I, T> { |
40 | |
|
41 | |
protected ExtendedDataOutput extendedDataOutput; |
42 | |
|
43 | |
private ImmutableClassesGiraphConfiguration<I, ?, ?> configuration; |
44 | |
|
45 | |
@Override |
46 | |
public void initialize() { |
47 | 0 | extendedDataOutput = getConf().createExtendedDataOutput(); |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public void initialize(int expectedSize) { |
52 | 0 | extendedDataOutput = getConf().createExtendedDataOutput(expectedSize); |
53 | 0 | } |
54 | |
|
55 | |
@Override |
56 | |
public void add(I vertexId, T data) { |
57 | |
try { |
58 | 0 | vertexId.write(extendedDataOutput); |
59 | 0 | writeData(extendedDataOutput, data); |
60 | 0 | } catch (IOException e) { |
61 | 0 | throw new IllegalStateException("add: IOException", e); |
62 | 0 | } |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public void add(byte[] serializedId, int idPos, T data) { |
67 | |
try { |
68 | 0 | extendedDataOutput.write(serializedId, 0, idPos); |
69 | 0 | writeData(extendedDataOutput, data); |
70 | 0 | } catch (IOException e) { |
71 | 0 | throw new IllegalStateException("add: IOException", e); |
72 | 0 | } |
73 | 0 | } |
74 | |
|
75 | |
@Override |
76 | |
public int getSize() { |
77 | 0 | return extendedDataOutput.getPos(); |
78 | |
} |
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
public int getSerializedSize() { |
83 | 0 | return SIZE_OF_BYTE + SIZE_OF_INT + getSize(); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
@Override |
88 | |
public boolean isEmpty() { |
89 | 0 | return extendedDataOutput.getPos() == 0; |
90 | |
} |
91 | |
|
92 | |
|
93 | |
@Override |
94 | |
public void clear() { |
95 | 0 | extendedDataOutput.reset(); |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
public void setConf(ImmutableClassesGiraphConfiguration configuration) { |
100 | 0 | this.configuration = configuration; |
101 | 0 | } |
102 | |
|
103 | |
@Override |
104 | |
public ImmutableClassesGiraphConfiguration<I, ?, ?> getConf() { |
105 | 0 | return configuration; |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public ByteStructVertexIdDataIterator<I, T> getVertexIdDataIterator() { |
110 | 0 | return new ByteStructVertexIdDataIterator<>(this); |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public void write(DataOutput output) throws IOException { |
115 | 0 | throw new UnsupportedOperationException("not supported"); |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public void readFields(DataInput dataInput) throws IOException { |
120 | 0 | throw new UnsupportedOperationException("not supported"); |
121 | |
} |
122 | |
} |