Search in sources :

Example 1 with JsVariableChanges

use of io.deephaven.web.client.api.console.JsVariableChanges in project deephaven-core by deephaven.

the class IdeSession method runCode.

public CancellablePromise<JsCommandResult> runCode(String code) {
    LazyPromise<JsCommandResult> promise = new LazyPromise<>();
    ExecuteCommandRequest request = new ExecuteCommandRequest();
    request.setConsoleId(this.result);
    request.setCode(code);
    Promise<ExecuteCommandResponse> runCodePromise = Callbacks.grpcUnaryPromise(c -> {
        connection.consoleServiceClient().executeCommand(request, connection.metadata(), c::apply);
    });
    runCodePromise.then(response -> {
        JsVariableChanges changes = JsVariableChanges.from(response.getChanges());
        promise.succeed(new JsCommandResult(changes, response.getErrorMessage()));
        return null;
    }, err -> {
        promise.fail(err);
        return null;
    });
    CancellablePromise<JsCommandResult> result = promise.asPromise(() -> {
        // connection.consoleServiceClient().cancelCommand(cancelRequest, connection.metadata());
        throw new UnsupportedOperationException("cancelCommand");
    });
    CommandInfo commandInfo = new CommandInfo(code, result);
    final CustomEventInit event = CustomEventInit.create();
    event.setDetail(commandInfo);
    fireEvent(IdeSession.EVENT_COMMANDSTARTED, event);
    return result;
}
Also used : JsCommandResult(io.deephaven.web.client.api.console.JsCommandResult) LazyPromise(io.deephaven.web.client.fu.LazyPromise) CustomEventInit(elemental2.dom.CustomEventInit) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges)

Example 2 with JsVariableChanges

use of io.deephaven.web.client.api.console.JsVariableChanges in project deephaven-core by deephaven.

the class WorkerConnection method subscribeToFieldUpdates.

@JsMethod
@SuppressWarnings("ConstantConditions")
public JsRunnable subscribeToFieldUpdates(JsConsumer<JsVariableChanges> callback) {
    fieldUpdatesCallback.add(callback);
    if (fieldUpdatesCallback.size == 1) {
        fieldsChangeUpdateStream = ResponseStreamWrapper.of(applicationServiceClient.listFields(new ListFieldsRequest(), metadata));
        fieldsChangeUpdateStream.onData(data -> {
            final JsVariableDefinition[] created = new JsVariableDefinition[0];
            final JsVariableDefinition[] updated = new JsVariableDefinition[0];
            final JsVariableDefinition[] removed = new JsVariableDefinition[0];
            JsArray<FieldInfo> removedFI = data.getRemovedList();
            for (int i = 0; i < removedFI.length; ++i) {
                String removedId = removedFI.getAt(i).getTypedTicket().getTicket().getTicket_asB64();
                JsVariableDefinition result = knownFields.get(removedId);
                removed[removed.length] = result;
                knownFields.remove(removedId);
            }
            JsArray<FieldInfo> createdFI = data.getCreatedList();
            for (int i = 0; i < createdFI.length; ++i) {
                JsVariableDefinition result = new JsVariableDefinition(createdFI.getAt(i));
                created[created.length] = result;
                knownFields.put(result.getId(), result);
            }
            JsArray<FieldInfo> updatedFI = data.getUpdatedList();
            for (int i = 0; i < updatedFI.length; ++i) {
                JsVariableDefinition result = new JsVariableDefinition(updatedFI.getAt(i));
                updated[updated.length] = result;
                knownFields.put(result.getId(), result);
            }
            // Ensure that if a new subscription is in line to receive its initial update, we need to defer
            // the updates until after it receives its initial state.
            LazyPromise.runLater(() -> notifyFieldsChangeListeners(new JsVariableChanges(created, updated, removed)));
        });
        fieldsChangeUpdateStream.onEnd(this::checkStatus);
    } else {
        final JsVariableDefinition[] empty = new JsVariableDefinition[0];
        final JsVariableChanges update = new JsVariableChanges(knownFields.values().toArray(empty), empty, empty);
        LazyPromise.runLater(() -> {
            callback.apply(update);
        });
    }
    return () -> {
        fieldUpdatesCallback.delete(callback);
        if (fieldUpdatesCallback.size == 0) {
            knownFields.clear();
            if (fieldsChangeUpdateStream != null) {
                fieldsChangeUpdateStream.cancel();
                fieldsChangeUpdateStream = null;
            }
        }
    };
}
Also used : JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) ListFieldsRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.ListFieldsRequest) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges) FieldInfo(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.FieldInfo) JsMethod(jsinterop.annotations.JsMethod)

Example 3 with JsVariableChanges

use of io.deephaven.web.client.api.console.JsVariableChanges in project deephaven-core by deephaven.

the class IdeSession method getVariableDefinition.

private Promise<JsVariableDefinition> getVariableDefinition(String name, String type) {
    LazyPromise<JsVariableDefinition> promise = new LazyPromise<>();
    final class Listener implements Consumer<JsVariableChanges> {

        final JsRunnable subscription;

        Listener() {
            subscription = subscribeToFieldUpdates(this::accept);
        }

        @Override
        public void accept(JsVariableChanges changes) {
            JsVariableDefinition foundField = changes.getCreated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
            if (foundField == null) {
                foundField = changes.getUpdated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
            }
            if (foundField != null) {
                subscription.run();
                promise.succeed(foundField);
            }
        }
    }
    Listener listener = new Listener();
    return promise.timeout(10_000).asPromise().then(Promise::resolve, fail -> {
        listener.subscription.run();
        // noinspection unchecked, rawtypes
        return (Promise<JsVariableDefinition>) (Promise) Promise.reject(fail);
    });
}
Also used : JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsOptional(jsinterop.annotations.JsOptional) JsCommandResult(io.deephaven.web.client.api.console.JsCommandResult) JsFigure(io.deephaven.web.client.api.widget.plot.JsFigure) HashMap(java.util.HashMap) Promise(elemental2.promise.Promise) BiDiStream(io.deephaven.web.client.api.barrage.stream.BiDiStream) JsPropertyMap(jsinterop.base.JsPropertyMap) Supplier(java.util.function.Supplier) Any(jsinterop.base.Any) EVENT_TABLE_OPENED(io.deephaven.web.client.api.QueryConnectable.EVENT_TABLE_OPENED) Js(jsinterop.base.Js) JsArrayLike(jsinterop.base.JsArrayLike) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges) Map(java.util.Map) io.deephaven.web.client.api(io.deephaven.web.client.api) io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb) JsType(jsinterop.annotations.JsType) LazyPromise(io.deephaven.web.client.fu.LazyPromise) ExecutionHandle(io.deephaven.web.shared.ide.ExecutionHandle) JsLog(io.deephaven.web.client.fu.JsLog) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) CustomEventInit(elemental2.dom.CustomEventInit) TextDocumentContentChangeEvent(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.changedocumentrequest.TextDocumentContentChangeEvent) JsArray(elemental2.core.JsArray) JsSet(elemental2.core.JsSet) Consumer(java.util.function.Consumer) LogItem(io.deephaven.web.shared.data.LogItem) JsIgnore(jsinterop.annotations.JsIgnore) JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) Timer(com.google.gwt.user.client.Timer) Promise(elemental2.promise.Promise) LazyPromise(io.deephaven.web.client.fu.LazyPromise) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) Consumer(java.util.function.Consumer) JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges)

Aggregations

JsVariableChanges (io.deephaven.web.client.api.console.JsVariableChanges)3 CustomEventInit (elemental2.dom.CustomEventInit)2 JsCommandResult (io.deephaven.web.client.api.console.JsCommandResult)2 JsVariableDefinition (io.deephaven.web.client.api.console.JsVariableDefinition)2 LazyPromise (io.deephaven.web.client.fu.LazyPromise)2 Timer (com.google.gwt.user.client.Timer)1 JsArray (elemental2.core.JsArray)1 JsSet (elemental2.core.JsSet)1 Promise (elemental2.promise.Promise)1 FieldInfo (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.FieldInfo)1 ListFieldsRequest (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.ListFieldsRequest)1 io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb)1 TextDocumentContentChangeEvent (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.changedocumentrequest.TextDocumentContentChangeEvent)1 Ticket (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket)1 io.deephaven.web.client.api (io.deephaven.web.client.api)1 EVENT_TABLE_OPENED (io.deephaven.web.client.api.QueryConnectable.EVENT_TABLE_OPENED)1 BiDiStream (io.deephaven.web.client.api.barrage.stream.BiDiStream)1 JsFigure (io.deephaven.web.client.api.widget.plot.JsFigure)1 CancellablePromise (io.deephaven.web.client.fu.CancellablePromise)1 JsLog (io.deephaven.web.client.fu.JsLog)1