1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.comm.requests;
20
21 import java.io.DataInput;
22 import java.io.DataOutput;
23 import java.io.IOException;
24
25 import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable;
26 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
27 import org.apache.hadoop.io.Writable;
28 import org.apache.hadoop.io.WritableComparable;
29
30
31
32
33
34
35
36
37 public abstract class WritableRequest<I extends WritableComparable,
38 V extends Writable, E extends Writable> implements Writable,
39 ImmutableClassesGiraphConfigurable<I, V, E> {
40
41
42
43
44 public static final int UNKNOWN_SIZE = -1;
45
46
47 protected ImmutableClassesGiraphConfiguration<I, V, E> conf;
48
49 private int clientId = -1;
50
51 private long requestId = -1;
52
53 public int getClientId() {
54 return clientId;
55 }
56
57 public void setClientId(int clientId) {
58 this.clientId = clientId;
59 }
60
61 public long getRequestId() {
62 return requestId;
63 }
64
65 public void setRequestId(long requestId) {
66 this.requestId = requestId;
67 }
68
69
70
71
72
73
74
75
76
77
78 public int getSerializedSize() {
79
80 return 4 + 8;
81 }
82
83
84
85
86
87
88 public abstract RequestType getType();
89
90
91
92
93
94
95 abstract void readFieldsRequest(DataInput input) throws IOException;
96
97
98
99
100
101
102 abstract void writeRequest(DataOutput output) throws IOException;
103
104 @Override
105 public final ImmutableClassesGiraphConfiguration<I, V, E> getConf() {
106 return conf;
107 }
108
109 @Override
110 public final void setConf(ImmutableClassesGiraphConfiguration<I, V, E> conf) {
111 this.conf = conf;
112 }
113
114 @Override
115 public final void readFields(DataInput input) throws IOException {
116 clientId = input.readInt();
117 requestId = input.readLong();
118 readFieldsRequest(input);
119 }
120
121 @Override
122 public final void write(DataOutput output) throws IOException {
123 output.writeInt(clientId);
124 output.writeLong(requestId);
125 writeRequest(output);
126 }
127 }