Search in sources :

Example 1 with ActiveTableBinding

use of io.deephaven.web.client.state.ActiveTableBinding in project deephaven-core by deephaven.

the class JsTable method setState.

@Override
public void setState(final ClientTableState state) {
    state.onRunning(s -> {
        if (state == currentState) {
            lastVisibleState = state;
            hasInputTable = s.getTableDef().getAttributes().isInputTable();
            // defer the size change so that is there is a viewport sub also waiting for onRunning, it gets it first
            LazyPromise.runLater(() -> {
                if (state == state()) {
                    setSize(state.getSize());
                }
            });
        }
    }, JsRunnable.doNothing());
    final ClientTableState was = currentState;
    if (was != state) {
        state.onRunning(s -> {
            // If already closed, we can ignore this, since we already cleaned those up
            if (!isClosed() && was != null && was != state()) {
                // if we held a subscription
                TableViewportSubscription existingSubscription = subscriptions.remove(was.getHandle());
                if (existingSubscription != null && existingSubscription.getStatus() != TableViewportSubscription.Status.DONE) {
                    JsLog.debug("closing old viewport", state(), existingSubscription.state());
                    // with the replacement state successfully running, we can shut down the old viewport (unless
                    // something
                    // external retained it)
                    existingSubscription.internalClose();
                }
            }
        }, JsRunnable.doNothing());
        boolean historyChanged = false;
        if (was != null) {
            // check if the new state is derived from the current state
            historyChanged = !state.isAncestor(was);
            was.pause(this);
            JsLog.debug("Table state change (new history? ", historyChanged, ") " + "from ", was.getHandle().toString(), was, " to ", state.getHandle().toString(), state);
        }
        currentState = state;
        ActiveTableBinding active = state.getActiveBinding(this);
        if (active == null) {
            state.createBinding(this);
        } else {
            active.changeState(state);
        }
        if (historyChanged) {
            // when the new state is not derived from the current state,
            // then, when the new state succeeds, we will totally releaseTable the previous table,
            // allowing it to be automatically released (if nobody else needs it).
            state.onRunning(success -> {
                if (isClosed()) {
                    // if already closed, we should have already released that handle too
                    return;
                }
                if (currentState != state) {
                    // ancestor
                    return;
                }
                final boolean shouldRelease = !state().isAncestor(was);
                JsLog.debug("History changing state update complete; release? ", shouldRelease, " state: ", was, LazyString.of(was::toStringMinimal));
                if (shouldRelease) {
                    was.releaseTable(this);
                }
            }, () -> {
                LazyPromise.runLater(() -> {
                    if (isClosed()) {
                        // if already closed, we should have already released that handle too
                        return;
                    }
                    if (currentState != state) {
                        // ancestor
                        return;
                    }
                    final boolean shouldRelease = !currentState.isAncestor(was);
                    JsLog.debug("History changing state update failed; release? ", shouldRelease, " state: ", was, LazyString.of(was::toStringMinimal));
                    if (shouldRelease) {
                        was.releaseTable(this);
                    }
                });
            });
        }
        final CustomEventInit init = CustomEventInit.create();
        init.setDetail(state);
        fireEvent(INTERNAL_EVENT_STATECHANGED, init);
    }
}
Also used : ActiveTableBinding(io.deephaven.web.client.state.ActiveTableBinding) ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit) TableViewportSubscription(io.deephaven.web.client.api.subscription.TableViewportSubscription)

Example 2 with ActiveTableBinding

use of io.deephaven.web.client.state.ActiveTableBinding in project deephaven-core by deephaven.

the class JsTable method hasRollbackHandle.

public boolean hasRollbackHandle(TableTicket tableHandle) {
    for (ClientTableState state : state().reversed()) {
        ActiveTableBinding binding = state.getActiveBinding(this);
        if (binding == null) {
            continue;
        }
        ActiveTableBinding rollback = binding.getRollback();
        if (rollback == null) {
            continue;
        }
        if (rollback.getState().getHandle().equals(tableHandle)) {
            return true;
        }
    }
    return false;
}
Also used : ActiveTableBinding(io.deephaven.web.client.state.ActiveTableBinding) ClientTableState(io.deephaven.web.client.state.ClientTableState)

Aggregations

ActiveTableBinding (io.deephaven.web.client.state.ActiveTableBinding)2 ClientTableState (io.deephaven.web.client.state.ClientTableState)2 CustomEventInit (elemental2.dom.CustomEventInit)1 TableViewportSubscription (io.deephaven.web.client.api.subscription.TableViewportSubscription)1