Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

import org.apache.activemq.artemis.cli.commands.ActionContext;
import org.apache.activemq.artemis.cli.commands.Connect;
import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract;
import org.jline.console.SystemRegistry;
Expand Down Expand Up @@ -101,7 +102,17 @@ public static void runShell(boolean printBanner) {
PicocliCommands picocliCommands = new PicocliCommands(commandLine);

Parser parser = new DefaultParser();
try (Terminal terminal = TerminalBuilder.terminal()) {
try (Terminal terminal = TerminalBuilder.builder()
.nativeSignals(true)
.build()) {
// Capture the main shell thread for signal handling
Thread shellThread = Thread.currentThread();

// Handle CTRL-C by interrupting the shell thread
terminal.handle(Terminal.Signal.INT, signal -> {
System.out.println("\n....Interrupted by the user.");
shellThread.interrupt();
});
SystemRegistry systemRegistry = new SystemRegistryImpl(parser, terminal, workDir, null);
systemRegistry.setCommandRegistries(picocliCommands);
systemRegistry.register("help", picocliCommands);
Expand All @@ -113,6 +124,9 @@ public static void runShell(boolean printBanner) {
.variable(LineReader.LIST_MAX, 50) // max tab completion candidates
.build();
factory.setTerminal(terminal);
if (ActionContext.system() != null) {
ActionContext.system().lineReader = reader;
}

String rightPrompt = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.InputStream;
import java.io.PrintStream;

import org.jline.reader.LineReader;

public class ActionContext {

public ActionContext(InputStream in, PrintStream out, PrintStream err) {
Expand All @@ -34,6 +36,7 @@ public ActionContext() {
public InputStream in;
public PrintStream out;
public PrintStream err;
public LineReader lineReader;

private static ThreadLocal<ActionContext> contextThreadLocal = ThreadLocal.withInitial(() -> new ActionContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,70 @@

package org.apache.activemq.artemis.cli.commands;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

import org.jline.reader.LineReader;
import picocli.CommandLine.Option;

public class InputAbstract extends ActionAbstract {

private Scanner scanner;
public interface InputReader {
String readLine(String prompt);
String readPassword(String prompt);
}

private class ScanReader implements InputReader {
ScanReader(InputStream inputStream, PrintStream promptStream) {
this.scanner = new Scanner(inputStream);
this.promptStream = promptStream;
}

Scanner scanner;
PrintStream promptStream;


@Override
public String readLine(String prompt) {
promptStream.println(prompt);
return scanner.nextLine();
}

@Override
public String readPassword(String prompt) {
promptStream.println(prompt);
char[] typedPassword = System.console().readPassword();
if (typedPassword == null) {
return null;
} else {
return new String(typedPassword);
}
}
}


private class JLineReader implements InputReader {
JLineReader(LineReader reader) {
this.reader = reader;
}

public LineReader reader;

@Override
public String readLine(String prompt) {
return reader.readLine(prompt);
}

@Override
public String readPassword(String prompt) {
return reader.readLine(prompt, '*');
}
}


InputReader lineReader;


private static boolean inputEnabled = false;

Expand Down Expand Up @@ -101,8 +158,8 @@ protected String input(String propertyName, String prompt, String silentDefault,
getActionContext().out.println();
do {
getActionContext().out.println(propertyName + ":");
getActionContext().out.println(prompt);
inputStr = scanner.nextLine();
inputStr = lineReader.readLine(prompt);

if (!acceptNull && inputStr.trim().isEmpty()) {
getActionContext().out.println("Invalid Entry!");
} else {
Expand All @@ -124,17 +181,14 @@ protected String inputPassword(String propertyName, String prompt, String silent
getActionContext().out.println();
do {
getActionContext().out.println(propertyName + ": is mandatory with this configuration:");
getActionContext().out.println(prompt);
char[] chars = System.console().readPassword();
inputStr = lineReader.readPassword(prompt + "\n");

// could be null if the user input something weird like Ctrl-d
if (chars == null) {
if (inputStr == null) {
getActionContext().out.println("Invalid Entry!");
continue;
}

inputStr = new String(chars);

if (inputStr.trim().isEmpty()) {
getActionContext().out.println("Invalid Entry!");
} else {
Expand All @@ -150,7 +204,11 @@ protected String inputPassword(String propertyName, String prompt, String silent
public Object execute(ActionContext context) throws Exception {
super.execute(context);

this.scanner = new Scanner(context.in);
if (context.lineReader != null) {
this.lineReader = new JLineReader(context.lineReader);
} else {
this.lineReader = new ScanReader(context.in, context.out);
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,29 @@ public Object execute(ActionContext context) throws Exception {

long received = 0;

for (ConsumerThread thread : threadsArray) {
thread.join();
received += thread.getReceived();
try {
for (ConsumerThread thread : threadsArray) {
thread.join();
received += thread.getReceived();
}
} catch (InterruptedException e) {
// Interrupt any sub threads if an interrupt is captured
for (Thread t : threadsArray) t.interrupt();
throw e;
}

if (serializer != null) {
serializer.stop();
}
return received;
} finally {
try {
if (serializer != null) {
serializer.stop();
}

if (outputStream != null) {
outputStream.close();
if (outputStream != null) {
outputStream.close();
}
} catch (Throwable ignored) {
}

return received;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,17 @@ public Object execute(ActionContext context) throws Exception {
}

long messagesProduced = 0;
for (ProducerThread thread : threadsArray) {
thread.join();
messagesProduced += thread.getSentCount();
try {
for (ProducerThread thread : threadsArray) {
thread.join();
messagesProduced += thread.getSentCount();
}
return messagesProduced;
} catch (InterruptedException e) {
// Interrupt any sub threads if an interrupt is captured
for (Thread t : threadsArray) t.interrupt();
throw e;
}
return messagesProduced;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/user-manual/versions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12315920&versio
* https://issues.apache.org/jira/browse/ARTEMIS-5925[ARTEMIS-5925] - The Lock coordinator can now be applied to broker connections, supporting "Star Mirror" for enhanced HA topologies
* https://issues.apache.org/jira/browse/ARTEMIS-5946[ARTEMIS-5946] - Update to Artemis Console 1.7.0
* https://issues.apache.org/jira/browse/ARTEMIS-5941[ARTEMIS-5941] - Route wildcard subscriptions direct to demand bindings for improved performance
* https://issues.apache.org/jira/browse/ARTEMIS-5941[ARTEMIS-5951] - CTRL-C is now properly handled on 'artemis shell'

== Version 2.52.0

Expand Down
Loading