Fix issues with Redis subscriber

This commit is contained in:
William committed 2022-01-15 20:39:25 +00:00
1 parent 2dd0bbb9d8
commit 840ebaf9ba
4 files changed
+27 -16

No files matched your search

+5 -1
View File
@@ -58,6 +58,10 @@
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>me.william278.huskhomes2.libraries.hikari</shadedPattern>
</relocation>
<relocation>
<pattern>redis.clients</pattern>
<shadedPattern>me.william278.huskhomes2.libraries.jedis</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
@@ -188,7 +192,7 @@
<artifactId>jedis</artifactId>
<version>4.0.1</version>
<type>jar</type>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
@@ -266,6 +266,12 @@ public final class HuskHomes extends JavaPlugin {
@Override
public void onDisable() {
if (HuskHomes.getSettings().doBungee()) {
if (!HuskHomes.getSettings().getMessengerType().equalsIgnoreCase("pluginmessage")) {
RedisReceiver.terminate();
}
}
// Terminate the Hikari data source
database.close();
@@ -11,6 +11,7 @@ import redis.clients.jedis.JedisPubSub;
import java.util.ArrayList;
import java.util.Collections;
import java.util.logging.Level;
public class RedisReceiver {
@@ -20,12 +21,17 @@ public class RedisReceiver {
return jedisPool.getResource();
}
// Initialize Jedis. Note that due to the shading on DefaultEvictionPool we have to change the contextual ClassLoader here
public static void initialize() {
jedisPool = new JedisPool(new JedisPoolConfig(),
HuskHomes.getSettings().getRedisHost(),
HuskHomes.getSettings().getRedisPort());
}
// Close the connection
public static void terminate() {
jedisPool.close();
}
private static final HuskHomes plugin = HuskHomes.getInstance();
public static final String REDIS_CHANNEL = "HuskHomes";
@@ -41,14 +47,12 @@ public class RedisReceiver {
public static void listen() {
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
try (Jedis jedis = getJedis()) {
if (!jedisPassword.equals("")) {
jedis.auth(jedisPassword);
}
jedis.connect();
if (jedis.isConnected()) {
plugin.getLogger().info("Enabled Redis listener successfully!");
new Thread(() -> jedis.subscribe(new JedisPubSub() {
new Thread(() -> {
try (Jedis jedis = getJedis()) {
if (!jedisPassword.equals("")) {
jedis.auth(jedisPassword);
}
jedis.subscribe(new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
if (!channel.equals(REDIS_CHANNEL)) {
@@ -103,10 +107,10 @@ public class RedisReceiver {
final String messageData = splitMessage[1];
CrossServerMessageHandler.handlePluginMessage(new RedisMessage(clusterID, receiver.getName(), messageType, messageData), receiver);
}
}, REDIS_CHANNEL), "Redis Subscriber").start();
} else {
plugin.getLogger().severe("Failed to initialize the redis listener!");
}, REDIS_CHANNEL);
} catch (Exception e) {
plugin.getLogger().log(Level.SEVERE, "An exception occurred in the Jedis subscriber", e);
}
}
}, "Redis Subscriber").start();
}
}
-3
View File
@@ -6,9 +6,6 @@ authors: [William278]
softdepend: [dynmap, Vault, BlueMap, Squaremap]
description: A powerful, intuitive and flexible teleportation suite
website: 'https://william278.net'
libraries:
- redis.clients:jedis:2.7.2
commands:
home:
usage: /<command> <home>