mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2026-01-04 15:31:37 +00:00
Remove proprietary code
This commit is contained in:
@@ -3,6 +3,7 @@ package me.william278.husksync.redis;
|
||||
import me.william278.husksync.Settings;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
@@ -31,34 +32,37 @@ public abstract class RedisListener {
|
||||
* Start the Redis listener
|
||||
*/
|
||||
public final void listen() {
|
||||
Jedis jedis = new Jedis(Settings.redisHost, Settings.redisPort);
|
||||
final String jedisPassword = Settings.redisPassword;
|
||||
if (!jedisPassword.equals("")) {
|
||||
jedis.auth(jedisPassword);
|
||||
}
|
||||
jedis.connect();
|
||||
if (jedis.isConnected()) {
|
||||
isActiveAndEnabled = true;
|
||||
log(Level.INFO,"Enabled Redis listener successfully!");
|
||||
new Thread(() -> jedis.subscribe(new JedisPubSub() {
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
// Only accept messages to the HuskSync channel
|
||||
if (!channel.equals(RedisMessage.REDIS_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
try(Jedis jedis = new Jedis(Settings.redisHost, Settings.redisPort)) {
|
||||
final String jedisPassword = Settings.redisPassword;
|
||||
if (!jedisPassword.equals("")) {
|
||||
jedis.auth(jedisPassword);
|
||||
}
|
||||
jedis.connect();
|
||||
if (jedis.isConnected()) {
|
||||
isActiveAndEnabled = true;
|
||||
log(Level.INFO,"Enabled Redis listener successfully!");
|
||||
new Thread(() -> jedis.subscribe(new JedisPubSub() {
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
// Only accept messages to the HuskSync channel
|
||||
if (!channel.equals(RedisMessage.REDIS_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle the message
|
||||
try {
|
||||
handleMessage(new RedisMessage(message));
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
log(Level.SEVERE, "Failed to deserialize message target");
|
||||
// Handle the message
|
||||
try {
|
||||
handleMessage(new RedisMessage(message));
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
log(Level.SEVERE, "Failed to deserialize message target");
|
||||
}
|
||||
}
|
||||
}
|
||||
}, RedisMessage.REDIS_CHANNEL), "Redis Subscriber").start();
|
||||
} else {
|
||||
isActiveAndEnabled = false;
|
||||
log(Level.SEVERE, "Failed to initialize the redis listener!");
|
||||
}, RedisMessage.REDIS_CHANNEL), "Redis Subscriber").start();
|
||||
} else {
|
||||
isActiveAndEnabled = false;
|
||||
log(Level.SEVERE, "Failed to initialize the redis listener!");
|
||||
}
|
||||
} catch (JedisException e) {
|
||||
log(Level.SEVERE, "Failed to establish a connection to the Redis server!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user