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

com.kolibrifx.plovercrest.server.streams.folds.HistoricalCombinatorStrategy Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
 */

package com.kolibrifx.plovercrest.server.streams.folds;

import java.util.Collection;
import com.kolibrifx.plovercrest.server.internal.folds.FoldCallback;
import com.kolibrifx.plovercrest.server.internal.folds.PeekableInputStream;

/**
 * @see com.kolibrifx.plovercrest.server.folds.FoldCombinators#historical()
 */
public class HistoricalCombinatorStrategy implements CombinatorStrategy {
    @Override
    public  boolean tryConsumeNext(final Collection> feeds,
                                      final FoldCallback cb) {
        if (feeds.isEmpty()) {
            return false;
        }
        PeekableInputStream best = null;
        for (final PeekableInputStream feed : feeds) {
            if (!feed.hasNext()) {
                // Missing data from one table. For this strategy, both is a no go.
                // This guarantees that timestamps are triggered in order.
                cb.onEnd();
                return false;
            }
            if (best == null || feed.nextTimestamp() < best.nextTimestamp()) {
                best = feed;
            }
        }
        assert best != null && best.hasNext();
        best.consumeNext(cb);
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy