Coverage Report - org.apache.giraph.examples.SimpleAggregatorWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleAggregatorWriter
0%
0/13
0%
0/2
1.25
 
 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.examples;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.Map.Entry;
 23  
 
 24  
 import org.apache.giraph.graph.AggregatorWriter;
 25  
 import org.apache.hadoop.fs.FSDataOutputStream;
 26  
 import org.apache.hadoop.fs.FileSystem;
 27  
 import org.apache.hadoop.fs.Path;
 28  
 import org.apache.hadoop.io.Writable;
 29  
 import org.apache.hadoop.mapreduce.Mapper.Context;
 30  
 
 31  
 /**
 32  
  * This is a simple example for an aggregator writer. After each superstep
 33  
  * the writer will persist the aggregator values to disk, by use of the
 34  
  * Writable interface. The file will be created on the current working
 35  
  * directory.
 36  
  */
 37  0
 public class SimpleAggregatorWriter implements AggregatorWriter {
 38  
   /** Name of the file we wrote to */
 39  
   private static String FILENAME;
 40  
   /** Saved output stream to write to */
 41  
   private FSDataOutputStream output;
 42  
 
 43  
   public static String getFilename() {
 44  0
     return FILENAME;
 45  
   }
 46  
 
 47  
   @SuppressWarnings("rawtypes")
 48  
   @Override
 49  
   public void initialize(Context context, long applicationAttempt)
 50  
     throws IOException {
 51  0
     FILENAME = "aggregatedValues_" + applicationAttempt;
 52  0
     Path p = new Path(FILENAME);
 53  0
     FileSystem fs = FileSystem.get(context.getConfiguration());
 54  0
     output = fs.create(p, true);
 55  0
   }
 56  
 
 57  
   @Override
 58  
   public void writeAggregator(
 59  
       Iterable<Entry<String, Writable>> aggregatorMap,
 60  
       long superstep) throws IOException {
 61  0
     for (Entry<String, Writable> entry : aggregatorMap) {
 62  0
       entry.getValue().write(output);
 63  
     }
 64  0
     output.flush();
 65  0
   }
 66  
 
 67  
   @Override
 68  
   public void close() throws IOException {
 69  0
     output.close();
 70  0
   }
 71  
 }