Search in sources :

Example 1 with CANCELLATION_MESSAGE

use of io.deephaven.web.shared.fu.PromiseLike.CANCELLATION_MESSAGE in project deephaven-core by deephaven.

the class QueryConnectable method startSession.

@JsMethod
public CancellablePromise<IdeSession> startSession(String type) {
    JsLog.debug("Starting", type, "console session");
    LazyPromise<Ticket> promise = new LazyPromise<>();
    final ClientConfiguration config = connection.get().getConfig();
    final Ticket ticket = new Ticket();
    ticket.setTicket(config.newTicketRaw());
    final JsRunnable closer = () -> {
        boolean run = !cancelled.has(ticket);
        if (run) {
            cancelled.add(ticket);
            connection.get().releaseTicket(ticket);
        }
    };
    onConnected().then(e -> Callbacks.grpcUnaryPromise(callback -> {
        StartConsoleRequest request = new StartConsoleRequest();
        request.setSessionType(type);
        request.setResultId(ticket);
        connection.get().consoleServiceClient().startConsole(request, connection.get().metadata(), callback::apply);
    })).then(result -> {
        promise.succeed(ticket);
        return null;
    }, error -> {
        promise.fail(error);
        return null;
    });
    return promise.asPromise(result -> {
        if (cancelled.has(ticket)) {
            // a bit hacky, but it works...
            throw new RuntimeException(CANCELLATION_MESSAGE);
        }
        final IdeSession session = new IdeSession(connection.get(), result, closer);
        sessions.add(session);
        return session;
    }, closer);
}
Also used : JsRunnable(io.deephaven.web.shared.fu.JsRunnable) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) JsMethod(jsinterop.annotations.JsMethod) Promise(elemental2.promise.Promise) ConnectToken(io.deephaven.web.shared.data.ConnectToken) JsPropertyMap(jsinterop.base.JsPropertyMap) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) JsProperty(jsinterop.annotations.JsProperty) CANCELLATION_MESSAGE(io.deephaven.web.shared.fu.PromiseLike.CANCELLATION_MESSAGE) ResponseStreamWrapper(io.deephaven.web.client.api.barrage.stream.ResponseStreamWrapper) StartConsoleRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest) LazyPromise(io.deephaven.web.client.fu.LazyPromise) 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) DomGlobal(elemental2.dom.DomGlobal) GetConsoleTypesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesRequest) CustomEventInit(elemental2.dom.CustomEventInit) IdeSession(io.deephaven.ide.shared.IdeSession) JsArray(elemental2.core.JsArray) JsSet(elemental2.core.JsSet) LogItem(io.deephaven.web.shared.data.LogItem) JsIgnore(jsinterop.annotations.JsIgnore) List(java.util.List) GetConsoleTypesResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesResponse) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) IdeSession(io.deephaven.ide.shared.IdeSession) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) StartConsoleRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsMethod(jsinterop.annotations.JsMethod)

Aggregations

JsArray (elemental2.core.JsArray)1 JsSet (elemental2.core.JsSet)1 CustomEventInit (elemental2.dom.CustomEventInit)1 DomGlobal (elemental2.dom.DomGlobal)1 Promise (elemental2.promise.Promise)1 IdeSession (io.deephaven.ide.shared.IdeSession)1 GetConsoleTypesRequest (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesRequest)1 GetConsoleTypesResponse (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesResponse)1 StartConsoleRequest (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest)1 Ticket (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket)1 ResponseStreamWrapper (io.deephaven.web.client.api.barrage.stream.ResponseStreamWrapper)1 CancellablePromise (io.deephaven.web.client.fu.CancellablePromise)1 JsLog (io.deephaven.web.client.fu.JsLog)1 LazyPromise (io.deephaven.web.client.fu.LazyPromise)1 ConnectToken (io.deephaven.web.shared.data.ConnectToken)1 LogItem (io.deephaven.web.shared.data.LogItem)1 JsConsumer (io.deephaven.web.shared.fu.JsConsumer)1 JsRunnable (io.deephaven.web.shared.fu.JsRunnable)1 CANCELLATION_MESSAGE (io.deephaven.web.shared.fu.PromiseLike.CANCELLATION_MESSAGE)1 RemoverFn (io.deephaven.web.shared.fu.RemoverFn)1