com.kolibrifx.plovercrest.server.internal.streams.NonOverlappingRangeObserver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plovercrest-server Show documentation
Show all versions of plovercrest-server Show documentation
Plovercrest server library.
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 NonOverlappingRangeObserver extends RangeStreamObserver {
private final long startTimestamp;
private final long endTimestamp;
private int skipCount;
public NonOverlappingRangeObserver(final StreamObserver wrappedObserver,
final long startTimestamp,
final long endTimestamp,
final int skipCount) {
super(wrappedObserver);
this.startTimestamp = startTimestamp;
this.endTimestamp = endTimestamp;
this.skipCount = skipCount;
}
@Override
public void onObserveImpl(final long timestamp, final long index, final T element) {
if (skipCount > 0) {
skipCount--;
return;
}
if (timestamp < startTimestamp) {
// skip first element if needed
return;
}
if (timestamp >= endTimestamp) {
throwEndOfRange();
}
callWrappedObserver(timestamp, index, element);
}
}