This project has retired. For details please refer to its
Attic page.
AbstractVertexIdData xref
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 @SuppressWarnings("unchecked")
38 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 extendedDataOutput = getConf().createExtendedDataOutput();
48 }
49
50 @Override
51 public void initialize(int expectedSize) {
52 extendedDataOutput = getConf().createExtendedDataOutput(expectedSize);
53 }
54
55 @Override
56 public void add(I vertexId, T data) {
57 try {
58 vertexId.write(extendedDataOutput);
59 writeData(extendedDataOutput, data);
60 } catch (IOException e) {
61 throw new IllegalStateException("add: IOException", e);
62 }
63 }
64
65 @Override
66 public void add(byte[] serializedId, int idPos, T data) {
67 try {
68 extendedDataOutput.write(serializedId, 0, idPos);
69 writeData(extendedDataOutput, data);
70 } catch (IOException e) {
71 throw new IllegalStateException("add: IOException", e);
72 }
73 }
74
75 @Override
76 public int getSize() {
77 return extendedDataOutput.getPos();
78 }
79
80
81 @Override
82 public int getSerializedSize() {
83 return SIZE_OF_BYTE + SIZE_OF_INT + getSize();
84 }
85
86
87 @Override
88 public boolean isEmpty() {
89 return extendedDataOutput.getPos() == 0;
90 }
91
92
93 @Override
94 public void clear() {
95 extendedDataOutput.reset();
96 }
97
98 @Override
99 public void setConf(ImmutableClassesGiraphConfiguration configuration) {
100 this.configuration = configuration;
101 }
102
103 @Override
104 public ImmutableClassesGiraphConfiguration<I, ?, ?> getConf() {
105 return configuration;
106 }
107
108 @Override
109 public ByteStructVertexIdDataIterator<I, T> getVertexIdDataIterator() {
110 return new ByteStructVertexIdDataIterator<>(this);
111 }
112
113 @Override
114 public void write(DataOutput output) throws IOException {
115 throw new UnsupportedOperationException("not supported");
116 }
117
118 @Override
119 public void readFields(DataInput dataInput) throws IOException {
120 throw new UnsupportedOperationException("not supported");
121 }
122 }