All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.UpdateSourceQueryTable Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl;

import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.rowset.RowSetBuilderRandom;
import io.deephaven.engine.rowset.RowSetFactory;
import io.deephaven.engine.rowset.TrackingWritableRowSet;
import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph;
import io.deephaven.engine.table.ColumnSource;

import java.util.Map;

/**
 * A {@link QueryTable} that acts as an update source within the {@link PeriodicUpdateGraph}, with {@link RowSet}
 * changes queued externally by a single producer.
 */
public class UpdateSourceQueryTable extends QueryTable implements Runnable {

    private RowSetBuilderRandom additionsBuilder = RowSetFactory.builderRandom();

    public UpdateSourceQueryTable(TrackingWritableRowSet rowSet, Map> result) {
        super(rowSet, result);
    }

    @Override
    public void run() {
        final RowSetBuilderRandom builder;
        synchronized (this) {
            builder = additionsBuilder;
            additionsBuilder = RowSetFactory.builderRandom();
        }
        final RowSet added = builder.build();
        getRowSet().writableCast().insert(added);
        if (added.size() > 0) {
            notifyListeners(added, RowSetFactory.empty(),
                    RowSetFactory.empty());
        }
    }

    public synchronized void addRowKey(final long rowKey) {
        additionsBuilder.addKey(rowKey);
    }

    public synchronized void addRowKeyRange(final long firstRowKey, final long lastRowKey) {
        additionsBuilder.addRange(firstRowKey, lastRowKey);
    }

    @Override
    public void destroy() {
        super.destroy();
        updateGraph.removeSource(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy