mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 12:18:01 +00:00
Changed all previous uses of return(Broken)Resource to try-with-resources
This commit is contained in:
parent
d68b2713c4
commit
712698c76c
@ -56,8 +56,7 @@ public class DataManager implements Listener {
|
||||
if (server != null)
|
||||
return server;
|
||||
|
||||
Jedis tmpRsc = plugin.getPool().getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = plugin.getPool().getResource()) {
|
||||
server = tmpRsc.hget("player:" + uuid, "server");
|
||||
|
||||
if (server == null)
|
||||
@ -68,11 +67,7 @@ public class DataManager implements Listener {
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
if (tmpRsc != null)
|
||||
plugin.getPool().returnBrokenResource(tmpRsc);
|
||||
throw new RuntimeException("Unable to get server for " + uuid, e);
|
||||
} finally {
|
||||
plugin.getPool().returnResource(tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,8 +82,7 @@ public class DataManager implements Listener {
|
||||
if (server != null)
|
||||
return server;
|
||||
|
||||
Jedis tmpRsc = plugin.getPool().getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = plugin.getPool().getResource()) {
|
||||
server = tmpRsc.hget("player:" + uuid, "proxy");
|
||||
|
||||
if (server == null)
|
||||
@ -99,11 +93,7 @@ public class DataManager implements Listener {
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
if (tmpRsc != null)
|
||||
plugin.getPool().returnBrokenResource(tmpRsc);
|
||||
throw new RuntimeException("Unable to get server for " + uuid, e);
|
||||
} finally {
|
||||
plugin.getPool().returnResource(tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,8 +108,7 @@ public class DataManager implements Listener {
|
||||
if (address != null)
|
||||
return address;
|
||||
|
||||
Jedis tmpRsc = plugin.getPool().getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = plugin.getPool().getResource()) {
|
||||
String result = tmpRsc.hget("player:" + uuid, "ip");
|
||||
if (result != null) {
|
||||
address = InetAddresses.forString(result);
|
||||
@ -130,11 +119,7 @@ public class DataManager implements Listener {
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
if (tmpRsc != null)
|
||||
plugin.getPool().returnBrokenResource(tmpRsc);
|
||||
throw new RuntimeException("Unable to get server for " + uuid, e);
|
||||
} finally {
|
||||
plugin.getPool().returnResource(tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,8 +134,7 @@ public class DataManager implements Listener {
|
||||
if (time != null)
|
||||
return time;
|
||||
|
||||
Jedis tmpRsc = plugin.getPool().getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = plugin.getPool().getResource()) {
|
||||
String result = tmpRsc.hget("player:" + uuid, "online");
|
||||
if (result != null)
|
||||
try {
|
||||
@ -188,11 +172,7 @@ public class DataManager implements Listener {
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||
if (tmpRsc != null)
|
||||
plugin.getPool().returnBrokenResource(tmpRsc);
|
||||
throw new RuntimeException("Unable to get server for " + uuid, e);
|
||||
} finally {
|
||||
plugin.getPool().returnResource(tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,7 @@ public final class RedisBungee extends Plugin {
|
||||
}
|
||||
|
||||
final List<String> getCurrentServerIds() {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
try (Jedis jedis = pool.getResource()) {
|
||||
int nag = nagAboutServers.decrementAndGet();
|
||||
if (nag <= 0) {
|
||||
nagAboutServers.set(10);
|
||||
@ -109,11 +108,7 @@ public final class RedisBungee extends Plugin {
|
||||
return servers.build();
|
||||
} catch (JedisConnectionException e) {
|
||||
getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
|
||||
if (jedis != null)
|
||||
pool.returnBrokenResource(jedis);
|
||||
return Collections.singletonList(configuration.getServerId());
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,26 +207,19 @@ public final class RedisBungee extends Plugin {
|
||||
throw new RuntimeException("Unable to connect to your Redis server!", e);
|
||||
}
|
||||
if (pool != null) {
|
||||
Jedis tmpRsc = pool.getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = pool.getResource()) {
|
||||
tmpRsc.hset("heartbeats", configuration.getServerId(), String.valueOf(System.currentTimeMillis()));
|
||||
} finally {
|
||||
pool.returnResource(tmpRsc);
|
||||
}
|
||||
serverIds = getCurrentServerIds();
|
||||
uuidTranslator = new UUIDTranslator(this);
|
||||
heartbeatTask = getProxy().getScheduler().schedule(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Jedis rsc = pool.getResource();
|
||||
try {
|
||||
try (Jedis rsc = pool.getResource()) {
|
||||
rsc.hset("heartbeats", configuration.getServerId(), String.valueOf(System.currentTimeMillis()));
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
||||
pool.returnBrokenResource(rsc);
|
||||
} finally {
|
||||
pool.returnResource(rsc);
|
||||
}
|
||||
serverIds = getCurrentServerIds();
|
||||
}
|
||||
@ -316,16 +304,13 @@ public final class RedisBungee extends Plugin {
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
|
||||
Jedis tmpRsc = pool.getResource();
|
||||
try {
|
||||
try (Jedis tmpRsc = pool.getResource()) {
|
||||
tmpRsc.hdel("heartbeats", configuration.getServerId());
|
||||
if (tmpRsc.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
||||
Set<String> players = tmpRsc.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
||||
for (String member : players)
|
||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||
}
|
||||
} finally {
|
||||
pool.returnResource(tmpRsc);
|
||||
}
|
||||
|
||||
pool.destroy();
|
||||
|
Loading…
Reference in New Issue
Block a user