use of de.invesdwin.util.time.duration.Duration in project invesdwin-context-persistence by subes.
the class ADataUpdater method doUpdate.
protected final FDate doUpdate() throws IncompleteUpdateFoundException {
final ATimeSeriesUpdater<K, V> updater = new ATimeSeriesUpdater<K, V>(key, getTable()) {
private static final int BATCH_LOG_INTERVAL = 100_000 / BATCH_FLUSH_INTERVAL;
@GuardedBy("this")
private Integer lastFlushIndex;
@GuardedBy("this")
private Duration flushDuration;
@GuardedBy("this")
private long flushElementCount;
@GuardedBy("this")
private FDate lastFlushMaxTime;
@GuardedBy("this")
private Instant lastFlushTime;
@Override
protected FDate extractTime(final V element) {
return ADataUpdater.this.extractTime(element);
}
@Override
protected FDate extractEndTime(final V element) {
return ADataUpdater.this.extractEndTime(element);
}
@Override
protected ICloseableIterable<? extends V> getSource(final FDate updateFrom) {
final ICloseableIterable<? extends V> downloadElements = downloadElements(key, updateFrom);
return downloadElements;
}
@Override
protected void onUpdateStart() {
log.info("Updating %s for [%s]", getElementsName(), keyToString(key));
}
@Override
protected synchronized void onFlush(final int flushIndex, final Instant flushStart, final UpdateProgress progress) {
lastFlushIndex = Integers.max(lastFlushIndex, flushIndex);
if (flushDuration == null) {
flushDuration = flushStart.toDuration();
} else {
flushDuration = flushDuration.add(flushStart.toDuration());
}
flushElementCount += progress.getCount();
lastFlushMaxTime = FDates.max(lastFlushMaxTime, progress.getMaxTime());
if (flushIndex % BATCH_LOG_INTERVAL == 0) {
logFlush();
}
}
private void logFlush() {
Assertions.assertThat(lastFlushIndex).isNotNull();
// if we are too fast, only print status once a second
if (lastFlushTime == null || lastFlushTime.toDuration().isGreaterThan(Duration.ONE_SECOND)) {
log.info("Persisted %s. %s batch for [%s]. Reached time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(key), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
lastFlushTime = new Instant();
}
lastFlushIndex = null;
flushDuration = null;
flushElementCount = 0;
lastFlushMaxTime = null;
}
@Override
protected synchronized void onUpdateFinished(final Instant updateStart) {
if (lastFlushIndex != null) {
logFlush();
}
log.info("Finished updating %s %s for [%s] from [%s] to [%s] after %s", getCount(), getElementsName(), keyToString(key), getMinTime(), getMaxTime(), updateStart);
}
};
updater.update();
return updater.getMaxTime();
}
use of de.invesdwin.util.time.duration.Duration in project invesdwin-context-persistence by subes.
the class ConfiguredHikariCPDataSource method createDelegate.
@Override
protected DataSource createDelegate() {
final HikariConfig config = new HikariConfig();
config.setJdbcUrl(context.getConnectionUrl());
config.setUsername(context.getConnectionUser());
config.setPassword(context.getConnectionPassword());
config.setDriverClassName(context.getConnectionDriver());
config.setIdleTimeout(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.MILLISECONDS));
config.setMaximumPoolSize(100);
config.setMinimumIdle(1);
enableStatementCache(config);
final HikariDataSource ds = new HikariDataSource(config);
Assertions.assertThat(this.closeableDs).isNull();
this.closeableDs = ds;
if (logging && PersistenceProperties.IS_P6SPY_AVAILABLE) {
final com.p6spy.engine.spy.P6DataSource proxy = new com.p6spy.engine.spy.P6DataSource(ds);
return proxy;
} else {
return ds;
}
}
use of de.invesdwin.util.time.duration.Duration in project invesdwin-context-persistence by subes.
the class ConfiguredC3p0DataSource method createDelegate.
@Override
protected DataSource createDelegate() {
final ComboPooledDataSource ds = new ComboPooledDataSource();
try {
ds.setDriverClass(context.getConnectionDriver());
} catch (final PropertyVetoException e1) {
throw Err.process(e1);
}
ds.setJdbcUrl(context.getConnectionUrl());
ds.setUser(context.getConnectionUser());
ds.setPassword(context.getConnectionPassword());
ds.setMaxStatements(5000);
ds.setMaxStatementsPerConnection(50);
// fix apparent deadlocks
ds.setStatementCacheNumDeferredCloseThreads(1);
ds.setMaxPoolSize(100);
ds.setMinPoolSize(1);
ds.setMaxIdleTime(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.SECONDS));
ds.setTestConnectionOnCheckout(true);
ds.setAutoCommitOnClose(true);
Assertions.assertThat(this.closeableDs).isNull();
this.closeableDs = ds;
if (logging && PersistenceProperties.IS_P6SPY_AVAILABLE) {
final com.p6spy.engine.spy.P6DataSource proxy = new com.p6spy.engine.spy.P6DataSource(ds);
return proxy;
} else {
return ds;
}
}
use of de.invesdwin.util.time.duration.Duration in project invesdwin-context-persistence by subes.
the class ALazyDataUpdater method doUpdate.
protected final FDate doUpdate(final FDate estimatedTo) throws IncompleteUpdateFoundException {
try {
final ALoggingTimeSeriesUpdater<K, V> updater = new ALoggingTimeSeriesUpdater<K, V>(key, getTable(), log) {
@Override
protected FDate extractEndTime(final V element) {
return ALazyDataUpdater.this.extractEndTime(element);
}
@Override
protected ICloseableIterable<? extends V> getSource(final FDate updateFrom) {
final ICloseableIterable<? extends V> downloadElements = ALazyDataUpdater.this.downloadElements(getKey(), updateFrom);
return downloadElements;
}
@Override
protected String keyToString(final K key) {
return ALazyDataUpdater.this.keyToString(key);
}
@Override
protected String getElementsName() {
return ALazyDataUpdater.this.getElementsName();
}
@Override
public Percent getProgress() {
if (estimatedTo == null) {
return null;
}
final FDate from = getMinTime();
if (from == null) {
return null;
}
final FDate curTime = getMaxTime();
if (curTime == null) {
return null;
}
return new Percent(new Duration(from, curTime), new Duration(from, estimatedTo)).orLower(Percent.ONE_HUNDRED_PERCENT);
}
};
final Callable<FDate> task = new Callable<FDate>() {
@Override
public FDate call() throws Exception {
updater.update();
return updater.getMaxTime();
}
};
final String taskName = "Loading " + getElementsName() + " for " + keyToString(getKey());
final Callable<Percent> progress = newProgressCallable(estimatedTo, updater);
return TaskInfoCallable.of(taskName, task, progress).call();
} catch (final IncompleteUpdateFoundException e) {
throw e;
} catch (final Throwable e) {
throw Throwables.propagate(e);
}
}
use of de.invesdwin.util.time.duration.Duration in project invesdwin-context-persistence by subes.
the class ALoggingTimeSeriesUpdater method logFlush.
private void logFlush() {
Assertions.assertThat(lastFlushIndex).isNotNull();
// if we are too fast, only print status once a second
if (lastFlushTime == null || lastFlushTime.isGreaterThan(Duration.ONE_SECOND)) {
final Duration flushDuration = updateStart.toDuration();
final Percent progress = getProgress();
if (progress != null) {
log.info("Persisted %s. %s batch for [%s]. Reached [%s] at time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), progress.asScale(PercentScale.PERCENT), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
} else {
log.info("Persisted %s. %s batch for [%s]. Reached time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
}
lastFlushTime = new Instant();
}
lastFlushIndex = null;
lastFlushMaxTime = null;
}
Aggregations