From d6a0f25adca3cb30db4746fc1cb561d10e535df7 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 24 Apr 2019 09:51:57 -0400 Subject: [PATCH 1/2] Several fixes: - STOP renamed to KILL - Fixed status label at the end to TERMINATED - Changed code to better diff between stop and kill - Automatically scroll to the end when a tab is selected - Avoid refreshing consoles when the text didn't change (was clearing selection) - Keep the caret position where the user wants if it is placed within the text area - Autoscroll if the user places the caret at the end --- .../org/terracotta/tinypounder/ProcUtils.java | 4 +- .../terracotta/tinypounder/RunningServer.java | 14 ++--- .../tinypounder/TinyPounderMainUI.java | 62 ++++++++++++------- src/main/resources/banner.txt | 2 +- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/terracotta/tinypounder/ProcUtils.java b/src/main/java/org/terracotta/tinypounder/ProcUtils.java index 95b87f9..e4e5c33 100644 --- a/src/main/java/org/terracotta/tinypounder/ProcUtils.java +++ b/src/main/java/org/terracotta/tinypounder/ProcUtils.java @@ -17,7 +17,7 @@ public class ProcUtils { private static String OS = System.getProperty("os.name").toLowerCase(); - static AnyProcess run(File workDir, String command, Queue consoleLines, Consumer onNewLine, Runnable onStop) { + static AnyProcess run(File workDir, String command, Queue consoleLines, Consumer onNewLine, Runnable onTerminated) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final OutputStream out = new OutputStream() { @Override @@ -53,7 +53,7 @@ public void write(int b) throws IOException { } catch (InterruptedException e) { Thread.currentThread().interrupt(); } - onStop.run(); + onTerminated.run(); }, "Process (" + command + ")"); waiter.setDaemon(true); waiter.start(); diff --git a/src/main/java/org/terracotta/tinypounder/RunningServer.java b/src/main/java/org/terracotta/tinypounder/RunningServer.java index 39c242f..4411ccf 100644 --- a/src/main/java/org/terracotta/tinypounder/RunningServer.java +++ b/src/main/java/org/terracotta/tinypounder/RunningServer.java @@ -22,23 +22,23 @@ class RunningServer { private final String serverName; private final TextArea console; private final ArrayBlockingQueue lines; - private final Runnable onStop; + private final Runnable onTerminated; private final Consumer onState; private final Consumer onPID; private long pid; - RunningServer(File workDir, File stripeconfig, String serverName, TextArea console, int maxLines, Runnable onStop, Consumer onState, Consumer onPID) { + RunningServer(File workDir, File stripeconfig, String serverName, TextArea console, int maxLines, Runnable onTerminated, Consumer onState, Consumer onPID) { this.workDir = workDir; this.stripeconfig = stripeconfig; this.serverName = serverName; this.lines = new ArrayBlockingQueue<>(maxLines); this.console = console; - this.onStop = onStop; + this.onTerminated = onTerminated; this.onState = onState; this.onPID = onPID; } - void stop() { + void kill() { try { ProcUtils.kill(pid); } catch (InterruptedException e) { @@ -73,13 +73,11 @@ void start() { } } }, - onStop); + onTerminated); } void refreshConsole() { - String text = String.join("", lines); - console.setValue(text); - console.setCursorPosition(text.length()); + TinyPounderMainUI.updateTextArea(console, lines); } } diff --git a/src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java b/src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java index 780ffd1..dd47b5e 100644 --- a/src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java +++ b/src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java @@ -57,10 +57,12 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -181,7 +183,7 @@ private void addExitCloseTab() { mainLayout.addSelectedTabChangeListener(tabEvent -> { if (tabEvent.getTabSheet().getSelectedTab().equals(tab.getComponent())) { new Thread(() -> { - runningServers.values().forEach(RunningServer::stop); + runningServers.values().forEach(RunningServer::kill); consoleRefresher.cancel(true); SpringApplication.exit(appContext); }).start(); @@ -355,7 +357,7 @@ private void addVoltronCommandsControls() { Button clusterStopBtn = new Button(); clusterStopBtn.addStyleName("align-bottom"); clusterStopBtn.setCaption("Stop cluster"); - clusterStopBtn.setData("stop"); + clusterStopBtn.setData("stop-cluster"); clusterStopBtn.addClickListener((Button.ClickListener) this::executeClusterToolCommand); row1.addComponents(clusterNameTF, clusterConfigBtn, clusterReConfigBtn, clusterBackupBtn, clusterDumpBtn, clusterStopBtn, clusterStatusBtn); @@ -364,7 +366,13 @@ private void addVoltronCommandsControls() { voltronControlLayout.addComponentsAndExpand(row1); consoles = new TabSheet(); + consoles.addSelectedTabChangeListener((TabSheet.SelectedTabChangeListener) event -> { + TextArea textArea = (TextArea) event.getTabSheet().getSelectedTab(); + textArea.setCursorPosition(textArea.getValue().length()); + }); + mainConsole = addConsole("Main", "main"); + voltronControlLayout.addComponentsAndExpand(consoles); } @@ -405,7 +413,7 @@ private void executeClusterToolCommand(Button.ClickEvent event) { case "dump": case "status": case "backup": - case "stop": { + case "stop-cluster": { ProcUtils.run( workDir, script + " " + command + " -n " + clusterNameTF.getValue() + " " + hostPortList.stream().collect(Collectors.joining(" ")), @@ -439,9 +447,7 @@ private String getHostPortFromServerName(String serverName) { } private void updateMainConsole(Queue consoleLines) { - String text = String.join("", consoleLines); - mainConsole.setValue(text); - mainConsole.setCursorPosition(text.length()); + updateTextArea(mainConsole, consoleLines); } private TextArea addConsole(String title, String key) { @@ -484,12 +490,12 @@ private void updateServerControls() { startBT.setStyleName("align-top"); serverControls.addComponent(startBT); - Button stopBT = new Button(); - stopBT.setEnabled(false); - stopBT.setCaption("STOP"); - stopBT.setStyleName("align-top"); - stopBT.setData(serverName); - serverControls.addComponent(stopBT); + Button killBT = new Button(); + killBT.setEnabled(false); + killBT.setCaption("KILL"); + killBT.setStyleName("align-top"); + killBT.setData(serverName); + serverControls.addComponent(killBT); Button statusBT = new Button(); statusBT.setEnabled(false); @@ -507,10 +513,10 @@ private void updateServerControls() { addConsole(serverName, stripeName + "-" + serverName); startBT.addClickListener((Button.ClickListener) event -> { - startServer(stripeName, (String) event.getButton().getData(), startBT, stopBT, statusBT, state, pid); + startServer(stripeName, (String) event.getButton().getData(), startBT, killBT, statusBT, state, pid); }); - stopBT.addClickListener((Button.ClickListener) event -> { - stopServer(stripeName, (String) event.getButton().getData(), stopBT, statusBT); + killBT.addClickListener((Button.ClickListener) event -> { + killServer(stripeName, (String) event.getButton().getData(), killBT, statusBT); }); statusBT.addClickListener((Button.ClickListener) this::executeClusterToolCommand); } @@ -550,17 +556,17 @@ private List getServerNameList() { return servers; } - private void stopServer(String stripeName, String serverName, Button stopBT, Button statusBT) { + private void killServer(String stripeName, String serverName, Button killBT, Button statusBT) { RunningServer runningServer = runningServers.get(stripeName + "-" + serverName); if (runningServer != null) { - runningServer.stop(); - stopBT.setEnabled(false); + runningServer.kill(); + killBT.setEnabled(false); statusBT.setEnabled(false); runningServer.refreshConsole(); } } - private void startServer(String stripeName, String serverName, Button startBT, Button stopBT, Button statusBT, Label stateLBL, Label pidLBL) { + private void startServer(String stripeName, String serverName, Button startBT, Button killBT, Button statusBT, Label stateLBL, Label pidLBL) { File stripeconfig = tcConfigLocationPerStripe.get(stripeName); if (stripeconfig == null) { generateXML(false); @@ -576,11 +582,11 @@ private void startServer(String stripeName, String serverName, Button startBT, B () -> { runningServers.remove(key); access(() -> { - stopBT.setEnabled(false); + killBT.setEnabled(false); statusBT.setEnabled(false); startBT.setEnabled(true); pidLBL.setValue(""); - stateLBL.setValue("STOPPED"); + stateLBL.setValue("TERMINATED"); }); }, newState -> access(() -> stateLBL.setValue("STATE: " + newState)), @@ -596,7 +602,7 @@ private void startServer(String stripeName, String serverName, Button startBT, B stateLBL.setValue("STARTING"); runningServer.start(); startBT.setEnabled(false); - stopBT.setEnabled(true); + killBT.setEnabled(true); statusBT.setEnabled(true); runningServer.refreshConsole(); } @@ -1639,6 +1645,7 @@ private void addClientSecurityControls() { clientSecurityLayout.addComponent(clientSecurityControls); } + private void addDatasetManagerControls() { datasetManagerControls = new VerticalLayout(); @@ -1982,5 +1989,16 @@ private static String getVersion() { return v == null ? "dev" : v; } + static void updateTextArea(TextArea textArea, Collection lines) { + synchronized (textArea) { + String text = String.join("", lines); + if (!Objects.equals(textArea.getValue(), text)) { + int position = textArea.getCursorPosition(); + boolean autoscroll = position >= textArea.getValue().length() - 1; + textArea.setValue(text); + textArea.setCursorPosition(autoscroll ? text.length() : Math.min(position, text.length())); + } + } + } } \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index 336963c..ff5878c 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -5,4 +5,4 @@ /_/ /_/_/ /_/\__, / /_/ \____/\__,_/_/ /_/\__,_/\___/_/ /____/ -Please don't use quotes around it ! \ No newline at end of file +Please don't use quotes around it ! From 22dd8f1be183a85e5921ab72ae3ffb8695301aaa Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 24 Apr 2019 09:55:56 -0400 Subject: [PATCH 2/2] Prepare next version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f007d78..03f9179 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.terracotta tinypounder - 1.1.1 + 1.2.0 jar tinypounder