From 264df5af79d875ca7711f7af2562dfffc612906d Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 7 Nov 2014 01:27:07 -0800 Subject: [PATCH] Fixed load time issue with ServerConfiguration. --- .../serverConfig/ServerConfiguration.java | 2 +- .../.externalToolBuilders/ServerData.launch | 8 +++--- .../serverdata/RedisServerRepository.java | 25 +++++++++++++------ .../src/mineplex/serverdata/ServerGroup.java | 5 ++-- .../mineplex/serverdata/ServerRepository.java | 2 +- .../mineplex/servermonitor/ServerMonitor.java | 2 +- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java index 95fda92ee..681f122df 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java @@ -23,7 +23,7 @@ public class ServerConfiguration extends MiniPlugin Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; - for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups()) + for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups(false)) { if (serverGroup.getName().equalsIgnoreCase(plugin.getConfig().getString("serverstatus.group"))) { diff --git a/Plugins/Mineplex.ServerData/.externalToolBuilders/ServerData.launch b/Plugins/Mineplex.ServerData/.externalToolBuilders/ServerData.launch index a6e931a53..1c1bd747c 100644 --- a/Plugins/Mineplex.ServerData/.externalToolBuilders/ServerData.launch +++ b/Plugins/Mineplex.ServerData/.externalToolBuilders/ServerData.launch @@ -1,11 +1,11 @@ - - - + + + - + diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 841705967..9a70ea4b5 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -241,7 +241,6 @@ public class RedisServerRepository implements ServerRepository servers.add(server); } } - } catch (JedisConnectionException exception) { @@ -261,21 +260,31 @@ public class RedisServerRepository implements ServerRepository } @Override - public Collection getServerGroups() + public Collection getServerGroups(boolean fetch) { Collection servers = new HashSet(); Jedis jedis = _jedisPool.getResource(); - try { + String key = "servergroups"; Set names = jedis.smembers(key); - - for (String groupName : names) + Set>> serverDatas = new HashSet>>(); + + Pipeline pipeline = jedis.pipelined(); + + for (String serverName : names) { - String dataKey = concatenate(key, groupName); - Map data = jedis.hgetAll(dataKey); - servers.add(new ServerGroup(data, _region)); + String dataKey = concatenate(key, serverName); + serverDatas.add(pipeline.hgetAll(dataKey)); + } + + pipeline.sync(); + + for (Response> response : serverDatas) + { + Map data = response.get(); + servers.add(new ServerGroup(data, _region, fetch)); } } catch (JedisConnectionException exception) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java index fbb2d6eb7..35253f75d 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java @@ -137,7 +137,7 @@ public class ServerGroup * the internal state of this ServerGroup. * @param region - the region from which to fetch active {@link MinecraftServer}s. */ - public ServerGroup(Map data, Region region) + public ServerGroup(Map data, Region region, boolean fetch) { _name = data.get("name"); _prefix = data.get("prefix"); @@ -176,7 +176,8 @@ public class ServerGroup _whitelist = Boolean.valueOf(data.get("whitelist")); _resourcePack = data.get("resourcePack"); - fetchServers(region); + if (fetch) + fetchServers(region); } /** diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerRepository.java index c0e2a50af..9c8ca10fd 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerRepository.java @@ -61,7 +61,7 @@ public interface ServerRepository * @return a newly instanced snapshot {@link Collection} of all the * currently active {@link ServerGroup}s in the repository. */ - public Collection getServerGroups(); + public Collection getServerGroups(boolean fetch); public Collection getDeadServers(); diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index c06cd3df6..66762e29e 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -74,7 +74,7 @@ public class ServerMonitor while (true) { - Collection serverGroups = _repository.getServerGroups(); + Collection serverGroups = _repository.getServerGroups(true); Collection serverStatuses = _repository.getServerStatuses(); for (MinecraftServer deadServer : _repository.getDeadServers())