Search in sources :

Example 1 with LogSubscriptionRequest

use of io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.LogSubscriptionRequest in project deephaven-core by deephaven.

the class WorkerConnection method subscribeToLogs.

public JsRunnable subscribeToLogs(JsConsumer<LogItem> callback) {
    boolean mustSub = logCallbacks.size == 0;
    logCallbacks.add(callback);
    if (mustSub) {
        logCallbacks.add(recordLog);
        // TODO core#225 track latest message seen and only sub after that
        logStream = ResponseStreamWrapper.of(consoleServiceClient.subscribeToLogs(new LogSubscriptionRequest(), metadata));
        logStream.onData(data -> {
            LogItem logItem = new LogItem();
            logItem.setLogLevel(data.getLogLevel());
            logItem.setMessage(data.getMessage());
            logItem.setMicros((double) java.lang.Long.parseLong(data.getMicros()));
            notifyLog(logItem);
        });
        logStream.onEnd(this::checkStatus);
    } else {
        pastLogs.forEach(callback::apply);
    }
    return () -> {
        logCallbacks.delete(callback);
        if (logCallbacks.size == 1) {
            logCallbacks.delete(recordLog);
            assert logCallbacks.size == 0;
            pastLogs.clear();
            if (logStream != null) {
                logStream.cancel();
                logStream = null;
            }
        }
    };
}
Also used : LogSubscriptionRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.LogSubscriptionRequest)

Aggregations

LogSubscriptionRequest (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.LogSubscriptionRequest)1