Coverage Report - org.apache.giraph.comm.requests.SendWorkerDataRequest
 
Classes in this File Line Coverage Branch Coverage Complexity
SendWorkerDataRequest
0%
0/30
0%
0/6
1.5
 
 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.utils.VertexIdData;
 22  
 import org.apache.giraph.utils.PairList;
 23  
 import org.apache.hadoop.io.WritableComparable;
 24  
 import org.apache.log4j.Logger;
 25  
 
 26  
 import java.io.DataInput;
 27  
 import java.io.DataOutput;
 28  
 import java.io.IOException;
 29  
 
 30  
 /**
 31  
  * Abstract request to send a collection of data, indexed by vertex id,
 32  
  * for a partition.
 33  
  *
 34  
  * @param <I> Vertex id
 35  
  * @param <T> Data
 36  
  * @param <B> Specialization of
 37  
  * {@link org.apache.giraph.utils.VertexIdData} for T
 38  
  */
 39  
 @SuppressWarnings("unchecked")
 40  
 public abstract class SendWorkerDataRequest<I extends WritableComparable, T,
 41  
     B extends VertexIdData<I, T>>
 42  
     extends WritableRequest implements WorkerRequest {
 43  
   /** Class logger */
 44  0
   private static final Logger LOG =
 45  0
       Logger.getLogger(SendWorkerDataRequest.class);
 46  
   /**
 47  
    * All data for a group of vertices, organized by partition, which
 48  
    * are owned by a single (destination) worker. This data is all
 49  
    * destined for this worker.
 50  
    * */
 51  
   protected PairList<Integer, B> partitionVertexData;
 52  
 
 53  
   /**
 54  
    * Constructor used for reflection only
 55  
    */
 56  0
   public SendWorkerDataRequest() { }
 57  
 
 58  
   /**
 59  
    * Constructor used to send request.
 60  
    *
 61  
    * @param partVertData Map of remote partitions =&gt; VertexIdData
 62  
    */
 63  
   public SendWorkerDataRequest(
 64  0
       PairList<Integer, B> partVertData) {
 65  0
     this.partitionVertexData = partVertData;
 66  0
   }
 67  
 
 68  
   /**
 69  
    * Create a new {@link org.apache.giraph.utils.VertexIdData}
 70  
    * specialized for the use case.
 71  
    *
 72  
    * @return A new instance of
 73  
    * {@link org.apache.giraph.utils.VertexIdData}
 74  
    */
 75  
   public abstract B createVertexIdData();
 76  
 
 77  
   @Override
 78  
   public void readFieldsRequest(DataInput input) throws IOException {
 79  0
     int numPartitions = input.readInt();
 80  0
     partitionVertexData = new PairList<Integer, B>();
 81  0
     partitionVertexData.initialize(numPartitions);
 82  0
     while (numPartitions-- > 0) {
 83  0
       final int partitionId = input.readInt();
 84  0
       B vertexIdData = createVertexIdData();
 85  0
       vertexIdData.setConf(getConf());
 86  0
       vertexIdData.readFields(input);
 87  0
       partitionVertexData.add(partitionId, vertexIdData);
 88  0
     }
 89  0
   }
 90  
 
 91  
   @Override
 92  
   public void writeRequest(DataOutput output) throws IOException {
 93  0
     output.writeInt(partitionVertexData.getSize());
 94  
     PairList<Integer, B>.Iterator
 95  0
         iterator = partitionVertexData.getIterator();
 96  0
     while (iterator.hasNext()) {
 97  0
       iterator.next();
 98  0
       output.writeInt(iterator.getCurrentFirst());
 99  0
       iterator.getCurrentSecond().write(output);
 100  
     }
 101  0
   }
 102  
 
 103  
   @Override
 104  
   public int getSerializedSize() {
 105  0
     int size = super.getSerializedSize() + 4;
 106  0
     PairList<Integer, B>.Iterator iterator = partitionVertexData.getIterator();
 107  0
     while (iterator.hasNext()) {
 108  0
       iterator.next();
 109  0
       size += 4 + iterator.getCurrentSecond().getSerializedSize();
 110  
     }
 111  0
     return size;
 112  
   }
 113  
 }
 114