From 846c75453c97aa2866611003f17810beb03397ba Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Thu, 14 Aug 2014 07:41:04 -0500 Subject: [PATCH] Revamping Redis Server status so it uses a consistent time value from redis database. --- .../mineplex/core/status/ServerStatusManager.java | 6 +++--- .../src/mineplex/hub/server/ui/LobbyMenu.java | 10 ++-------- .../serverdata/RedisServerRepository.java | 13 +++++++------ .../src/mineplex/serverdata/Region.java | 2 +- .../src/mineplex/servermonitor/ServerMonitor.java | 15 ++++++++++++--- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java index 199578f14..0e7cf59f7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java @@ -20,8 +20,8 @@ import mineplex.serverdata.ServerRepository; public class ServerStatusManager extends MiniPlugin { - // The default timeout (in milliseconds) before the ServerStatus expires. - public final int DEFAULT_SERVER_TIMEOUT = 15000; + // The default timeout (in seconds) before the ServerStatus expires. + public final int DEFAULT_SERVER_TIMEOUT = 15; private ServerRepository _repository; private LagMeter _lagMeter; @@ -120,7 +120,7 @@ public class ServerStatusManager extends MiniPlugin { public void run() { - _repository.updataServerStatus(serverSnapshot, 15000); + _repository.updataServerStatus(serverSnapshot, DEFAULT_SERVER_TIMEOUT); } }); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java index e36a10fff..50bd405f8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java @@ -55,6 +55,7 @@ public class LobbyMenu extends ShopPageBase implements Material status = Material.IRON_BLOCK; List lore = new ArrayList(); + slot = Integer.parseInt(serverInfo.Name.split("-")[1]) - 1; if (slot >= 54) break; @@ -79,19 +80,12 @@ public class LobbyMenu extends ShopPageBase implements AddButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false), new JoinServerButton(this, serverInfo)); else AddItem(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false)); - - slot += 1; - } - - while (slot < 54) - { - setItem(slot, null); - slot++; } } public void Update() { + clear(); BuildPage(); } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 04c529ba1..00ce50430 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -14,6 +14,7 @@ import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Response; import redis.clients.jedis.Transaction; +import redis.clients.jedis.Tuple; /** * RedisServerRepository offers a Redis-based implementation of {@link ServerRepository} @@ -110,8 +111,8 @@ public class RedisServerRepository implements ServerRepository String serverName = serverData.getName(); String setKey = concatenate("serverstatus", "minecraft", _region.toString()); String dataKey = concatenate(setKey, serverName); - long expiry = System.currentTimeMillis() + timeout; - + long expiry = Long.parseLong(jedis.time().get(0)) + timeout; + Transaction transaction = jedis.multi(); transaction.set(dataKey, serializedData); transaction.zadd(setKey, expiry, serverName); @@ -250,7 +251,7 @@ public class RedisServerRepository implements ServerRepository try { - String min = "(" + System.currentTimeMillis(); + String min = "(" + jedis.time().get(0); String max = "+inf"; names = jedis.zrangeByScore(key, min, max); } @@ -283,12 +284,12 @@ public class RedisServerRepository implements ServerRepository Pipeline pipeline = jedis.pipelined(); String setKey = concatenate("serverstatus", "minecraft", _region.toString()); String min = "-inf"; - String max = System.currentTimeMillis() + ""; + String max = jedis.time().get(0); List> responses = new ArrayList>(); - for (String serverName : jedis.zrangeByScore(setKey, min, max)) + for (Tuple serverName : jedis.zrangeByScoreWithScores(setKey, min, max)) { - String dataKey = concatenate(setKey, serverName); + String dataKey = concatenate(setKey, serverName.getElement()); responses.add(pipeline.get(dataKey)); } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Region.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Region.java index 5c764c9a4..53086a28e 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Region.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Region.java @@ -9,5 +9,5 @@ package mineplex.serverdata; public enum Region { US, - EU; + EU, } diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index 31ee8b5d4..ac8e1433d 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -121,13 +121,22 @@ public class ServerMonitor } }*/ + HashSet onlineServers = new HashSet(); + + for (MinecraftServer minecraftServer : _repository.getServerStatuses()) + { + onlineServers.add(minecraftServer.getName()); + } + for (Iterator>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();) { Entry> entry = iterator.next(); - if (System.currentTimeMillis() - entry.getValue().getValue() > 15000) + if (onlineServers.contains(entry.getKey())) + iterator.remove(); + else if (System.currentTimeMillis() - entry.getValue().getValue() > 20000) { - System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey() + " timeDiff : " + (System.currentTimeMillis() - entry.getValue().getValue())); + System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey()); String serverName = entry.getKey(); String serverAddress = entry.getValue().getKey(); @@ -189,7 +198,7 @@ public class ServerMonitor processWaits++; } - processWaits = 0; + processWaits = 0; try {