public void process(long newTime, double newValue) { Header header = parentDb.getHeader(); long step = header.getStep(); long oldTime = header.getLastUpdateTime(); long startTime = Util.normalize(oldTime, step); long endTime = startTime + step; double oldValue = lastValue.get(); double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); if (newTime < endTime) { accumulate(oldTime, newTime, updateValue); } else { // should store something long boundaryTime = Util.normalize(newTime, step); accumulate(oldTime, boundaryTime, updateValue); double value = calculateTotal(startTime, boundaryTime); // how many updates? long numSteps = (boundaryTime - endTime) / step + 1L; // ACTION! parentDb.archive(this, value, numSteps); // cleanup nanSeconds.set(0); accumValue.set(0.0); accumulate(boundaryTime, newTime, updateValue); } }