From 94a95de4957947c6bdf74b729d0a9f199bf27bb5 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sun, 6 Jan 2019 01:58:13 -0500 Subject: [PATCH] Name SubServers threads This change does not apply to SubServers.Client because those apps use the platform's native scheduler instead of threads --- .../SubServers/Bungee/Host/External/ExternalSubServer.java | 2 +- .../SubServers/Bungee/Host/Internal/InternalHost.java | 4 ++-- .../SubServers/Bungee/Host/Internal/InternalSubCreator.java | 1 + .../SubServers/Bungee/Host/Internal/InternalSubLogger.java | 4 ++-- .../SubServers/Bungee/Host/Internal/InternalSubServer.java | 4 ++-- .../src/net/ME1312/SubServers/Bungee/Library/Metrics.java | 2 +- .../src/net/ME1312/SubServers/Bungee/Network/Client.java | 4 ++-- .../Bungee/Network/Packet/PacketCreateServer.java | 2 +- .../src/net/ME1312/SubServers/Bungee/SubCommand.java | 2 +- .../src/net/ME1312/SubServers/Bungee/SubPlugin.java | 6 +++--- SubServers.Host/pom.xml | 2 +- SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java | 3 ++- .../net/ME1312/SubServers/Host/Executable/SubCreator.java | 2 ++ .../net/ME1312/SubServers/Host/Executable/SubLogger.java | 4 ++-- .../net/ME1312/SubServers/Host/Executable/SubServer.java | 3 ++- .../src/net/ME1312/SubServers/Host/Library/Metrics.java | 3 ++- .../Host/Network/Packet/PacketExDeleteServer.java | 3 ++- .../net/ME1312/SubServers/Host/Network/SubDataClient.java | 4 ++-- .../src/net/ME1312/SubServers/Sync/Library/Metrics.java | 2 +- .../net/ME1312/SubServers/Sync/Network/SubDataClient.java | 4 ++-- .../src/net/ME1312/SubServers/Sync/SubCommand.java | 2 +- .../src/net/ME1312/SubServers/Sync/SubPlugin.java | 2 +- 22 files changed, 36 insertions(+), 29 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java index 90e45db1..dcdaf2d9 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java @@ -138,7 +138,7 @@ public class ExternalSubServer extends SubServerContainer { } catch (InterruptedException e) { e.printStackTrace(); } - }).start(); + }, "SubServers.Bungee::External_Server_Restart_Handler(" + getName() + ')').start(); } } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java index 025ec7e3..0e6bd753 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java @@ -183,7 +183,7 @@ public class InternalHost extends Host { e.printStackTrace(); } System.out.println("SubServers > Deleted SubServer: " + server); - }).start(); + }, "SubServers.Bungee::Internal_Server_Deletion(" + name + ')').start(); return true; } else return false; } @@ -228,7 +228,7 @@ public class InternalHost extends Host { e.printStackTrace(); } System.out.println("SubServers > Deleted SubServer: " + server); - }).start(); + }, "SubServers.Bungee::Internal_Server_Deletion(" + name + ')').start(); return true; } else return false; } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java index 2b3a325c..dfef7c78 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java @@ -49,6 +49,7 @@ public class InternalSubCreator extends SubCreator { private Process process; private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Callback callback) { + super("SubServers.Bungee::Internal_SubCreator_Process_Handler(" + name + ')'); this.player = player; this.name = name; this.template = template; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java index 113b8b65..7895d169 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java @@ -61,8 +61,8 @@ public class InternalSubLogger extends SubLogger { e.printStackTrace(); } } - if (out == null) (out = new Thread(() -> start(process.getInputStream(), false))).start(); - if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true))).start(); + if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), "SubServers.Bungee::Internal_Log_Spooler(" + name + ')')).start(); + if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), "SubServers.Bungee::Internal_Error_Spooler(" + name + ')')).start(); List filters = new ArrayList(); filters.addAll(this.filters); for (SubLogFilter filter : filters) try { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index 029daf2d..35a13d63 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -172,7 +172,7 @@ public class InternalSubServer extends SubServerContainer { } catch (InterruptedException e) { e.printStackTrace(); } - }).start(); + }, "SubServers.Bungee::Internal_Server_Restart_Handler(" + getName() + ')').start(); } } } @@ -185,7 +185,7 @@ public class InternalSubServer extends SubServerContainer { host.plugin.getPluginManager().callEvent(event); lock = false; if (!event.isCancelled()) { - (thread = new Thread(this::run)).start(); + (thread = new Thread(this::run, "SubServers.Bungee::Internal_Server_Process_Handler(" + getName() + ')')).start(); return true; } else return false; } else return false; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Metrics.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Metrics.java index d5e9b63f..9ad8dfdd 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Metrics.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Metrics.java @@ -150,7 +150,7 @@ public class Metrics { } private void startSubmitting() { - new Timer().schedule( new TimerTask() { + new Timer("SubServers.Bungee::Metrics_Uploader").schedule( new TimerTask() { @Override public void run() { // The data collection is async, as well as sending the data diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java index 3a22d66b..cebe2e2f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java @@ -43,7 +43,7 @@ public class Client { socket = client; out = MessagePack.newDefaultPacker(client.getOutputStream()); address = new InetSocketAddress(client.getInetAddress(), client.getPort()); - authorized = new Timer(); + authorized = new Timer("SubServers.Bungee::SubData_Authorization_Timeout(" + address.toString() + ')'); authorized.schedule(new TimerTask() { @Override public void run() { @@ -81,7 +81,7 @@ public class Client { e1.printStackTrace(); } } - }).start(); + }, "SubServers.Bungee::SubData_Packet_Listener(" + address.toString() + ')').start(); } private void recievePacket(Value input) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCreateServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCreateServer.java index 7ef23106..ebca040e 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCreateServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCreateServer.java @@ -82,7 +82,7 @@ public class PacketCreateServer implements PacketIn, PacketOut { } catch (InterruptedException e) { e.printStackTrace(); } - }).start(); + }, "SubServers.Bungee::SubData_SubCreator_Handler(" + client.getAddress().toString() + ')').start(); } else { client.sendPacket(new PacketCreateServer(0, "Creating SubServer", (data.contains("id")) ? data.getRawString("id") : null)); } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index e0b09c17..8d96156a 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -115,7 +115,7 @@ public final class SubCommand extends CommandX { sender.sendMessage("SubServers.Bungee v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind."); } } catch (Exception e) {} - }).start(); + }, "SubServers.Bungee::Update_Check").start(); } else if (args[0].equalsIgnoreCase("reload")) { if (args.length > 1) { switch (args[1].toLowerCase()) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java index bfc662c4..ba7aa260 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java @@ -396,7 +396,7 @@ public final class SubPlugin extends BungeeCord implements Listener { e.printStackTrace(); } } - })); + }, "SubServers.Bungee::System_Shutdown")); running = true; List autorun = new LinkedList(); for (String name : config.get().getSection("Servers").getKeys()) { @@ -544,7 +544,7 @@ public final class SubPlugin extends BungeeCord implements Listener { getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get()); new Metrics(this); - new Timer().schedule(new TimerTask() { + new Timer("SubServers.Bungee::Routine_Update_Check").schedule(new TimerTask() { @SuppressWarnings("unchecked") @Override public void run() { @@ -577,7 +577,7 @@ public final class SubPlugin extends BungeeCord implements Listener { if (!(e instanceof SocketException)) e.printStackTrace(); } } - }).start(); + }, "SubServers.Bungee::SubData_Connection_Listener").start(); } /** diff --git a/SubServers.Host/pom.xml b/SubServers.Host/pom.xml index 98240639..b118a24f 100644 --- a/SubServers.Host/pom.xml +++ b/SubServers.Host/pom.xml @@ -20,7 +20,7 @@ net.ME1312.Galaxi GalaxiEngine - 19w01a + 19w02c compile diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java index b03ab5e5..f7f45238 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java @@ -4,6 +4,7 @@ import com.dosse.upnp.UPnP; import net.ME1312.Galaxi.Engine.GalaxiEngine; import net.ME1312.Galaxi.Engine.GalaxiOption; import net.ME1312.Galaxi.Event.GalaxiReloadEvent; +import net.ME1312.Galaxi.Galaxi; import net.ME1312.Galaxi.Library.Config.YAMLConfig; import net.ME1312.Galaxi.Library.Config.YAMLSection; import net.ME1312.Galaxi.Library.Log.Logger; @@ -213,7 +214,7 @@ public final class ExHost { log.warn.println("Received request from system to shutdown"); engine.stop(); } - })); + }, SubAPI.getInstance().getAppInfo().getName() + "::System_Shutdown")); creator = new SubCreator(this); loadDefaults(); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreator.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreator.java index b7e5cd25..5d336707 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreator.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreator.java @@ -14,6 +14,7 @@ import net.ME1312.SubServers.Host.Network.API.SubCreator.ServerType; import net.ME1312.SubServers.Host.Network.Packet.PacketExCreateServer; import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage; import net.ME1312.SubServers.Host.ExHost; +import net.ME1312.SubServers.Host.SubAPI; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -190,6 +191,7 @@ public class SubCreator { private Process process; private CreatorTask(String name, ServerTemplate template, Version version, int port, UUID address, String id) { + super(SubAPI.getInstance().getAppInfo().getName() + "::SubCreator_Process_Handler(" + name + ')'); this.name = name; this.template = template; this.version = version; diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLogger.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLogger.java index ca7e4a59..4e17890a 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLogger.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLogger.java @@ -63,8 +63,8 @@ public class SubLogger { logger.error.println(e); } } - if (out == null) (out = new Thread(() -> start(process.getInputStream(), false))).start(); - if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true))).start(); + if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), SubAPI.getInstance().getAppInfo().getName() + "::Log_Spooler(" + name + ')')).start(); + if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start(); } diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java index 61014040..dbb256fb 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java @@ -7,6 +7,7 @@ import net.ME1312.Galaxi.Library.Version.Version; import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Host.Network.Packet.PacketExUpdateServer; import net.ME1312.SubServers.Host.ExHost; +import net.ME1312.SubServers.Host.SubAPI; import java.io.*; import java.util.LinkedList; @@ -141,7 +142,7 @@ public class SubServer { public void start(UUID address) { if (isEnabled() && !(thread != null && thread.isAlive())) { logger.address = address; - (thread = new Thread(this::run)).start(); + (thread = new Thread(this::run, SubAPI.getInstance().getAppInfo().getName() + "::Server_Process_Handler(" + name + ')')).start(); } } diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Metrics.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Metrics.java index 49752ed0..56c60400 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Metrics.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Metrics.java @@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Config.YAMLConfig; import net.ME1312.Galaxi.Library.Config.YAMLSection; import net.ME1312.Galaxi.Library.Log.Logger; import net.ME1312.SubServers.Host.ExHost; +import net.ME1312.SubServers.Host.SubAPI; import org.json.JSONArray; import org.json.JSONObject; @@ -144,7 +145,7 @@ public class Metrics { * Starts the Scheduler which submits our data every 30 minutes. */ private void startSubmitting() { - final Timer timer = new Timer(true); + final Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Metrics_Uploader", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java index 2779464c..373cb12d 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java @@ -12,6 +12,7 @@ import net.ME1312.SubServers.Host.Network.PacketIn; import net.ME1312.SubServers.Host.Network.PacketOut; import net.ME1312.SubServers.Host.Network.SubDataClient; import net.ME1312.SubServers.Host.ExHost; +import net.ME1312.SubServers.Host.SubAPI; import java.io.File; import java.io.FileWriter; @@ -106,7 +107,7 @@ public class PacketExDeleteServer implements PacketIn, PacketOut { if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort())) UPnP.closePortTCP(server.getPort()); log.info.println("Deleted SubServer: " + data.getRawString("server")); host.subdata.sendPacket(new PacketExDeleteServer(0, "Server Deleted Successfully", (data.contains("id"))?data.getRawString("id"):null)); - }).start(); + }, SubAPI.getInstance().getAppInfo().getName() + "::Server_Deletion(" + server.getName() + ')').start(); } } catch (Throwable e) { host.subdata.sendPacket(new PacketExDeleteServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null)); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java index c7003c4b..5a63ebf3 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java @@ -177,7 +177,7 @@ public final class SubDataClient { log.error.println(e1); } } - }).start(); + }, SubAPI.getInstance().getAppInfo().getName() + "::SubData_Packet_Listener").start(); } private void recieve(Value input) { @@ -550,7 +550,7 @@ public final class SubDataClient { log.info.println("The SubData Connection was closed"); if (reconnect > 0) { log.info.println("Attempting to reconnect in " + reconnect + " seconds"); - Timer timer = new Timer(); + Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler"); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Metrics.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Metrics.java index 968409c3..a5146a72 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Metrics.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Metrics.java @@ -130,7 +130,7 @@ public class Metrics { } private void startSubmitting() { - new Timer().schedule( new TimerTask() { + new Timer("SubServers.Sync::Metrics_Uploader").schedule( new TimerTask() { @Override public void run() { // The data collection is async, as well as sending the data diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java index 5f654ede..876814c3 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java @@ -189,7 +189,7 @@ public final class SubDataClient { e1.printStackTrace(); } } - }).start(); + }, "SubServers.Sync::SubData_Packet_Listener").start(); } private void recieve(Value input) { @@ -470,7 +470,7 @@ public final class SubDataClient { System.out.println("SubServers > The SubData Connection was closed"); if (reconnect > 0) { System.out.println("SubServers > Attempting to reconnect in " + reconnect + " seconds"); - Timer timer = new Timer(); + Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler"); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java index 55324457..59fcd4a2 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java @@ -114,7 +114,7 @@ public final class SubCommand extends CommandX { } } catch (Exception e) { } - }).start(); + }, "SubServers.Sync::Update_Check").start(); } else if (args[0].equalsIgnoreCase("list")) { plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> { int i = 0; diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java index 2060f47a..54e81731 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java @@ -132,7 +132,7 @@ public final class SubPlugin extends BungeeCord implements Listener { getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get()); new Metrics(this); - new Timer().schedule(new TimerTask() { + new Timer("SubServers.Sync::Routine_Update_Check").schedule(new TimerTask() { @SuppressWarnings("unchecked") @Override public void run() {