Fixes for ServerMonitor.

This commit is contained in:
Jonathan Williams 2014-09-25 05:37:10 -07:00
parent 1f0bd462e3
commit e29dd4ff71
2 changed files with 30 additions and 23 deletions

View File

@ -185,7 +185,7 @@ public class RedisServerRepository implements ServerRepository
String dataKey = concatenate(setKey, serverName);
Transaction transaction = jedis.multi();
transaction.set(dataKey, null);
transaction.del(dataKey);
transaction.zrem(setKey, serverName);
transaction.exec();
}
@ -258,25 +258,6 @@ public class RedisServerRepository implements ServerRepository
}
}
Map<String, ServerGroup> serverGroups = new HashMap<String, ServerGroup>();
for (ServerGroup serverGroup : getServerGroups())
{
serverGroups.put(serverGroup.getName(), serverGroup);
}
// TODO: Find cleaner way to prep dedicated server group counts?
for (DedicatedServer server : servers)
{
for (MinecraftServer minecraftServer : getServerStatuses())
{
if (serverGroups.containsKey(minecraftServer.getGroup()))
{
ServerGroup serverGroup = serverGroups.get(minecraftServer.getGroup());
server.incrementServerCount(serverGroup);
}
}
}
return servers;
}
@ -415,7 +396,10 @@ public class RedisServerRepository implements ServerRepository
for (Response<String> response : responses)
{
String serializedData = response.get();
servers.add(Utility.deserialize(serializedData, MinecraftServer.class));
MinecraftServer server = Utility.deserialize(serializedData, MinecraftServer.class);
if (server != null)
servers.add(server);
}
}
catch (JedisConnectionException exception)

View File

@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
@ -74,7 +75,8 @@ public class ServerMonitor
while (true)
{
Collection<ServerGroup> serverGroups = _repository.getServerGroups();
Collection<MinecraftServer> serverStatuses = _repository.getServerStatuses();
for (MinecraftServer deadServer : _repository.getDeadServers())
{
killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true);
@ -82,6 +84,24 @@ public class ServerMonitor
List<DedicatedServer> dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
Map<String, ServerGroup> serverGroupMap = new HashMap<String, ServerGroup>();
for (ServerGroup serverGroup : serverGroups)
{
serverGroupMap.put(serverGroup.getName(), serverGroup);
}
for (MinecraftServer minecraftServer : serverStatuses)
{
for (DedicatedServer server : dedicatedServers)
{
if (serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))
{
ServerGroup serverGroup = serverGroupMap.get(minecraftServer.getGroup());
server.incrementServerCount(serverGroup);
}
}
}
if (_count % 15 == 0)
{
_badServers.clear();
@ -129,7 +149,7 @@ public class ServerMonitor
HashSet<String> onlineServers = new HashSet<String>();
for (MinecraftServer minecraftServer : _repository.getServerStatuses())
for (MinecraftServer minecraftServer : serverStatuses)
{
onlineServers.add(minecraftServer.getName());
@ -237,7 +257,10 @@ public class ServerMonitor
int availableSlots = serverGroup.getMaxPlayerCount() - serverGroup.getPlayerCount();
if (availableSlots < 1500)
{
serversToAdd = Math.max(1, (1500 - availableSlots) / serverGroup.getMaxPlayers());
serversToKill = 0;
}
else if (serversToKill > 0)
serversToKill = Math.min(serversToKill, (availableSlots - 1500) / 80);
}