use of io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable in project ksql by confluentinc.
the class Cli method handlePrintedTopic.
@SuppressWarnings({ "try", "unused" })
private void handlePrintedTopic(final String printTopic, final SqlBaseParser.PrintTopicContext ignored) {
final RestResponse<StreamPublisher<String>> topicResponse = makeKsqlRequest(printTopic, restClient::makePrintTopicRequest);
if (topicResponse.isSuccessful()) {
try (StatusClosable toClose = terminal.setStatusMessage("Press CTRL-C to interrupt")) {
final CompletableFuture<Void> future = new CompletableFuture<>();
final StreamPublisher<String> publisher = topicResponse.getResponse();
final PrintTopicSubscriber subscriber = new PrintTopicSubscriber(publisher.getContext(), future);
publisher.subscribe(subscriber);
terminal.handle(Terminal.Signal.INT, signal -> {
terminal.handle(Terminal.Signal.INT, Terminal.SignalHandler.SIG_IGN);
subscriber.close();
future.complete(null);
});
try {
future.get();
} catch (Exception e) {
LOGGER.error("Unexpected exception in waiting for print topic completion", e);
} finally {
publisher.close();
}
terminal.writer().println("Topic printing ceased");
}
} else {
terminal.writer().println(topicResponse.getErrorMessage().getMessage());
}
terminal.flush();
}
use of io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable in project ksql by confluentinc.
the class JLineTerminalTest method shouldResetStatusMessage.
@Test
public void shouldResetStatusMessage() {
// Given:
final StatusClosable closable = terminal.setStatusMessage("test message");
clearInvocations(statusBar);
// When:
closable.close();
// Then:
verify(statusBar).update(ImmutableList.of(new AttributedString("", AttributedStyle.DEFAULT)));
}
use of io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable in project ksql by confluentinc.
the class Cli method handleQuery.
// ignored param is required to compile.
@SuppressWarnings({ "try", "unused" })
private void handleQuery(final String statement, final SqlBaseParser.QueryStatementContext query) {
final RestResponse<StreamPublisher<StreamedRow>> queryResponse = makeKsqlRequest(statement, restClient::makeQueryRequestStreamed);
if (!queryResponse.isSuccessful()) {
terminal.printErrorMessage(queryResponse.getErrorMessage());
terminal.flush();
} else {
try (StatusClosable toClose = terminal.setStatusMessage("Press CTRL-C to interrupt")) {
final StreamPublisher<StreamedRow> publisher = queryResponse.getResponse();
final CompletableFuture<Void> future = new CompletableFuture<>();
final QueryStreamSubscriber subscriber = new QueryStreamSubscriber(publisher.getContext(), future);
publisher.subscribe(subscriber);
terminal.handle(Terminal.Signal.INT, signal -> {
terminal.handle(Terminal.Signal.INT, Terminal.SignalHandler.SIG_IGN);
subscriber.close();
future.complete(null);
});
try {
if (streamedQueryTimeoutMs != null) {
future.get(streamedQueryTimeoutMs, TimeUnit.MILLISECONDS);
} else {
future.get();
}
} catch (Exception e) {
LOGGER.error("Unexpected exception in waiting for query", e);
} finally {
terminal.writer().println("Query terminated");
terminal.flush();
publisher.close();
}
}
}
}
Aggregations