1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.comm.requests;
2021import org.apache.giraph.master.MasterGlobalCommHandler;
22import org.apache.giraph.partition.PartitionStats;
2324import java.io.DataInput;
25import java.io.DataOutput;
26import java.io.IOException;
27import java.util.ArrayList;
28import java.util.Collection;
29import java.util.List;
3031/**32 * Request for sending partition stats from workers to master33 */34publicclassPartitionStatsRequestextendsWritableRequest35implementsMasterRequest {
36/**Partition stats */37private List<PartitionStats> partitionStats;
3839/**40 * Constructor41 *42 * @param partitionStats Partition stats to send43 */44publicPartitionStatsRequest(Collection<PartitionStats> partitionStats) {
45this.partitionStats = new ArrayList<>(partitionStats);
46 }
4748/** Constructor for reflection */49publicPartitionStatsRequest() {
50 }
5152 @Override
53publicvoid doRequest(MasterGlobalCommHandler commHandler) {
54 commHandler.receivedPartitionStats(partitionStats);
55 }
5657 @Override
58publicRequestType getType() {
59return RequestType.PARTITION_STATS_REQUEST;
60 }
6162 @Override
63void writeRequest(DataOutput output) throws IOException {
64 output.writeInt(partitionStats.size());
65for (PartitionStats partitionStat : partitionStats) {
66 partitionStat.write(output);
67 }
68 }
6970 @Override
71void readFieldsRequest(DataInput input) throws IOException {
72int size = input.readInt();
73 partitionStats = new ArrayList<>(size);
74for (int i = 0; i < size; i++) {
75PartitionStats newPartitionStats = newPartitionStats();
76 newPartitionStats.readFields(input);
77 partitionStats.add(newPartitionStats);
78 }
79 }
80 }