com.hazelcast.mapreduce
Class Reducer<ValueIn,ValueOut>

java.lang.Object
  extended by com.hazelcast.mapreduce.Reducer<ValueIn,ValueOut>
Type Parameters:
ValueIn - value type of the incoming values
ValueOut - value type of the reduced values

@Beta
public abstract class Reducer<ValueIn,ValueOut>
extends Object

The abstract Reducer class is used to build reducers for the Job.
Reducers may be distributed inside of the cluster but there is always only one Reducer per key.

Reducers are always called in a thread-safe way however they may be moved from one thread to another in the internal thread pool. As of version 3.3.3 the internal state is automatically ensured to be visible according to the Java memory model by the framework. The previous requirement for making fields volatile is dropped.

Due to the fact that there is only one Reducer per key mapped values needs to be transmitted to one of the cluster nodes. To reduce the traffic costs between the nodes a Combiner implementation can be added to the call which runs alongside the mapper to pre-reduce mapped values into intermediate results.

A simple Reducer implementation could look like that sum-function implementation:

 public class SumReducer implements Reducer<Integer, Integer>
 {
   private int sum = 0;

   public void reduce( Integer value )
   {
     sum += value;
   }

   public Integer finalizeReduce()
   {
     return sum;
   }
 }
 

Since:
3.2

Constructor Summary
Reducer()
           
 
Method Summary
 void beginReduce()
          This method is called before the first value is submitted to this Reducer instance.
abstract  ValueOut finalizeReduce()
          finalizeReduce is called as last step for a reducing phase per key and retrieved the final reduced result.
abstract  void reduce(ValueIn value)
          This method is called to supply values to be reduced into a final reduced result.
The reduce method might be called multiple times so the eventually reduces value needs to be hold internally in a member state of the Reducer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reducer

public Reducer()
Method Detail

beginReduce

public void beginReduce()
This method is called before the first value is submitted to this Reducer instance. It can be used to setup any internal needed state before starting to reduce the actual values.


reduce

public abstract void reduce(ValueIn value)
This method is called to supply values to be reduced into a final reduced result.
The reduce method might be called multiple times so the eventually reduces value needs to be hold internally in a member state of the Reducer.

Parameters:
value - value to be reduced

finalizeReduce

public abstract ValueOut finalizeReduce()
finalizeReduce is called as last step for a reducing phase per key and retrieved the final reduced result.

Returns:
the final reduced result


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.