Update to TerminalConsoleAppender 1.1.0

Fixes a long-standing race condition in TerminalConsoleAppender,
that eventually resulted in IllegalStateExceptions or duplicate
input prompts.

Fixes #242, Fixes #188
This commit is contained in:
Minecrell 2018-07-06 23:00:08 +02:00 committed by Jamie Mansfield
parent 6a77c81ac1
commit 223b748b87
5 changed files with 85 additions and 133 deletions

View File

@ -1,5 +1,5 @@
From 86114fe2b34ce641430a7bbd18e6acb99b46101f Mon Sep 17 00:00:00 2001 From 5b28001ff643ac29ecd7f73d19689019a326c81d Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net> From: Minecrell <minecrell@minecrell.net>
Date: Fri, 22 Sep 2017 12:46:47 +0200 Date: Fri, 22 Sep 2017 12:46:47 +0200
Subject: [PATCH] Use Log4j2 for logging and TerminalConsoleAppender for Subject: [PATCH] Use Log4j2 for logging and TerminalConsoleAppender for
console console
@ -28,7 +28,7 @@ index ee76507c..e7bc7a5d 100644
</plugins> </plugins>
</build> </build>
diff --git a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java diff --git a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
index 2efe7211..3e719f6e 100644 index 2efe7211..f5270655 100644
--- a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java --- a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
+++ b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java +++ b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
@@ -57,6 +57,9 @@ public class BungeeCordLauncher @@ -57,6 +57,9 @@ public class BungeeCordLauncher
@ -36,7 +36,7 @@ index 2efe7211..3e719f6e 100644
if ( !options.has( "noconsole" ) ) if ( !options.has( "noconsole" ) )
{ {
+ // Waterfall start - Use TerminalConsoleAppender + // Waterfall start - Use TerminalConsoleAppender
+ io.github.waterfallmc.waterfall.console.WaterfallConsole.readCommands(); + new io.github.waterfallmc.waterfall.console.WaterfallConsole().start();
+ /* + /*
String line; String line;
while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null )
@ -52,10 +52,10 @@ index 2efe7211..3e719f6e 100644
} }
diff --git a/log4j/pom.xml b/log4j/pom.xml diff --git a/log4j/pom.xml b/log4j/pom.xml
new file mode 100644 new file mode 100644
index 00000000..e49c948f index 00000000..36fceb93
--- /dev/null --- /dev/null
+++ b/log4j/pom.xml +++ b/log4j/pom.xml
@@ -0,0 +1,64 @@ @@ -0,0 +1,48 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion>
@ -75,49 +75,33 @@ index 00000000..e49c948f
+ <name>Waterfall-Log</name> + <name>Waterfall-Log</name>
+ <description>Simplistic and performant Log4j2 based logger and console API designed for use with Waterfall and Minecraft related applications.</description> + <description>Simplistic and performant Log4j2 based logger and console API designed for use with Waterfall and Minecraft related applications.</description>
+ +
+ <properties>
+ <log4j2.version>2.11.0</log4j2.version>
+ </properties>
+
+ <dependencies> + <dependencies>
+ <!-- Log4j --> + <!-- Log4j -->
+ <dependency> + <dependency>
+ <groupId>org.apache.logging.log4j</groupId> + <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId> + <artifactId>log4j-core</artifactId>
+ <version>2.9.1</version> + <version>${log4j2.version}</version>
+ </dependency> + </dependency>
+ <dependency> + <dependency>
+ <groupId>org.apache.logging.log4j</groupId> + <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-iostreams</artifactId> + <artifactId>log4j-iostreams</artifactId>
+ <version>2.9.1</version> + <version>${log4j2.version}</version>
+ </dependency> + </dependency>
+ <dependency> + <dependency>
+ <groupId>org.apache.logging.log4j</groupId> + <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jul</artifactId> + <artifactId>log4j-jul</artifactId>
+ <version>2.9.1</version> + <version>${log4j2.version}</version>
+ </dependency> + </dependency>
+ <dependency> + <dependency>
+ <groupId>com.lmax</groupId> + <groupId>com.lmax</groupId>
+ <artifactId>disruptor</artifactId> + <artifactId>disruptor</artifactId>
+ <version>3.3.6</version> + <version>3.4.2</version>
+ <scope>runtime</scope> + <scope>runtime</scope>
+ </dependency> + </dependency>
+
+ <!-- Console improvements -->
+ <dependency>
+ <groupId>net.minecrell</groupId>
+ <artifactId>terminalconsoleappender</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>net.java.dev.jna</groupId>
+ <artifactId>jna</artifactId>
+ <version>4.4.0</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>io.github.waterfallmc</groupId>
+ <artifactId>waterfall-chat</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies> + </dependencies>
+</project> +</project>
diff --git a/log4j/src/main/java/io/github/waterfallmc/waterfall/log4j/Log4JLogHandler.java b/log4j/src/main/java/io/github/waterfallmc/waterfall/log4j/Log4JLogHandler.java diff --git a/log4j/src/main/java/io/github/waterfallmc/waterfall/log4j/Log4JLogHandler.java b/log4j/src/main/java/io/github/waterfallmc/waterfall/log4j/Log4JLogHandler.java
@ -261,7 +245,7 @@ index 79493df2..0183bf9c 100644
<module>protocol</module> <module>protocol</module>
<module>proxy</module> <module>proxy</module>
diff --git a/proxy/pom.xml b/proxy/pom.xml diff --git a/proxy/pom.xml b/proxy/pom.xml
index 03708968..bb15d274 100644 index 03708968..9f1b066e 100644
--- a/proxy/pom.xml --- a/proxy/pom.xml
+++ b/proxy/pom.xml +++ b/proxy/pom.xml
@@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
@ -273,8 +257,29 @@ index 03708968..bb15d274 100644
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -98,6 +98,20 @@
<version>5.1.46</version>
<scope>runtime</scope>
</dependency>
+
+ <!-- Waterfall start - Console improvements -->
+ <dependency>
+ <groupId>net.minecrell</groupId>
+ <artifactId>terminalconsoleappender</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>net.java.dev.jna</groupId>
+ <artifactId>jna</artifactId>
+ <version>4.5.2</version>
+ <scope>runtime</scope>
+ </dependency>
+ <!-- Waterfall end -->
</dependencies>
<build>
diff --git a/proxy/src/main/java/Test.java b/proxy/src/main/java/Test.java diff --git a/proxy/src/main/java/Test.java b/proxy/src/main/java/Test.java
index 446dfe2f..c3cb5aaa 100644 index 446dfe2f..f036efcd 100644
--- a/proxy/src/main/java/Test.java --- a/proxy/src/main/java/Test.java
+++ b/proxy/src/main/java/Test.java +++ b/proxy/src/main/java/Test.java
@@ -22,6 +22,9 @@ public class Test @@ -22,6 +22,9 @@ public class Test
@ -282,7 +287,7 @@ index 446dfe2f..c3cb5aaa 100644
bungee.start(); bungee.start();
+ // Waterfall start - Use TerminalConsoleAppender + // Waterfall start - Use TerminalConsoleAppender
+ io.github.waterfallmc.waterfall.console.WaterfallConsole.readCommands(); + new io.github.waterfallmc.waterfall.console.WaterfallConsole().start();
+ /* + /*
while ( bungee.isRunning ) while ( bungee.isRunning )
{ {
@ -297,100 +302,46 @@ index 446dfe2f..c3cb5aaa 100644
} }
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java
new file mode 100644 new file mode 100644
index 00000000..6cfe283a index 00000000..765d24bc
--- /dev/null --- /dev/null
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java +++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java
@@ -0,0 +1,93 @@ @@ -0,0 +1,39 @@
+package io.github.waterfallmc.waterfall.console; +package io.github.waterfallmc.waterfall.console;
+ +
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.BungeeCord;
+import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.ProxyServer;
+import net.minecrell.terminalconsole.TerminalConsoleAppender; +import net.md_5.bungee.api.chat.ComponentBuilder;
+import org.jline.reader.EndOfFileException; +import net.minecrell.terminalconsole.SimpleTerminalConsole;
+import org.jline.reader.LineReader; +import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder; +import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.UserInterruptException;
+import org.jline.terminal.Terminal;
+ +
+import java.io.BufferedReader; +public final class WaterfallConsole extends SimpleTerminalConsole {
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+ +
+public final class WaterfallConsole { + @Override
+ + protected LineReader buildReader(LineReaderBuilder builder) {
+ private static final Executor executor = Executors.newSingleThreadExecutor( + ProxyServer proxy = ProxyServer.getInstance();
+ new ThreadFactoryBuilder().setNameFormat( "Console Command Thread #%d" ).build()); + return super.buildReader(builder
+ + .appName(proxy.getName())
+ public static void readCommands() throws IOException { + );
+ Terminal terminal = TerminalConsoleAppender.getTerminal();
+ if (terminal != null) {
+ readCommands(terminal);
+ } else {
+ readCommands(System.in);
+ }
+ } + }
+ +
+ private static void runCommand(String input) { + @Override
+ final String command = input.trim(); + protected boolean isRunning() {
+ if (command.isEmpty()) { + return BungeeCord.getInstance().isRunning;
+ return;
+ } + }
+ +
+ executor.execute(() -> { + @Override
+ protected void runCommand(String command) {
+ ProxyServer proxy = ProxyServer.getInstance(); + ProxyServer proxy = ProxyServer.getInstance();
+ if (!proxy.getPluginManager().dispatchCommand(proxy.getConsole(), command)) { + if (!proxy.getPluginManager().dispatchCommand(proxy.getConsole(), command)) {
+ proxy.getConsole().sendMessage(ChatColor.RED + "Command not found"); + proxy.getConsole().sendMessage(new ComponentBuilder("Command not found").color(ChatColor.RED).create());
+ } + }
+ });
+ } + }
+ +
+ private static void readCommands(Terminal terminal) throws IOException { + @Override
+ final BungeeCord bungee = BungeeCord.getInstance(); + protected void shutdown() {
+ final LineReader reader = LineReaderBuilder.builder()
+ .appName(ProxyServer.getInstance().getName())
+ .terminal(terminal)
+ .build();
+ reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION);
+ reader.unsetOpt(LineReader.Option.INSERT_TAB);
+
+ TerminalConsoleAppender.setReader(reader);
+
+ try {
+ String line;
+ while (bungee.isRunning) {
+ try {
+ line = reader.readLine("> ");
+ } catch (EndOfFileException ignored) {
+ // Continue reading after EOT
+ continue;
+ }
+
+ if (line == null) {
+ break;
+ }
+
+ runCommand(line);
+ }
+ } catch (UserInterruptException e) {
+ ProxyServer.getInstance().stop(); + ProxyServer.getInstance().stop();
+ } finally {
+ TerminalConsoleAppender.setReader(null);
+ }
+ }
+
+ private static void readCommands(InputStream in) throws IOException {
+ final BungeeCord bungee = BungeeCord.getInstance();
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
+ String line;
+ while (bungee.isRunning && (line = reader.readLine()) != null) {
+ runCommand(line);
+ }
+ }
+ } + }
+ +
+} +}

View File

@ -1,5 +1,5 @@
From cc1216e4ae16ecc16b06b848ddea7c1a15834b8b Mon Sep 17 00:00:00 2001 From cc1216e4ae16ecc16b06b848ddea7c1a15834b8b Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net> From: Minecrell <minecrell@minecrell.net>
Date: Fri, 22 Sep 2017 13:07:31 +0200 Date: Fri, 22 Sep 2017 13:07:31 +0200
Subject: [PATCH] Handle plugin prefixes using Log4J Subject: [PATCH] Handle plugin prefixes using Log4J

View File

@ -1,11 +1,11 @@
From 8d7700a5ef39cf148965e355adafccd27a02900a Mon Sep 17 00:00:00 2001 From b77cc41ce6d472939205d2795e04769ae01d94fc Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net> From: Minecrell <minecrell@minecrell.net>
Date: Fri, 22 Sep 2017 13:15:09 +0200 Date: Fri, 22 Sep 2017 13:15:09 +0200
Subject: [PATCH] Allow plugins to use SLF4J for logging Subject: [PATCH] Allow plugins to use SLF4J for logging
diff --git a/api/pom.xml b/api/pom.xml diff --git a/api/pom.xml b/api/pom.xml
index 2a3c5eae..25d870d1 100644 index 48bd8a54..0e46cbbe 100644
--- a/api/pom.xml --- a/api/pom.xml
+++ b/api/pom.xml +++ b/api/pom.xml
@@ -43,5 +43,12 @@ @@ -43,5 +43,12 @@
@ -39,21 +39,22 @@ index e85b4914..2e5ae4fb 100644
* Called when the plugin has just been loaded. Most of the proxy will not * Called when the plugin has just been loaded. Most of the proxy will not
* be initialized, so only use it for registering * be initialized, so only use it for registering
diff --git a/log4j/pom.xml b/log4j/pom.xml diff --git a/log4j/pom.xml b/log4j/pom.xml
index 78045e1d..d078cd68 100644 index 36fceb93..a085a39c 100644
--- a/log4j/pom.xml --- a/log4j/pom.xml
+++ b/log4j/pom.xml +++ b/log4j/pom.xml
@@ -34,6 +34,11 @@ @@ -38,6 +38,12 @@
<artifactId>log4j-jul</artifactId> <artifactId>log4j-jul</artifactId>
<version>2.9.1</version> <version>${log4j2.version}</version>
</dependency> </dependency>
+ <dependency> + <dependency>
+ <groupId>org.apache.logging.log4j</groupId> + <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId> + <artifactId>log4j-slf4j-impl</artifactId>
+ <version>2.9.1</version> + <version>${log4j2.version}</version>
+ <scope>runtime</scope>
+ </dependency> + </dependency>
<dependency> <dependency>
<groupId>com.lmax</groupId> <groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId> <artifactId>disruptor</artifactId>
-- --
2.14.1 2.18.0

View File

@ -1,5 +1,5 @@
From 0945d31d4f5b083d5d1177fb9b916f154e6968f5 Mon Sep 17 00:00:00 2001 From 11629f33a3756606d47546784605aa3a7ae7fb41 Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net> From: Minecrell <minecrell@minecrell.net>
Date: Sun, 24 Sep 2017 12:06:49 +0200 Date: Sun, 24 Sep 2017 12:06:49 +0200
Subject: [PATCH] Add Log4j configuration that replicates the old BungeeCord Subject: [PATCH] Add Log4j configuration that replicates the old BungeeCord
setup setup

View File

@ -1,5 +1,5 @@
From 4f89985a92b0dc63f3a7467b77c421b69d52aff8 Mon Sep 17 00:00:00 2001 From 056c5b8f8853c5e0471fa0f88b5fe18c58cd9345 Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net> From: Minecrell <minecrell@minecrell.net>
Date: Tue, 26 Sep 2017 18:59:37 +0200 Date: Tue, 26 Sep 2017 18:59:37 +0200
Subject: [PATCH] Add console command completion Subject: [PATCH] Add console command completion
@ -90,17 +90,17 @@ index 00000000..bfcb6e9f
+ +
+} +}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java
index 6cfe283a..31967d7d 100644 index 765d24bc..6cec0b5a 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java --- a/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java +++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/console/WaterfallConsole.java
@@ -51,6 +51,7 @@ public final class WaterfallConsole { @@ -15,6 +15,7 @@ public final class WaterfallConsole extends SimpleTerminalConsole {
final LineReader reader = LineReaderBuilder.builder() ProxyServer proxy = ProxyServer.getInstance();
.appName(ProxyServer.getInstance().getName()) return super.buildReader(builder
.terminal(terminal) .appName(proxy.getName())
+ .completer(new ConsoleCommandCompleter(bungee)) + .completer(new ConsoleCommandCompleter(proxy))
.build(); );
reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION); }
reader.unsetOpt(LineReader.Option.INSERT_TAB);
-- --
2.18.0 2.18.0