diff --git a/.idea/artifacts/SkLimework_jar.xml b/.idea/artifacts/SkLimework_jar.xml
index 213b017..394f97a 100644
--- a/.idea/artifacts/SkLimework_jar.xml
+++ b/.idea/artifacts/SkLimework_jar.xml
@@ -1,13 +1,12 @@
-
- $PROJECT_DIR$
+
+ $PROJECT_DIR$/../FallBack/plugins
-
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b0601b2..e96d021 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,17 +7,10 @@
-
-
-
-
-
-
-
-
+
@@ -62,6 +55,18 @@
+
+
+
diff --git a/src/main/java/net/limework/skLimework/Events/RedisSub.java b/src/main/java/net/limework/skLimework/Events/RedisSub.java
index 046fdc5..dabb2a0 100644
--- a/src/main/java/net/limework/skLimework/Events/RedisSub.java
+++ b/src/main/java/net/limework/skLimework/Events/RedisSub.java
@@ -7,19 +7,20 @@ import org.cryptomator.siv.UnauthenticCiphertextException;
import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
-import redis.clients.jedis.exceptions.JedisConnectionException;
import javax.crypto.IllegalBlockSizeException;
-import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
public class RedisSub extends BinaryJedisPubSub implements Runnable{
private AddonPlugin plugin;
private BinaryJedis j;
- private Boolean isShuttingDown = false;
private List channels;
+ private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
+ private AtomicBoolean isRedisOnline = new AtomicBoolean();
+
public RedisSub(AddonPlugin plugin, BinaryJedis j, List channels) {
this.plugin = plugin;
@@ -29,35 +30,34 @@ public class RedisSub extends BinaryJedisPubSub implements Runnable{
@Override
public void run(){
- try{
- this.j.subscribe(this, channels.get(0).getBytes(), channels.get(1).getBytes(), channels.get(2).getBytes(), channels.get(3).getBytes(), channels.get(4).getBytes());
-
- } catch (Exception je){
- plugin.getLogger().warning("Lost connection to redis!");
- newJedis();
- }
- }
-
-
- private void newJedis() {
- //this.unsubscribe();
- this.j.close();
- while (!isShuttingDown){
+ while (!isShuttingDown.get()){
try {
- plugin.getLogger().info("reconnecting to Redis!");
- this.j = plugin.getJedisPool().getResource();
- plugin.getLogger().info("Connected!");
- break;
- }catch (Exception e){
- plugin.getLogger().warning("reconnecting to Redis has Failed! retrying in 4 seconds!");
- try { Thread.sleep(4000);}catch (InterruptedException ignored){}
+ message("&e[Jedis] &cConnecting to redis...........");
+ if (!this.j.isConnected()) this.j = plugin.getJedisPool().getResource();
+ isRedisOnline.set(true);
+ message("&e[Jedis] &aRedis Connected");
+ this.j.subscribe(this,
+ channels.get(0).getBytes(),
+ channels.get(1).getBytes(),
+ channels.get(2).getBytes(),
+ channels.get(3).getBytes(),
+ channels.get(4).getBytes());
+ } catch (Exception e){
+ message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
+ this.j.close();
+ isRedisOnline.set(false);
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
- if (isShuttingDown) return;
- plugin.getJedisExecutionService().execute(this);
}
-
+ private void message(String message){
+ plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
+ }
@Override
public void onMessage(byte[] channel, byte[] message) {
@@ -83,9 +83,13 @@ public class RedisSub extends BinaryJedisPubSub implements Runnable{
}
public void shutdown(){
- isShuttingDown = true;
+ this.isShuttingDown.set(true);
this.unsubscribe();
j.close();
}
+ public boolean IsRedisOnline() {
+ return isRedisOnline.get();
+ }
+
}
\ No newline at end of file