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.comm.ServerData;
22import org.apache.giraph.edge.Edge;
23import org.apache.giraph.utils.ByteArrayVertexIdEdges;
24import org.apache.giraph.utils.PairList;
25import org.apache.giraph.utils.VertexIdEdges;
26import org.apache.hadoop.io.Writable;
27import org.apache.hadoop.io.WritableComparable;
2829/**30 * Send a collection of edges for a partition.31 *32 * @param <I> Vertex id33 * @param <E> Edge data34 */35 @SuppressWarnings("unchecked")
36publicclass SendWorkerEdgesRequest<I extends WritableComparable,
37 E extends Writable>
38extends SendWorkerDataRequest<I, Edge<I, E>,
39 VertexIdEdges<I, E>> {
40/**41 * Constructor used for reflection only42 */43publicSendWorkerEdgesRequest() { }
4445/**46 * Constructor used to send request.47 *48 * @param partVertEdges Map of remote partitions =>49 * ByteArrayVertexIdEdges50 */51publicSendWorkerEdgesRequest(
52 PairList<Integer, VertexIdEdges<I, E>> partVertEdges) {
53this.partitionVertexData = partVertEdges;
54 }
5556 @Override
57public VertexIdEdges<I, E> createVertexIdData() {
58returnnew ByteArrayVertexIdEdges<>();
59 }
6061 @Override
62publicRequestType getType() {
63return RequestType.SEND_WORKER_EDGES_REQUEST;
64 }
6566 @Override
67publicvoid doRequest(ServerData serverData) {
68 PairList<Integer, VertexIdEdges<I, E>>.Iterator
69 iterator = partitionVertexData.getIterator();
70while (iterator.hasNext()) {
71 iterator.next();
72 serverData.getEdgeStore()
73 .addPartitionEdges(iterator.getCurrentFirst(),
74 iterator.getCurrentSecond());
75 }
76 }
77 }