Accessing Mapper's counter in Reducer phase (before finishing the job)
<p>As it is quite obvious from title, my aim is to use the Mapper's counter in the reduce phase, before finishing the particular job.</p>

<p>I have come across a few questions which were highly related to this question, but non of them solved all my problems.
(<a href="https://stackoverflow.com/questions/5450290/accessing-a-mappers-counter-from-a-reducer">Accessing a mapper&#39;s counter from a reducer</a>,
<a href="https://stackoverflow.com/questions/31480400/hadoop-mapreduce-custom-java-counters-exception-in-thread-main-java-lang-ille">Hadoop, MapReduce Custom Java Counters Exception in thread &quot;main&quot; java.lang.IllegalStateException: Job in state DEFINE instead of RUNNING</a>,
etc.)</p>

<pre><code>    @Override
public void setup(Context context) throws IOException, InterruptedException{
    Configuration conf = context.getConfiguration();
    Cluster cluster = new Cluster(conf);
    Job currentJob = cluster.getJob(context.getJobID());
    mapperCounter = currentJob.getCounters().findCounter(COUNTER_NAME).getValue();  
}
</code></pre>

<p>My problem is that the cluster does not contain any job history. </p>

<p><img src="https://i.stack.imgur.com/a24HJ.png" alt=""></p>

<p>The way how I call the mapreduce job:</p>

<pre><code>private void firstFrequents(String outpath) throws IOException,
        InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();
        Cluster cluster = new Cluster(conf);
        conf.setInt("minFreq", MIN_FREQUENCY);
        Job job = Job.getInstance(conf, "APR");
        // Counters counters = job.getCounters();
        job.setJobName("TotalTransactions");
        job.setJarByClass(AssociationRules.class);
        job.setMapperClass(FirstFrequentsMapper.class);
        job.setReducerClass(CandidateReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.addInputPath(job, new Path("input"));
        FileOutputFormat.setOutputPath(job, new Path(outpath));


        job.waitForCompletion(true);
    }
</code></pre>

<p>Mapper:</p>

<pre><code>    import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class FirstFrequentsMapper extends
        Mapper&lt;Object, Text, Text, IntWritable&gt; {
    public enum Counters {
        TotalTransactions
    }

    private IntWritable one = new IntWritable(1);

    public void map(Object key, Text value, Context context)
            throws IOException, InterruptedException {
        String[] line = value.toString().split("\\\t+|,+");
        int iter = 0;
        for (String string : line) {
            context.write(new Text(line[iter]), one);
            iter++;
        }
        context.getCounter(Counters.TotalTransactions).increment(1);

    }
    }
</code></pre>

<p>Reducer</p>

<pre><code>    public class CandidateReducer extends Reducer&lt;Text, IntWritable, Text, IntWritable&gt;{
    private int minFrequency;
    private long totalTransactions;

    @Override
    public void setup(Context context) throws IOException, InterruptedException{
        Configuration conf = context.getConfiguration();
        minFrequency = conf.getInt("minFreq", 1);    
       Cluster cluster = new Cluster(conf);
        Job currentJob = cluster.getJob(context.getJobID());
        totalTransactions = currentJob.getCounters().findCounter(FirstFrequentsMapper.Counters.TotalTransactions).getValue();  
        System.out.print(totalTransactions);
    }


    public void reduce(Text key, Iterable&lt;IntWritable&gt; values, Context context)throws IOException, InterruptedException {
        int counter = 0;
        for (IntWritable val : values) {
            counter+=val.get();
        }

        /* Item frequency calculated*/
        /* Write it to output if it is frequent */
        if (counter&gt;= minFrequency) {
            context.write(key,new IntWritable(counter));
        }
    }


}
</code></pre>