private void save(final Stats stats) {
db.thenApply(db -> {
try {
final Sample sample = db.createSample();
sample.setValue("projects!", stats.projects.get());
sample.setValue("sources!", stats.sources.get());
sample.setValue("processors!", stats.processors.get());
sample.setValue("endpoints!", stats.endpoints.get());
stats.facets.forEach((k, v) -> sample.setValue(k + '!', v.get()));
sample.update();
savedData = true;
log.debug("Updated RRD storage");
final long autoDumpTimeout = config.getAutoDumpTimeout();
long now;
if (autoDumpTimeout > 0 && ((now = System.currentTimeMillis()) - lastDump) > autoDumpTimeout) {
doDump(db);
lastDump = now;
}
} catch (final IOException e) {
log.error(e.getMessage() + ", stats: " + stats, e);
}
return db;
});
}