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