Package com.thinkaurelius.faunus.mapreduce.util

Source Code of com.thinkaurelius.faunus.mapreduce.util.SafeMapperOutputs

package com.thinkaurelius.faunus.mapreduce.util;

import com.thinkaurelius.faunus.Tokens;
import com.thinkaurelius.faunus.mapreduce.FaunusCompiler;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;

import java.io.IOException;

/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class SafeMapperOutputs {

    private final MultipleOutputs outputs;
    private final Mapper.Context context;
    private final boolean testing;

    public SafeMapperOutputs(final Mapper.Context context) {
        this.context = context;
        this.outputs = new MultipleOutputs(this.context);
        this.testing = this.context.getConfiguration().getBoolean(FaunusCompiler.TESTING, false);
    }

    public void write(final String type, final Writable key, final Writable value) throws IOException, InterruptedException {
        if (this.testing) {
            if (type.equals(Tokens.SIDEEFFECT))
                this.context.write(key, value);
        } else
            this.outputs.write(type, key, value);
    }

    public void close() throws IOException, InterruptedException {
        this.outputs.close();
    }
}
TOP

Related Classes of com.thinkaurelius.faunus.mapreduce.util.SafeMapperOutputs

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.