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