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.utils.ByteArrayVertexIdMessages;
23import org.apache.giraph.utils.PairList;
24import org.apache.giraph.utils.VertexIdMessages;
25import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.io.WritableComparable;
2728/**29 * Send a collection of vertex messages for a partition.30 *31 * @param <I> Vertex id32 * @param <M> Message data33 */34 @SuppressWarnings("unchecked")
35publicclass SendWorkerMessagesRequest<I extends WritableComparable,
36 M extends Writable> extends SendWorkerDataRequest<I, M,
37 VertexIdMessages<I, M>> {
3839/** Default constructor */40publicSendWorkerMessagesRequest() {
41 }
4243/**44 * Constructor used to send request.45 *46 * @param partVertMsgs Map of remote partitions =>47 * VertexIdMessages48 */49publicSendWorkerMessagesRequest(
50 PairList<Integer, VertexIdMessages<I, M>> partVertMsgs) {
51this.partitionVertexData = partVertMsgs;
52 }
5354 @Override
55public VertexIdMessages<I, M> createVertexIdData() {
56returnnew ByteArrayVertexIdMessages<I, M>(
57 getConf().createOutgoingMessageValueFactory());
58 }
5960 @Override
61publicRequestType getType() {
62return RequestType.SEND_WORKER_MESSAGES_REQUEST;
63 }
6465 @Override
66publicvoid doRequest(ServerData serverData) {
67 PairList<Integer, VertexIdMessages<I, M>>.Iterator
68 iterator = partitionVertexData.getIterator();
69while (iterator.hasNext()) {
70 iterator.next();
71 serverData.getIncomingMessageStore().
72 addPartitionMessages(iterator.getCurrentFirst(),
73 iterator.getCurrentSecond());
74 }
75 }
76 }