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.IOException; |
22 | |
|
23 | |
import org.apache.giraph.comm.GlobalCommType; |
24 | |
import org.apache.giraph.comm.ServerData; |
25 | |
import org.apache.giraph.comm.aggregators.AllAggregatorServerData; |
26 | |
import org.apache.giraph.utils.UnsafeByteArrayInputStream; |
27 | |
import org.apache.giraph.utils.WritableUtils; |
28 | |
import org.apache.hadoop.io.LongWritable; |
29 | |
import org.apache.hadoop.io.Writable; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class SendAggregatorsToWorkerRequest extends |
36 | |
ByteArrayWithSenderTaskIdRequest implements WorkerRequest { |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public SendAggregatorsToWorkerRequest(byte[] data, int senderTaskId) { |
45 | 0 | super(data, senderTaskId); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public SendAggregatorsToWorkerRequest() { |
52 | 0 | } |
53 | |
|
54 | |
@Override |
55 | |
public void doRequest(ServerData serverData) { |
56 | 0 | UnsafeByteArrayInputStream input = getUnsafeByteArrayInput(); |
57 | 0 | AllAggregatorServerData aggregatorData = serverData.getAllAggregatorData(); |
58 | |
try { |
59 | 0 | int num = input.readInt(); |
60 | 0 | for (int i = 0; i < num; i++) { |
61 | 0 | String name = input.readUTF(); |
62 | 0 | GlobalCommType type = GlobalCommType.values()[input.readByte()]; |
63 | 0 | Writable value = WritableUtils.readWritableObject(input, conf); |
64 | 0 | if (type == GlobalCommType.SPECIAL_COUNT) { |
65 | 0 | aggregatorData.receivedRequestCountFromWorker( |
66 | 0 | ((LongWritable) value).get(), |
67 | 0 | getSenderTaskId()); |
68 | |
} else { |
69 | 0 | aggregatorData.receiveValueFromMaster(name, type, value); |
70 | |
} |
71 | |
} |
72 | 0 | } catch (IOException e) { |
73 | 0 | throw new IllegalStateException("doRequest: " + |
74 | |
"IOException occurred while processing request", e); |
75 | 0 | } |
76 | 0 | aggregatorData.receivedRequestFromWorker(); |
77 | 0 | } |
78 | |
|
79 | |
@Override |
80 | |
public RequestType getType() { |
81 | 0 | return RequestType.SEND_AGGREGATORS_TO_WORKER_REQUEST; |
82 | |
} |
83 | |
} |