From 265933f36e47cd365444baea708cd49e26541496 Mon Sep 17 00:00:00 2001 From: mohammed Alteniji Date: Tue, 25 Apr 2023 11:09:45 +0400 Subject: [PATCH] fix Velocity plugin startup / shutdown issues, java docs notes for some classes and logs for shutdown / startup (#73) closes #71 --- .../redisbungee/api/RedisBungeePlugin.java | 2 ++ .../redisbungee/api/tasks/InitialUtils.java | 9 +++------ .../minecraft/redisbungee/api/tasks/RedisTask.java | 4 ++++ .../minecraft/redisbungee/RedisBungee.java | 5 ++++- .../redisbungee/RedisBungeeVelocityPlugin.java | 14 ++++++++++---- gradle.properties | 2 +- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java index e940a2c..a0e2471 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java @@ -35,6 +35,8 @@ import static com.google.common.base.Preconditions.checkArgument; /** * This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord or another forks of RedisBungee + *

+ * Reason this is interface because some proxies implementations require the user to extend class for plugins for example bungeecord. * * @author Ham1255 * @since 0.7.0 diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/InitialUtils.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/InitialUtils.java index 9f0253c..8a2986f 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/InitialUtils.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/InitialUtils.java @@ -12,8 +12,6 @@ package com.imaginarycode.minecraft.redisbungee.api.tasks; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisCluster; import redis.clients.jedis.Protocol; import redis.clients.jedis.UnifiedJedis; @@ -28,12 +26,11 @@ public class InitialUtils { @Override public Void unifiedJedisTask(UnifiedJedis unifiedJedis) { // This is more portable than INFO

- String info = new String((byte[]) unifiedJedis.sendCommand(Protocol.Command.INFO)); for (String s : info.split("\r\n")) { if (s.startsWith("redis_version:")) { String version = s.split(":")[1]; - plugin.logInfo(version + " <- redis version"); + plugin.logInfo("Redis server version: " + version); if (!RedisUtil.isRedisVersionRight(version)) { plugin.logFatal("Your version of Redis (" + version + ") is not at least version 3.0 RedisBungee requires a newer version of Redis."); throw new RuntimeException("Unsupported Redis version detected"); @@ -62,7 +59,7 @@ public class InitialUtils { } catch (IOException e) { throw new RuntimeException(e); } - plugin.logInfo("crash file was deleted"); + plugin.logInfo("crash file was deleted continuing RedisBungee startup "); } else if (unifiedJedis.hexists("heartbeats", plugin.getConfiguration().getProxyId())) { try { long value = Long.parseLong(unifiedJedis.hget("heartbeats", plugin.getConfiguration().getProxyId())); @@ -81,7 +78,7 @@ public class InitialUtils { } private static void logImposter(RedisBungeePlugin plugin) { - plugin.logFatal("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running."); + plugin.logFatal("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running."); plugin.logFatal("For data consistency reasons, RedisBungee will now disable itself."); plugin.logFatal("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check."); } diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/RedisTask.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/RedisTask.java index 7446c43..eb1b416 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/RedisTask.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/tasks/RedisTask.java @@ -20,6 +20,10 @@ import redis.clients.jedis.UnifiedJedis; import java.util.concurrent.Callable; +/** + * Since Jedis now have UnifiedJedis which basically extended by cluster / single connections classes + * can help us to have shared code. + */ public abstract class RedisTask implements Runnable, Callable { protected final Summoner summoner; diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index d2d7b33..8131b41 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -198,6 +198,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin, Con @Override public void initialize() { + logInfo("Initializing RedisBungee....."); updateProxiesIds(); // start heartbeat task heartbeatTask = getProxy().getScheduler().buildTask(this, new HeartbeatTask(this, this.globalPlayerCount)).repeat(HeartbeatTask.INTERVAL, HeartbeatTask.REPEAT_INTERVAL_TIME_UNIT).schedule(); @@ -283,10 +285,12 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin, Con getProxy().getCommandManager().register("ip", new RedisBungeeCommands.IpCommand(this), "playerip", "rip", "rplayerip"); getProxy().getCommandManager().register("find", new RedisBungeeCommands.FindCommand(this), "rfind"); } + logInfo("RedisBungee initialized successfully "); } @Override public void stop() { + logInfo("Turning off redis connections....."); // Poison the PubSub listener if (psl != null) { psl.poison(); @@ -306,10 +310,12 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin, Con this.httpClient.getDispatcher().getExecutorService().shutdown(); try { + logInfo("waiting for httpclient thread-pool termination....."); this.httpClient.getDispatcher().getExecutorService().awaitTermination(20, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } + logInfo("RedisBungee shutdown complete"); } @Override @@ -330,13 +336,13 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin, Con this.proxiesIds = this.getCurrentProxiesIds(false); } - @Subscribe - public void proxyInit(ProxyInitializeEvent event) { + @Subscribe(order = PostOrder.FIRST) + public void onProxyInitializeEvent(ProxyInitializeEvent event) { initialize(); } - @Subscribe - public void proxyShutdownEvent(ProxyShutdownEvent event) { + @Subscribe(order = PostOrder.LAST) + public void onProxyShutdownEvent(ProxyShutdownEvent event) { stop(); } diff --git a/gradle.properties b/gradle.properties index 54a31fb..8058410 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = com.imaginarycode.minecraft -version = 0.11.0-SNAPSHOT \ No newline at end of file +version = 0.11.1-SNAPSHOT \ No newline at end of file