Coverage Report - org.apache.giraph.block_app.reducers.collect.CollectShardedReducerHandle
 
Classes in this File Line Coverage Branch Coverage Complexity
CollectShardedReducerHandle
0%
0/11
0%
0/2
0
CollectShardedReducerHandle$CollectShardedBroadcastHandle
0%
0/8
0%
0/2
0
 
 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  
 package org.apache.giraph.block_app.reducers.collect;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.giraph.block_app.framework.api.CreateReducersApi;
 24  
 import org.apache.giraph.block_app.framework.piece.global_comm.BroadcastHandle;
 25  
 import org.apache.giraph.block_app.framework.piece.global_comm.array.BroadcastArrayHandle;
 26  
 import org.apache.giraph.master.MasterGlobalCommUsage;
 27  
 import org.apache.giraph.reducers.ReduceOperation;
 28  
 import org.apache.giraph.worker.WorkerBroadcastUsage;
 29  
 import org.apache.giraph.writable.kryo.KryoWritableWrapper;
 30  
 
 31  
 /**
 32  
  * ShardedReducerHandle where we keep a list of reduced values
 33  
  *
 34  
  * @param <S> Single value type
 35  
  */
 36  0
 public class CollectShardedReducerHandle<S>
 37  
     extends ShardedReducerHandle<S, List<S>> {
 38  0
   public CollectShardedReducerHandle(CreateReducersApi reduceApi) {
 39  0
     register(reduceApi);
 40  0
   }
 41  
 
 42  
   @Override
 43  
   public ReduceOperation<S, KryoWritableWrapper<List<S>>>
 44  
   createReduceOperation() {
 45  0
     return new CollectReduceOperation<>();
 46  
   }
 47  
 
 48  
   @Override
 49  
   public List<S> createReduceResult(MasterGlobalCommUsage master) {
 50  0
     int size = 0;
 51  0
     for (int i = 0; i < REDUCER_COUNT; i++) {
 52  0
       size += reducers.get(i).getReducedValue(master).get().size();
 53  
     }
 54  0
     return createList(size);
 55  
   }
 56  
 
 57  
   public List<S> createList(int size) {
 58  0
     return new ArrayList<S>(size);
 59  
   }
 60  
 
 61  
   @Override
 62  
   public BroadcastHandle<List<S>> createBroadcastHandle(
 63  
       BroadcastArrayHandle<KryoWritableWrapper<List<S>>> broadcasts) {
 64  0
     return new CollectShardedBroadcastHandle(broadcasts);
 65  
   }
 66  
 
 67  
   /**
 68  
    * BroadcastHandle for CollectShardedReducerHandle
 69  
    */
 70  0
   public class CollectShardedBroadcastHandle extends ShardedBroadcastHandle {
 71  
     public CollectShardedBroadcastHandle(
 72  0
         BroadcastArrayHandle<KryoWritableWrapper<List<S>>> broadcasts) {
 73  0
       super(broadcasts);
 74  0
     }
 75  
 
 76  
     @Override
 77  
     public List<S> createBroadcastResult(WorkerBroadcastUsage worker) {
 78  0
       int size = 0;
 79  0
       for (int i = 0; i < REDUCER_COUNT; i++) {
 80  0
         size += broadcasts.get(i).getBroadcast(worker).get().size();
 81  
       }
 82  0
       return createList(size);
 83  
     }
 84  
   }
 85  
 }