X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.history%2Fsrc%2Forg%2Fsimantics%2Fhistory%2Fimpl%2FCollectorImpl.java;h=c202f733ca6af88c284351de3cfadea3eee9899d;hb=88579da9fef9b6d2af5a5c9d7d1ec3c7ae1d2ab5;hp=e956b37117fcc365cbb85cf0e2b339752d814bcc;hpb=05606cd41241cd473a102de76a5d0970d7c73af6;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java b/bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java index e956b3711..c202f733c 100644 --- a/bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java +++ b/bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java @@ -87,6 +87,15 @@ public class CollectorImpl implements Collector { /** True when all items are open */ boolean itemsOpen = true; + + /** True when history collection will write data to disk */ + boolean enabled = true; + + /** + * Transient info only set in {@link #beginStep(NumberBinding, Object)} based on + * {@link #enabled} + */ + private transient boolean stepEnabled = true; public FlushPolicy flushPolicy = FlushPolicy.FlushOnEveryStep; @@ -122,7 +131,16 @@ public class CollectorImpl implements Collector { this.history = history; this.state = (CollectorState) previousState.clone(); } - + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public boolean isEnabled() { + return enabled; + } + @Override public synchronized void addItem(Bean item) throws HistoryException { try { @@ -494,13 +512,20 @@ public class CollectorImpl implements Collector { @Override public void beginStep(NumberBinding binding, Object time) throws HistoryException { - openAllItems(); + stepEnabled = enabled; updateDt(binding, time); state.time.setValue(binding, time); + if (enabled) { + openAllItems(); + } } @Override public void setValue(String id, Binding binding, Object value) throws HistoryException { + // Short-circuit calls when collection not enabled + if (!stepEnabled) + return; + VariableState vs = state.values.get( id ); if (vs == null) { vs = new VariableState(); @@ -554,6 +579,8 @@ public class CollectorImpl implements Collector { @Override public void endStep() throws HistoryException { + if (!stepEnabled) + return; // Write values to streams for (ActiveStream i : items) {