use of de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction in project invesdwin-context-persistence by subes.
the class ASegmentedTimeSeriesStorageCache method getNextValue.
public V getNextValue(final FDate date, final int shiftForwardUnits) {
assertShiftUnitsPositiveNonZero(shiftForwardUnits);
final V lastValue = getLastValue();
final FDate lastTime = segmentedTable.extractEndTime(lastValue);
if (date.isAfterOrEqualTo(lastTime)) {
return lastValue;
} else {
final SingleValue value = storage.getOrLoad_nextValueLookupTable(hashKey, date, shiftForwardUnits, () -> {
final MutableReference<V> nextValue = new MutableReference<>();
final MutableInt shiftForwardRemaining = new MutableInt(shiftForwardUnits);
try (ICloseableIterator<V> rangeValues = readRangeValues(date, null, DisabledLock.INSTANCE, new ISkipFileFunction() {
@Override
public boolean skipFile(final MemoryFileSummary file) {
final boolean skip = nextValue.get() != null && file.getValueCount() < shiftForwardRemaining.intValue();
if (skip) {
shiftForwardRemaining.subtract(file.getValueCount());
}
return skip;
}
}).iterator()) {
while (shiftForwardRemaining.intValue() >= 0) {
nextValue.set(rangeValues.next());
shiftForwardRemaining.decrement();
}
} catch (final NoSuchElementException e) {
// ignore
}
return new SingleValue(valueSerde, nextValue.get());
});
return value.getValue(valueSerde);
}
}
use of de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction in project invesdwin-context-persistence by subes.
the class TimeSeriesStorageCache method getNextValue.
public V getNextValue(final FDate date, final int shiftForwardUnits) {
assertShiftUnitsPositiveNonZero(shiftForwardUnits);
final V lastValue = getLastValue();
if (lastValue == null) {
return null;
}
final FDate lastTime = extractEndTime.apply(lastValue);
if (date.isAfterOrEqualTo(lastTime)) {
return lastValue;
} else {
final SingleValue value = storage.getOrLoad_nextValueLookupTable(hashKey, date, shiftForwardUnits, () -> {
final MutableReference<V> nextValue = new MutableReference<>();
final MutableInt shiftForwardRemaining = new MutableInt(shiftForwardUnits);
try (ICloseableIterator<V> rangeValues = readRangeValues(date, null, DisabledLock.INSTANCE, new ISkipFileFunction() {
@Override
public boolean skipFile(final MemoryFileSummary file) {
final boolean skip = nextValue.get() != null && file.getValueCount() < shiftForwardRemaining.intValue();
if (skip) {
shiftForwardRemaining.subtract(file.getValueCount());
}
return skip;
}
})) {
while (shiftForwardRemaining.intValue() >= 0) {
nextValue.set(rangeValues.next());
shiftForwardRemaining.decrement();
}
} catch (final NoSuchElementException e) {
// ignore
}
return new SingleValue(valueSerde, nextValue.get());
});
return value.getValue(valueSerde);
}
}
use of de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction in project invesdwin-context-persistence by subes.
the class ASegmentedTimeSeriesStorageCache method getPreviousValue.
public V getPreviousValue(final FDate date, final int shiftBackUnits) {
assertShiftUnitsPositiveNonZero(shiftBackUnits);
final V firstValue = getFirstValue();
final FDate firstTime = segmentedTable.extractEndTime(firstValue);
if (date.isBeforeOrEqualTo(firstTime)) {
return firstValue;
} else {
final SingleValue value = storage.getOrLoad_previousValueLookupTable(hashKey, date, shiftBackUnits, () -> {
final MutableReference<V> previousValue = new MutableReference<>();
final MutableInt shiftBackRemaining = new MutableInt(shiftBackUnits);
try (ICloseableIterator<V> rangeValuesReverse = readRangeValuesReverse(date, null, DisabledLock.INSTANCE, new ISkipFileFunction() {
@Override
public boolean skipFile(final MemoryFileSummary file) {
final boolean skip = previousValue.get() != null && file.getValueCount() < shiftBackRemaining.intValue();
if (skip) {
shiftBackRemaining.add(file.getValueCount());
}
return skip;
}
}).iterator()) {
while (shiftBackRemaining.intValue() >= 0) {
previousValue.set(rangeValuesReverse.next());
shiftBackRemaining.decrement();
}
} catch (final NoSuchElementException e) {
// ignore
}
return new SingleValue(valueSerde, previousValue.get());
});
return value.getValue(valueSerde);
}
}
Aggregations