io.deephaven.engine.table.impl.InstrumentedUpdateSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl;
import io.deephaven.engine.table.impl.perf.PerformanceEntry;
import io.deephaven.engine.updategraph.UpdateSourceRegistrar;
import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.Objects;
public abstract class InstrumentedUpdateSource implements Runnable {
protected final UpdateSourceRegistrar updateSourceRegistrar;
@Nullable
protected final PerformanceEntry entry;
public InstrumentedUpdateSource(
@NotNull final UpdateSourceRegistrar updateSourceRegistrar,
@Nullable final String description) {
this.updateSourceRegistrar = Objects.requireNonNull(updateSourceRegistrar);
this.entry = PeriodicUpdateGraph.createUpdatePerformanceEntry(
updateSourceRegistrar.getUpdateGraph(), description);
}
@Override
public final void run() {
if (entry != null) {
entry.onUpdateStart();
}
try {
instrumentedRefresh();
} catch (final Exception error) {
updateSourceRegistrar.removeSource(this);
onRefreshError(error);
} finally {
if (entry != null) {
entry.onUpdateEnd();
}
}
}
protected abstract void instrumentedRefresh();
protected abstract void onRefreshError(Exception error);
}