All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qcri.rheem.profiler.java.SinkProfiler Maven / Gradle / Ivy

The newest version!
package org.qcri.rheem.profiler.java;

import org.apache.commons.lang3.Validate;
import org.qcri.rheem.java.channels.JavaChannelInstance;
import org.qcri.rheem.java.operators.JavaExecutionOperator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Supplier;

/**
 * {@link OperatorProfiler} implementation for sinks.
 */
public class SinkProfiler extends OperatorProfiler {

    private JavaChannelInstance inputChannelInstance;

    public SinkProfiler(Supplier operatorGenerator, Supplier... dataQuantumGenerators) {
        super(operatorGenerator, dataQuantumGenerators);
    }

    @Override
    public void prepare(long... inputCardinalities) {
        Validate.isTrue(inputCardinalities.length == 1);

        super.prepare(inputCardinalities);
        int inputCardinality = (int) inputCardinalities[0];

        // Create input data.
        Collection dataQuanta = new ArrayList<>(inputCardinality);
        final Supplier supplier = this.dataQuantumGenerators.get(0);
        for (int i = 0; i < inputCardinality; i++) {
            dataQuanta.add(supplier.get());
        }
        this.inputChannelInstance = createChannelInstance(dataQuanta);
    }

    @Override
    protected long executeOperator() {
        this.evaluate(
                new JavaChannelInstance[]{this.inputChannelInstance},
                new JavaChannelInstance[]{}
        );
        return 0L;
    }

}