From 285d6ab9a4f167406fc77982d6d3bbabf7e3b953 Mon Sep 17 00:00:00 2001 From: Manevolent Date: Thu, 6 Sep 2018 11:53:44 -0400 Subject: [PATCH] Add setEventMultiThreading(boolean) instead of forcing multi-threading on --- .../client/LocalTeamspeakClientSocket.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index c44c28e..520e11a 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -41,7 +41,7 @@ public class LocalTeamspeakClientSocket private final DatagramPacket packet = new DatagramPacket(new byte[500], 500); private final Map namedProcessors = new HashMap<>(); - private final ExecutorService commandExecutionService = Executors.newSingleThreadExecutor(); + private ExecutorService commandExecutionService = Executors.newSingleThreadExecutor(); private final Object commandSendLock = new Object(); private volatile InetSocketAddress remote; @@ -141,6 +141,26 @@ public class LocalTeamspeakClientSocket }); } + public void setCommandExecutorService(ExecutorService executorService) { + this.commandExecutionService = executorService; + } + + /** + * Enables or disables event callback multi-threading. This is dangerous. If this is enabled, events can be + * processed out-of-order. It is suggested you use your own threading system for particular events you feel safe + * parallelling, such as chat messages. + * + * This is not enabled by default. + * + * @param enabled Event simultaneous (parallel) processing enabled + */ + public void setEventMultiThreading(boolean enabled) { + if (enabled) + setCommandExecutorService(Executors.newCachedThreadPool()); + else + setCommandExecutorService(Executors.newSingleThreadExecutor()); + } + public void addListener(TS3Listener listener) { this.listeners.add(listener); }