mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Bump Jedis version (with some caveats).
This commit is contained in:
parent
c46041f802
commit
d111052ead
8
pom.xml
8
pom.xml
@ -141,7 +141,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>2.5.1</version>
|
<version>2.7.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -130,20 +130,14 @@ public final class RedisBungee extends Plugin {
|
|||||||
final int getCount() {
|
final int getCount() {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc;
|
try (Jedis rsc = pool.getResource()){
|
||||||
rsc = pool.getResource();
|
|
||||||
try {
|
|
||||||
for (String i : getServerIds()) {
|
for (String i : getServerIds()) {
|
||||||
c += rsc.scard("proxy:" + i + ":usersOnline");
|
c += rsc.scard("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||||
if (rsc != null)
|
|
||||||
pool.returnBrokenResource(rsc);
|
|
||||||
throw new RuntimeException("Unable to get total player count", e);
|
throw new RuntimeException("Unable to get total player count", e);
|
||||||
} finally {
|
|
||||||
pool.returnResource(rsc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
@ -163,8 +157,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
final Set<UUID> getPlayers() {
|
final Set<UUID> getPlayers() {
|
||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis rsc = pool.getResource();
|
try (Jedis rsc = pool.getResource();) {
|
||||||
try {
|
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getServerIds()) {
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
@ -183,11 +176,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||||
if (rsc != null)
|
|
||||||
pool.returnBrokenResource(rsc);
|
|
||||||
throw new RuntimeException("Unable to get all players online", e);
|
throw new RuntimeException("Unable to get all players online", e);
|
||||||
} finally {
|
|
||||||
pool.returnResource(rsc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return setBuilder.build();
|
return setBuilder.build();
|
||||||
@ -204,17 +193,12 @@ public final class RedisBungee extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final void sendChannelMessage(String channel, String message) {
|
final void sendChannelMessage(String channel, String message) {
|
||||||
Jedis jedis = pool.getResource();
|
try (Jedis jedis = pool.getResource()) {
|
||||||
try {
|
|
||||||
jedis.publish(channel, message);
|
jedis.publish(channel, message);
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
||||||
if (jedis != null)
|
|
||||||
pool.returnBrokenResource(jedis);
|
|
||||||
throw new RuntimeException("Unable to publish channel message", e);
|
throw new RuntimeException("Unable to publish channel message", e);
|
||||||
} finally {
|
|
||||||
pool.returnResource(jedis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,8 +255,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
integrityCheck = getProxy().getScheduler().schedule(this, new Runnable() {
|
integrityCheck = getProxy().getScheduler().schedule(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Jedis tmpRsc = pool.getResource();
|
try (Jedis tmpRsc = pool.getResource()) {
|
||||||
try {
|
|
||||||
Set<String> players = new HashSet<>(getLocalPlayersAsUuidStrings());
|
Set<String> players = new HashSet<>(getLocalPlayersAsUuidStrings());
|
||||||
Set<String> redisCollection = tmpRsc.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> redisCollection = tmpRsc.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
||||||
|
|
||||||
@ -306,8 +289,6 @@ public final class RedisBungee extends Plugin {
|
|||||||
getLogger().warning("Player " + player + " is on the proxy but not in Redis.");
|
getLogger().warning("Player " + player + " is on the proxy but not in Redis.");
|
||||||
tmpRsc.sadd("proxy:" + configuration.getServerId() + ":usersOnline", player);
|
tmpRsc.sadd("proxy:" + configuration.getServerId() + ":usersOnline", player);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
pool.returnResource(tmpRsc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 1, TimeUnit.MINUTES);
|
}, 0, 1, TimeUnit.MINUTES);
|
||||||
@ -387,10 +368,20 @@ public final class RedisBungee extends Plugin {
|
|||||||
FutureTask<JedisPool> task = new FutureTask<>(new Callable<JedisPool>() {
|
FutureTask<JedisPool> task = new FutureTask<>(new Callable<JedisPool>() {
|
||||||
@Override
|
@Override
|
||||||
public JedisPool call() throws Exception {
|
public JedisPool call() throws Exception {
|
||||||
|
// With recent versions of Jedis, we must set the classloader to the one BungeeCord used
|
||||||
|
// to load RedisBungee with.
|
||||||
|
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||||
|
Thread.currentThread().setContextClassLoader(RedisBungee.class.getClassLoader());
|
||||||
|
|
||||||
|
// Create the pool...
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
config.setMaxTotal(configuration.getInt("max-redis-connections", 8));
|
config.setMaxTotal(configuration.getInt("max-redis-connections", 8));
|
||||||
config.setJmxEnabled(false);
|
config.setJmxEnabled(false);
|
||||||
return new JedisPool(config, redisServer, redisPort, 0, finalRedisPassword);
|
JedisPool pool = new JedisPool(config, redisServer, redisPort, 0, finalRedisPassword);
|
||||||
|
|
||||||
|
// Reset classloader and return the pool
|
||||||
|
Thread.currentThread().setContextClassLoader(previous);
|
||||||
|
return pool;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user