Fix issue where broken Jedis resources were not being properly handled.

This commit is contained in:
Ty 2014-08-15 11:33:34 -04:00
parent 5c5a57b048
commit da8aa3f1e3

View File

@ -14,6 +14,7 @@ import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline; import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response; import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction; import redis.clients.jedis.Transaction;
import redis.clients.jedis.exceptions.JedisConnectionException;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@ -73,10 +74,19 @@ public class RedisServerRepository implements ServerRepository
servers.add(Utility.deserialize(serializedData, MinecraftServer.class)); servers.add(Utility.deserialize(serializedData, MinecraftServer.class));
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return servers; return servers;
} }
@ -94,10 +104,19 @@ public class RedisServerRepository implements ServerRepository
String serializedData = jedis.get(dataKey); String serializedData = jedis.get(dataKey);
server = Utility.deserialize(serializedData, MinecraftServer.class); server = Utility.deserialize(serializedData, MinecraftServer.class);
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return server; return server;
} }
@ -120,11 +139,20 @@ public class RedisServerRepository implements ServerRepository
transaction.zadd(setKey, expiry, serverName); transaction.zadd(setKey, expiry, serverName);
transaction.exec(); transaction.exec();
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
} }
}
@Override @Override
public void removeServerStatus(MinecraftServer serverData) public void removeServerStatus(MinecraftServer serverData)
@ -142,11 +170,20 @@ public class RedisServerRepository implements ServerRepository
transaction.zrem(setKey, serverName); transaction.zrem(setKey, serverName);
transaction.exec(); transaction.exec();
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
} }
}
@Override @Override
public boolean serverExists(String serverName) public boolean serverExists(String serverName)
@ -188,10 +225,19 @@ public class RedisServerRepository implements ServerRepository
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
Map<String, ServerGroup> serverGroups = new HashMap<String, ServerGroup>(); Map<String, ServerGroup> serverGroups = new HashMap<String, ServerGroup>();
for (ServerGroup serverGroup : getServerGroups()) for (ServerGroup serverGroup : getServerGroups())
@ -233,10 +279,19 @@ public class RedisServerRepository implements ServerRepository
servers.add(new ServerGroup(data, _region)); servers.add(new ServerGroup(data, _region));
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return servers; return servers;
} }
@ -259,10 +314,19 @@ public class RedisServerRepository implements ServerRepository
transaction.exec(); transaction.exec();
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return 0; return 0;
} }
@ -283,10 +347,19 @@ public class RedisServerRepository implements ServerRepository
String max = "+inf"; String max = "+inf";
names = jedis.zrangeByScore(key, min, max); names = jedis.zrangeByScore(key, min, max);
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return names; return names;
} }
@ -306,10 +379,19 @@ public class RedisServerRepository implements ServerRepository
String max = System.currentTimeMillis() + ""; String max = System.currentTimeMillis() + "";
names = jedis.zrangeByScore(key, min, max); names = jedis.zrangeByScore(key, min, max);
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{
if (jedis != null)
{ {
_jedisPool.returnResource(jedis); _jedisPool.returnResource(jedis);
} }
}
return names; return names;
} }