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,9 +74,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return servers; return servers;
@ -94,9 +104,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return server; return server;
@ -120,9 +139,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
} }
@ -142,9 +170,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
} }
@ -188,9 +225,18 @@ public class RedisServerRepository implements ServerRepository
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
Map<String, ServerGroup> serverGroups = new HashMap<String, ServerGroup>(); Map<String, ServerGroup> serverGroups = new HashMap<String, ServerGroup>();
@ -233,9 +279,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return servers; return servers;
@ -259,9 +314,18 @@ public class RedisServerRepository implements ServerRepository
transaction.exec(); transaction.exec();
} }
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally finally
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return 0; return 0;
@ -283,9 +347,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return names; return names;
@ -306,9 +379,18 @@ 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
{ {
_jedisPool.returnResource(jedis); if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
} }
return names; return names;