This project has retired. For details please refer to its Attic page.
SendVertexRequest 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.partition.Partition;
23  import org.apache.hadoop.io.Writable;
24  import org.apache.hadoop.io.WritableComparable;
25  import org.apache.log4j.Logger;
26  
27  import java.io.DataInput;
28  import java.io.DataOutput;
29  import java.io.IOException;
30  
31  /**
32   * Send a collection of vertices for a partition.  Note that this doesn't
33   * use a cache - might want to optimize in the future.
34   *
35   * @param <I> Vertex id
36   * @param <V> Vertex data
37   * @param <E> Edge data
38   */
39  @SuppressWarnings("rawtypes")
40  public class SendVertexRequest<I extends WritableComparable,
41      V extends Writable, E extends Writable> extends
42      WritableRequest<I, V, E> implements WorkerRequest<I, V, E> {
43    /** Class logger */
44    private static final Logger LOG =
45        Logger.getLogger(SendVertexRequest.class);
46    /** Partition */
47    private Partition<I, V, E> partition;
48  
49    /**
50     * Constructor used for reflection only
51     */
52    public SendVertexRequest() { }
53  
54    /**
55     * Constructor for sending a request.
56     *
57     * @param partition Partition to send the request to
58     */
59    public SendVertexRequest(Partition<I, V, E> partition) {
60      this.partition = partition;
61    }
62  
63    @Override
64    public void readFieldsRequest(DataInput input) throws IOException {
65      partition = getConf().createPartition(-1, null);
66      partition.readFields(input);
67    }
68  
69    @Override
70    public void writeRequest(DataOutput output) throws IOException {
71      partition.write(output);
72    }
73  
74    @Override
75    public RequestType getType() {
76      return RequestType.SEND_VERTEX_REQUEST;
77    }
78  
79    @Override
80    public void doRequest(ServerData<I, V, E> serverData) {
81      serverData.getPartitionStore().addPartition(partition);
82    }
83  
84    @Override
85    public int getSerializedSize() {
86      return WritableRequest.UNKNOWN_SIZE;
87    }
88  }
89