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

com.kolibrifx.plovercrest.server.internal.streams.OverlappingRangeObserver 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.internal.streams;

import com.kolibrifx.plovercrest.server.streams.StreamObserver;

public class OverlappingRangeObserver extends RangeStreamObserver {
    private final long endTimestamp;
    private int skipCount;

    public OverlappingRangeObserver(final StreamObserver wrappedObserver,
                                    final long endTimestamp,
                                    final int skipCount) {
        super(wrappedObserver);
        this.endTimestamp = endTimestamp;
        this.skipCount = skipCount;
    }

    @Override
    public void onObserveImpl(final long timestamp, final long index, final T element) {
        if (skipCount > 0) {
            skipCount--;
            return;
        }
        callWrappedObserver(timestamp, index, element);
        if (timestamp > endTimestamp) {
            // read one element beyond the end
            throwEndOfRange();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy