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