This project has retired. For details please refer to its Attic page.
SendWorkerMessagesRequest xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.comm.requests;
20  
21  import org.apache.giraph.comm.ServerData;
22  import org.apache.giraph.utils.ByteArrayVertexIdMessages;
23  import org.apache.giraph.utils.PairList;
24  import org.apache.giraph.utils.VertexIdMessages;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.io.WritableComparable;
27  
28  /**
29   * Send a collection of vertex messages for a partition.
30   *
31   * @param <I> Vertex id
32   * @param <M> Message data
33   */
34  @SuppressWarnings("unchecked")
35  public class SendWorkerMessagesRequest<I extends WritableComparable,
36      M extends Writable> extends SendWorkerDataRequest<I, M,
37      VertexIdMessages<I, M>> {
38  
39    /** Default constructor */
40    public SendWorkerMessagesRequest() {
41    }
42  
43    /**
44     * Constructor used to send request.
45     *
46     * @param partVertMsgs Map of remote partitions =&gt;
47     *                     VertexIdMessages
48     */
49    public SendWorkerMessagesRequest(
50        PairList<Integer, VertexIdMessages<I, M>> partVertMsgs) {
51      this.partitionVertexData = partVertMsgs;
52    }
53  
54    @Override
55    public VertexIdMessages<I, M> createVertexIdData() {
56      return new ByteArrayVertexIdMessages<I, M>(
57          getConf().createOutgoingMessageValueFactory());
58    }
59  
60    @Override
61    public RequestType getType() {
62      return RequestType.SEND_WORKER_MESSAGES_REQUEST;
63    }
64  
65    @Override
66    public void doRequest(ServerData serverData) {
67      PairList<Integer, VertexIdMessages<I, M>>.Iterator
68          iterator = partitionVertexData.getIterator();
69      while (iterator.hasNext()) {
70        iterator.next();
71        serverData.getIncomingMessageStore().
72            addPartitionMessages(iterator.getCurrentFirst(),
73                iterator.getCurrentSecond());
74      }
75    }
76  }