2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Use proper exception handling in UUIDTranslator.

This commit is contained in:
Tux 2014-12-29 11:40:34 -05:00
parent 5a0509ac48
commit 5c9664c344

View File

@ -70,16 +70,14 @@ public final class UUIDTranslator {
return UUIDFetcher.getUUID(player); return UUIDFetcher.getUUID(player);
} }
// This is a bit of a special case.
// If we are in offline mode, UUID generation is simple. // If we are in offline mode, UUID generation is simple.
// We don't even have to cache the UUID, unless we need to reduce GC pressure. // We don't even have to cache the UUID, since this is easy to recalculate.
if (!plugin.getProxy().getConfig().isOnlineMode()) { if (!plugin.getProxy().getConfig().isOnlineMode()) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8)); return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8));
} }
// Let's try Redis. // Let's try Redis.
Jedis jedis = plugin.getPool().getResource(); try (Jedis jedis = plugin.getPool().getResource()) {
try {
String stored = jedis.hget("uuid-cache", player.toLowerCase()); String stored = jedis.hget("uuid-cache", player.toLowerCase());
if (stored != null) { if (stored != null) {
// Found an entry value. Deserialize it. // Found an entry value. Deserialize it.
@ -114,10 +112,6 @@ public final class UUIDTranslator {
} }
} catch (JedisException e) { } catch (JedisException e) {
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e); plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
if (jedis != null)
plugin.getPool().returnBrokenResource(jedis);
// Go ahead and give them what we have.
return null;
} }
return null; // Nope, game over! return null; // Nope, game over!
@ -139,8 +133,7 @@ public final class UUIDTranslator {
} }
// Okay, it wasn't locally cached. Let's try Redis. // Okay, it wasn't locally cached. Let's try Redis.
Jedis jedis = plugin.getPool().getResource(); try (Jedis jedis = plugin.getPool().getResource()) {
try {
String stored = jedis.hget("uuid-cache", player.toString()); String stored = jedis.hget("uuid-cache", player.toString());
if (stored != null) { if (stored != null) {
// Found an entry value. Deserialize it. // Found an entry value. Deserialize it.
@ -177,8 +170,6 @@ public final class UUIDTranslator {
} catch (JedisException e) { } catch (JedisException e) {
plugin.getLogger().log(Level.SEVERE, "Unable to fetch name for " + player, e); plugin.getLogger().log(Level.SEVERE, "Unable to fetch name for " + player, e);
return null; return null;
} finally {
plugin.getPool().returnResource(jedis);
} }
} }