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

com.aconex.scrutineer.elasticsearch.ElasticSearchSorter Maven / Gradle / Ivy

Go to download

Compares 2 streams of Ids and Versions to prove that a secondary source is in sync with a primary source of truth. Designed to verify an elasticsearch cluster contains correct information from a JDBC source.

There is a newer version: 7.9.3
Show newest version
package com.aconex.scrutineer.elasticsearch;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.slf4j.Logger;

import com.aconex.scrutineer.IdAndVersion;
import com.aconex.scrutineer.LogUtils;
import com.fasterxml.sort.Sorter;
import com.google.common.io.CountingInputStream;

public class ElasticSearchSorter {

    private static final Logger LOG = LogUtils.loggerForThisClass();

    private final Sorter sorter;

    public ElasticSearchSorter(Sorter sorter) {
        this.sorter = sorter;
    }

    public void sort(InputStream inputStream, OutputStream outputStream) {
        long begin = System.currentTimeMillis();
        CountingInputStream countingInputStream = new CountingInputStream(inputStream);
        doSort(countingInputStream, outputStream);
        LogUtils.infoTimeTaken(LOG, begin, countingInputStream.getCount(), "Sorted stream of %d bytes", countingInputStream.getCount());
    }

    private void doSort(InputStream inputStream, OutputStream outputStream ) {
        try {
            sorter.sort(inputStream,outputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy