org.apache.giraph.examples
Class SimpleAggregatorWriter

java.lang.Object
  extended by org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable
      extended by org.apache.giraph.examples.SimpleAggregatorWriter
All Implemented Interfaces:
AggregatorWriter, ImmutableClassesGiraphConfigurable

public class SimpleAggregatorWriter
extends DefaultImmutableClassesGiraphConfigurable
implements AggregatorWriter

This is a simple example for an aggregator writer. After each superstep the writer will persist the aggregator values to disk, by use of the Writable interface. The file will be created on the current working directory.


Field Summary
 
Fields inherited from interface org.apache.giraph.aggregators.AggregatorWriter
LAST_SUPERSTEP
 
Constructor Summary
SimpleAggregatorWriter()
           
 
Method Summary
 void close()
          The method is called at the end of a successful computation.
static String getFilename()
           
 void initialize(org.apache.hadoop.mapreduce.Mapper.Context context, long applicationAttempt)
          The method is called at the initialization of the AggregatorWriter.
 void writeAggregator(Iterable<Map.Entry<String,org.apache.hadoop.io.Writable>> aggregatorMap, long superstep)
          The method is called at the end of each superstep.
 
Methods inherited from class org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable
getConf, setConf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.giraph.conf.ImmutableClassesGiraphConfigurable
getConf, setConf
 

Constructor Detail

SimpleAggregatorWriter

public SimpleAggregatorWriter()
Method Detail

getFilename

public static String getFilename()

initialize

public void initialize(org.apache.hadoop.mapreduce.Mapper.Context context,
                       long applicationAttempt)
                throws IOException
Description copied from interface: AggregatorWriter
The method is called at the initialization of the AggregatorWriter. More precisely, the aggregatorWriter is initialized each time a new master is elected.

Specified by:
initialize in interface AggregatorWriter
Parameters:
context - Mapper Context where the master is running on
applicationAttempt - ID of the applicationAttempt, used to disambiguate aggregator writes for different attempts
Throws:
IOException

writeAggregator

public void writeAggregator(Iterable<Map.Entry<String,org.apache.hadoop.io.Writable>> aggregatorMap,
                            long superstep)
                     throws IOException
Description copied from interface: AggregatorWriter
The method is called at the end of each superstep. The user might decide whether to write the aggregators values for the current superstep. For the last superstep, AggregatorWriter.LAST_SUPERSTEP is passed.

Specified by:
writeAggregator in interface AggregatorWriter
Parameters:
aggregatorMap - Map from aggregator name to aggregator value
superstep - Current superstep
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: AggregatorWriter
The method is called at the end of a successful computation. The method is not called when the job fails and a new master is elected. For this reason it's advised to flush data at the end of AggregatorWriter.writeAggregator(Iterable, long).

Specified by:
close in interface AggregatorWriter
Throws:
IOException


Copyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.