Coverage Report - org.apache.giraph.block_app.reducers.array.ArrayOfHandles
 
Classes in this File Line Coverage Branch Coverage Complexity
ArrayOfHandles
0%
0/12
0%
0/4
0
ArrayOfHandles$ArrayOfBroadcasts
0%
0/5
N/A
0
ArrayOfHandles$ArrayOfReducers
0%
0/7
N/A
0
ArrayOfHandles$ArrayOfReducers$1
0%
0/2
N/A
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.array;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 
 22  
 import org.apache.giraph.block_app.framework.api.BlockMasterApi;
 23  
 import org.apache.giraph.block_app.framework.piece.global_comm.BroadcastHandle;
 24  
 import org.apache.giraph.block_app.framework.piece.global_comm.ReducerHandle;
 25  
 import org.apache.giraph.block_app.framework.piece.global_comm.array.ArrayHandle;
 26  
 import org.apache.giraph.block_app.framework.piece.global_comm.array.BroadcastArrayHandle;
 27  
 import org.apache.giraph.block_app.framework.piece.global_comm.array.ReducerArrayHandle;
 28  
 import org.apache.giraph.function.Supplier;
 29  
 import org.apache.giraph.function.primitive.Int2ObjFunction;
 30  
 import org.apache.giraph.worker.WorkerBroadcastUsage;
 31  
 
 32  
 /**
 33  
  * ArrayHandle implemented as an array of individual handles.
 34  
  *
 35  
  * @param <H> Handle type
 36  
  */
 37  
 public class ArrayOfHandles<H> implements ArrayHandle<H> {
 38  
   protected final ArrayList<H> handles;
 39  
 
 40  0
   public ArrayOfHandles(int count, Supplier<H> reduceHandleFactory) {
 41  0
     handles = new ArrayList<>();
 42  0
     for (int i = 0; i < count; i++) {
 43  0
       handles.add(reduceHandleFactory.get());
 44  
     }
 45  0
   }
 46  
 
 47  0
   public ArrayOfHandles(int count, Int2ObjFunction<H> reduceHandleFactory) {
 48  0
     handles = new ArrayList<>();
 49  0
     for (int i = 0; i < count; i++) {
 50  0
       handles.add(reduceHandleFactory.apply(i));
 51  
     }
 52  0
   }
 53  
 
 54  
   @Override
 55  
   public H get(int index) {
 56  0
     return handles.get(index);
 57  
   }
 58  
 
 59  
   @Override
 60  
   public int getStaticSize() {
 61  0
     return handles.size();
 62  
   }
 63  
 
 64  
   /**
 65  
    * ReducerArrayHandle implemented as an array of separate reducer handles.
 66  
    *
 67  
    * @param <S> Handle type
 68  
    * @param <R> Reduce value type
 69  
    */
 70  
   public static class ArrayOfReducers<S, R>
 71  
       extends ArrayOfHandles<ReducerHandle<S, R>>
 72  
       implements ReducerArrayHandle<S, R> {
 73  
 
 74  
     public ArrayOfReducers(
 75  
         int count, Supplier<ReducerHandle<S, R>> reduceHandleFactory) {
 76  0
       super(count, reduceHandleFactory);
 77  0
     }
 78  
 
 79  
     public ArrayOfReducers(
 80  
         int count, Int2ObjFunction<ReducerHandle<S, R>> reduceHandleFactory) {
 81  0
       super(count, reduceHandleFactory);
 82  0
     }
 83  
 
 84  
     @Override
 85  
     public int getReducedSize(BlockMasterApi master) {
 86  0
       return getStaticSize();
 87  
     }
 88  
 
 89  
     @Override
 90  
     public BroadcastArrayHandle<R> broadcastValue(final BlockMasterApi master) {
 91  0
       return new ArrayOfBroadcasts<>(
 92  0
           getStaticSize(),
 93  0
           new Int2ObjFunction<BroadcastHandle<R>>() {
 94  
             @Override
 95  
             public BroadcastHandle<R> apply(int index) {
 96  0
               return get(index).broadcastValue(master);
 97  
             }
 98  
           });
 99  
     }
 100  
   }
 101  
 
 102  
   /**
 103  
    * BroadcastArrayHandle implemented as an array of separate broadcast handles.
 104  
    *
 105  
    * @param <T> Handle type
 106  
    */
 107  
   public static class ArrayOfBroadcasts<T>
 108  
       extends ArrayOfHandles<BroadcastHandle<T>>
 109  
       implements BroadcastArrayHandle<T> {
 110  
 
 111  
     public ArrayOfBroadcasts(
 112  
         int count,
 113  
         Int2ObjFunction<BroadcastHandle<T>> broadcastHandleFactory) {
 114  0
       super(count, broadcastHandleFactory);
 115  0
     }
 116  
 
 117  
     public ArrayOfBroadcasts(
 118  
         int count,
 119  
         Supplier<BroadcastHandle<T>> broadcastHandleFactory) {
 120  0
       super(count, broadcastHandleFactory);
 121  0
     }
 122  
 
 123  
     @Override
 124  
     public int getBroadcastedSize(WorkerBroadcastUsage worker) {
 125  0
       return getStaticSize();
 126  
     }
 127  
   }
 128  
 }