Search in sources :

Example 1 with MutableReference

use of de.invesdwin.util.concurrent.reference.MutableReference 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);
    }
}
Also used : MemoryFileSummary(de.invesdwin.context.persistence.timeseriesdb.storage.MemoryFileSummary) SingleValue(de.invesdwin.context.persistence.timeseriesdb.storage.SingleValue) MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableReference(de.invesdwin.util.concurrent.reference.MutableReference) ISkipFileFunction(de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction) FDate(de.invesdwin.util.time.date.FDate) FastNoSuchElementException(de.invesdwin.util.error.FastNoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with MutableReference

use of de.invesdwin.util.concurrent.reference.MutableReference 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);
    }
}
Also used : MemoryFileSummary(de.invesdwin.context.persistence.timeseriesdb.storage.MemoryFileSummary) SingleValue(de.invesdwin.context.persistence.timeseriesdb.storage.SingleValue) MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableReference(de.invesdwin.util.concurrent.reference.MutableReference) ISkipFileFunction(de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction) FDate(de.invesdwin.util.time.date.FDate) FastNoSuchElementException(de.invesdwin.util.error.FastNoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with MutableReference

use of de.invesdwin.util.concurrent.reference.MutableReference 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);
    }
}
Also used : MemoryFileSummary(de.invesdwin.context.persistence.timeseriesdb.storage.MemoryFileSummary) SingleValue(de.invesdwin.context.persistence.timeseriesdb.storage.SingleValue) MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableReference(de.invesdwin.util.concurrent.reference.MutableReference) ISkipFileFunction(de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction) FDate(de.invesdwin.util.time.date.FDate) FastNoSuchElementException(de.invesdwin.util.error.FastNoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with MutableReference

use of de.invesdwin.util.concurrent.reference.MutableReference in project invesdwin-context-persistence by subes.

the class TimeSeriesStorageCache method getPreviousValue.

public V getPreviousValue(final FDate date, final int shiftBackUnits) {
    assertShiftUnitsPositiveNonZero(shiftBackUnits);
    final V firstValue = getFirstValue();
    if (firstValue == null) {
        return null;
    }
    final FDate firstTime = extractEndTime.apply(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, file -> {
                final boolean skip = previousValue.get() != null && file.getValueCount() < shiftBackRemaining.intValue();
                if (skip) {
                    shiftBackRemaining.subtract(file.getValueCount());
                }
                return skip;
            })) {
                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);
    }
}
Also used : SingleValue(de.invesdwin.context.persistence.timeseriesdb.storage.SingleValue) MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableReference(de.invesdwin.util.concurrent.reference.MutableReference) FDate(de.invesdwin.util.time.date.FDate) FastNoSuchElementException(de.invesdwin.util.error.FastNoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

SingleValue (de.invesdwin.context.persistence.timeseriesdb.storage.SingleValue)4 MutableReference (de.invesdwin.util.concurrent.reference.MutableReference)4 FastNoSuchElementException (de.invesdwin.util.error.FastNoSuchElementException)4 FDate (de.invesdwin.util.time.date.FDate)4 NoSuchElementException (java.util.NoSuchElementException)4 MutableInt (org.apache.commons.lang3.mutable.MutableInt)4 ISkipFileFunction (de.invesdwin.context.persistence.timeseriesdb.storage.ISkipFileFunction)3 MemoryFileSummary (de.invesdwin.context.persistence.timeseriesdb.storage.MemoryFileSummary)3