Search in sources :

Example 1 with FetchObjectResponse

use of io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse in project deephaven-core by deephaven.

the class JsFigureFactory method create.

private static Promise<JsFigure> create(JsFigureDescriptor descriptor) {
    JsArray<JsTable> tables = descriptor.getTables();
    if (tables == null || tables.length == 0) {
        return (Promise<JsFigure>) (Promise) Promise.reject("No tables provided for Figure creation");
    }
    FigureDescriptor figureDescriptor = convertJsFigureDescriptor(descriptor);
    FetchObjectResponse response = new FetchObjectResponse();
    response.setData(figureDescriptor.serializeBinary());
    Promise<?>[] tableCopyPromises = tables.map((table, index, all) -> table.copy(false)).asArray(new Promise[0]);
    return Promise.all(tableCopyPromises).then(unknownTableCopies -> {
        JsArray<JsTable> jsTableCopies = Js.cast(unknownTableCopies);
        JsTable[] tableCopies = jsTableCopies.asArray(new JsTable[0]);
        return new JsFigure(c -> c.apply(null, response), (figure, descriptor1) -> {
            // We need to listen for disconnects and reconnects
            boolean[] isTableDisconnected = new boolean[tableCopies.length];
            ArrayList<RemoverFn> removerFns = new ArrayList<>(tableCopies.length * 3);
            for (int i = 0; i < tableCopies.length; i++) {
                final int tableIndex = i;
                // Tables are closed when the figure is closed, no need to remove listeners later
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_DISCONNECT, ignore -> {
                    isTableDisconnected[tableIndex] = true;
                    for (int j = 0; j < isTableDisconnected.length; j++) {
                        if (isTableDisconnected[j] && j != tableIndex) {
                            return;
                        }
                    }
                    figure.fireEvent(JsFigure.EVENT_DISCONNECT);
                    figure.unsubscribe();
                }));
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_RECONNECT, ignore -> {
                    isTableDisconnected[tableIndex] = false;
                    for (int j = 0; j < isTableDisconnected.length; j++) {
                        if (isTableDisconnected[j]) {
                            return;
                        }
                    }
                    try {
                        figure.verifyTables();
                        figure.fireEvent(JsFigure.EVENT_RECONNECT);
                        figure.enqueueSubscriptionCheck();
                    } catch (JsFigure.FigureSourceException e) {
                        final CustomEventInit init = CustomEventInit.create();
                        init.setDetail(e);
                        figure.fireEvent(JsFigure.EVENT_RECONNECTFAILED, init);
                    }
                }));
                removerFns.add(tableCopies[i].addEventListener(JsTable.EVENT_RECONNECTFAILED, err -> {
                    for (RemoverFn removerFn : removerFns) {
                        removerFn.remove();
                    }
                    figure.unsubscribe();
                    final CustomEventInit init = CustomEventInit.create();
                    init.setDetail(err);
                    figure.fireEvent(JsFigure.EVENT_RECONNECTFAILED, init);
                }));
            }
            return Promise.resolve(new JsFigure.FigureTableFetchData(tableCopies, new TableMap[0], Collections.emptyMap()));
        }).refetch();
    });
}
Also used : IThenable(elemental2.promise.IThenable) TableMap(io.deephaven.web.client.api.TableMap) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) FigureDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor) JsMethod(jsinterop.annotations.JsMethod) HashMap(java.util.HashMap) CustomEventInit(elemental2.dom.CustomEventInit) Promise(elemental2.promise.Promise) JsPropertyMap(jsinterop.base.JsPropertyMap) JsArray(elemental2.core.JsArray) ArrayList(java.util.ArrayList) Js(jsinterop.base.Js) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) JsTable(io.deephaven.web.client.api.JsTable) Map(java.util.Map) Collections(java.util.Collections) io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor) ArrayList(java.util.ArrayList) Promise(elemental2.promise.Promise) JsTable(io.deephaven.web.client.api.JsTable) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) CustomEventInit(elemental2.dom.CustomEventInit) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) FigureDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor)

Example 2 with FetchObjectResponse

use of io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse in project deephaven-core by deephaven.

the class WorkerConnection method getWidget.

public Promise<JsWidget> getWidget(JsVariableDefinition varDef) {
    return whenServerReady("get a widget").then(server -> Callbacks.<FetchObjectResponse, Object>grpcUnaryPromise(c -> {
        FetchObjectRequest request = new FetchObjectRequest();
        TypedTicket typedTicket = new TypedTicket();
        typedTicket.setTicket(TableTicket.createTicket(varDef));
        typedTicket.setType(varDef.getType());
        request.setSourceId(typedTicket);
        objectServiceClient().fetchObject(request, metadata(), c::apply);
    })).then(response -> Promise.resolve(new JsWidget(this, response)));
}
Also used : Arrays(java.util.Arrays) InitialTableDefinition(io.deephaven.web.client.api.barrage.def.InitialTableDefinition) LogSubscriptionRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.LogSubscriptionRequest) JsPropertyMap(jsinterop.base.JsPropertyMap) Buffer(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Buffer) HandshakeResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb.HandshakeResponse) TypedTicket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.TypedTicket) JsTimeZone(io.deephaven.web.client.api.i18n.JsTimeZone) ObjectServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb_service.ObjectServiceClient) StackTrace(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb.terminationnotificationresponse.StackTrace) io.deephaven.web.shared.data(io.deephaven.web.shared.data) Map(java.util.Map) SessionServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb_service.SessionServiceClient) FieldsChangeUpdate(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.FieldsChangeUpdate) ListFieldsRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.ListFieldsRequest) Set(java.util.Set) ClientTableState(io.deephaven.web.client.state.ClientTableState) ExportedTableCreationResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ExportedTableCreationResponse) JsArray(elemental2.core.JsArray) JsSet(elemental2.core.JsSet) Uint8Array(elemental2.core.Uint8Array) MetadataVersion(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.MetadataVersion) JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) KeyValue(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.KeyValue) ConsoleServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb_service.ConsoleServiceClient) BarrageMessageWrapper(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageMessageWrapper) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsItr(io.deephaven.web.client.fu.JsItr) JsOptional(jsinterop.annotations.JsOptional) JsWidget(io.deephaven.web.client.api.widget.JsWidget) JsFigure(io.deephaven.web.client.api.widget.plot.JsFigure) Promise(elemental2.promise.Promise) BiDiStream(io.deephaven.web.client.api.barrage.stream.BiDiStream) Supplier(java.util.function.Supplier) RequestBatcher(io.deephaven.web.client.api.batch.RequestBatcher) ArrayList(java.util.ArrayList) Builder(io.deephaven.javascript.proto.dhinternal.flatbuffers.Builder) ResponseStreamWrapper(io.deephaven.web.client.api.barrage.stream.ResponseStreamWrapper) BiConsumer(java.util.function.BiConsumer) TableReviver(io.deephaven.web.client.state.TableReviver) FetchObjectRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectRequest) JsTreeTable(io.deephaven.web.client.api.tree.JsTreeTable) TableServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb_service.TableServiceClient) LazyPromise(io.deephaven.web.client.fu.LazyPromise) Nullable(javax.annotation.Nullable) BrowserHeaders(io.deephaven.javascript.proto.dhinternal.browserheaders.BrowserHeaders) LogSubscriptionData(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.LogSubscriptionData) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) ColumnDefinition(io.deephaven.web.client.api.barrage.def.ColumnDefinition) RecordBatch(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.RecordBatch) MergeTablesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.MergeTablesRequest) ApplyPreviewColumnsRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ApplyPreviewColumnsRequest) InputTableServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.inputtable_pb_service.InputTableServiceClient) BarrageSubscriptionOptions(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageSubscriptionOptions) ColumnConversionMode(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.ColumnConversionMode) EmptyTableRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.EmptyTableRequest) BarrageUpdateMetadata(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageUpdateMetadata) ByteBuffer(java.nio.ByteBuffer) TableConfig(io.deephaven.web.client.api.batch.TableConfig) TableReference(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.TableReference) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges) ReleaseRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb.ReleaseRequest) FlightData(io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.flight_pb.FlightData) ApplicationServiceClient(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb_service.ApplicationServiceClient) ExportedTableUpdatesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ExportedTableUpdatesRequest) JsLog(io.deephaven.web.client.fu.JsLog) Collectors(java.util.stream.Collectors) HasTableBinding(io.deephaven.web.client.state.HasTableBinding) List(java.util.List) FlightServiceClient(io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.flight_pb_service.FlightServiceClient) HasLifecycle(io.deephaven.web.client.api.lifecycle.HasLifecycle) Message(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.Message) JsWeakMap(elemental2.core.JsWeakMap) BarrageSubscriptionRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageSubscriptionRequest) ExportedTableUpdateMessage(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ExportedTableUpdateMessage) Optional(java.util.Optional) TimeTableRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.TimeTableRequest) HandshakeRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb.HandshakeRequest) Code(io.deephaven.javascript.proto.dhinternal.grpcweb.grpc.Code) Grpc(io.deephaven.javascript.proto.dhinternal.grpcweb.Grpc) BrowserFlightServiceClient(io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.browserflight_pb_service.BrowserFlightServiceClient) BarrageMessageType(io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageMessageType) JsMethod(jsinterop.annotations.JsMethod) HashMap(java.util.HashMap) StateCache(io.deephaven.web.client.api.state.StateCache) HashSet(java.util.HashSet) FetchTableRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.FetchTableRequest) Js(jsinterop.base.Js) FieldNode(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.FieldNode) Charset(java.nio.charset.Charset) Field(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Field) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) Long(io.deephaven.javascript.proto.dhinternal.flatbuffers.Long) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) DomGlobal(elemental2.dom.DomGlobal) Schema(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Schema) TerminationNotificationRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.session_pb.TerminationNotificationRequest) JsDataHandler(io.deephaven.web.client.api.parse.JsDataHandler) BarrageUtils(io.deephaven.web.client.api.barrage.BarrageUtils) FieldInfo(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.application_pb.FieldInfo) BitSet(java.util.BitSet) MessageHeader(io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.MessageHeader) FetchObjectRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectRequest) TypedTicket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.TypedTicket) JsWidget(io.deephaven.web.client.api.widget.JsWidget) Grpc(io.deephaven.javascript.proto.dhinternal.grpcweb.Grpc) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse)

Aggregations

JsArray (elemental2.core.JsArray)2 Promise (elemental2.promise.Promise)2 FetchObjectResponse (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse)2 JsSet (elemental2.core.JsSet)1 JsWeakMap (elemental2.core.JsWeakMap)1 Uint8Array (elemental2.core.Uint8Array)1 CustomEventInit (elemental2.dom.CustomEventInit)1 DomGlobal (elemental2.dom.DomGlobal)1 IThenable (elemental2.promise.IThenable)1 FieldNode (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.FieldNode)1 Message (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.Message)1 MessageHeader (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.MessageHeader)1 RecordBatch (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.message_generated.org.apache.arrow.flatbuf.RecordBatch)1 Buffer (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Buffer)1 Field (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Field)1 KeyValue (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.KeyValue)1 MetadataVersion (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.MetadataVersion)1 Schema (io.deephaven.javascript.proto.dhinternal.arrow.flight.flatbuf.schema_generated.org.apache.arrow.flatbuf.Schema)1 BrowserFlightServiceClient (io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.browserflight_pb_service.BrowserFlightServiceClient)1 FlightData (io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.flight_pb.FlightData)1