Revamping Redis Server status so it uses a consistent time value from redis database.

This commit is contained in:
Jonathan Williams 2014-08-14 07:41:04 -05:00
parent cacf736f4f
commit 846c75453c
5 changed files with 25 additions and 21 deletions

View File

@ -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);
}
});
}

View File

@ -55,6 +55,7 @@ public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> implements
Material status = Material.IRON_BLOCK;
List<String> lore = new ArrayList<String>();
slot = Integer.parseInt(serverInfo.Name.split("-")[1]) - 1;
if (slot >= 54)
break;
@ -79,19 +80,12 @@ public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> 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();
}

View File

@ -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<Response<String>> responses = new ArrayList<Response<String>>();
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));
}

View File

@ -9,5 +9,5 @@ package mineplex.serverdata;
public enum Region
{
US,
EU;
EU,
}

View File

@ -121,13 +121,22 @@ public class ServerMonitor
}
}*/
HashSet<String> onlineServers = new HashSet<String>();
for (MinecraftServer minecraftServer : _repository.getServerStatuses())
{
onlineServers.add(minecraftServer.getName());
}
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
{
Entry<String, Entry<String, Long>> 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
{