New Reconnector hopefuly works

This commit is contained in:
ham1255 2020-06-14 17:43:46 +04:00
parent 3dffba07df
commit 39e9536e8f
3 changed files with 47 additions and 39 deletions

View File

@ -1,13 +1,12 @@
<component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="SkLimework:jar">
<output-path>$PROJECT_DIR$</output-path>
<artifact type="jar" name="SkLimework:jar">
<output-path>$PROJECT_DIR$/../FallBack/plugins</output-path>
<root id="archive" name="SkLimework.jar">
<element id="module-output" name="SkLimework" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.6.2/commons-pool2-2.6.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/json/json/20190722/json-20190722.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/cryptomator/siv-mode/1.4.0/siv-mode-1.4.0.jar" path-in-jar="/" />
<element id="directory" name="sourcecode">
<element id="module-source" name="SkLimework" />
</element>

View File

@ -7,17 +7,10 @@
</component>
<component name="ChangeListManager">
<list default="true" id="61139119-6327-48a6-9183-0df6346ed8d8" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/dictionaries/Govindas.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/artifacts/SkLimework_jar.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/artifacts/SkLimework_jar.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/SkLimework.jar" beforeDir="false" afterPath="$PROJECT_DIR$/SkLimework.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/Events/RedisSub.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/Events/RedisSub.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/Events/onRedisMessage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/Events/onRedisMessage.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/elements/EffSendMessage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/elements/EffSendMessage.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/config.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/config.yml" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -62,6 +55,18 @@
<recent name="net.limework.skLimework.elements" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration name="Tester" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="net.limework.skLimework.DoNotUse.Tester" />

View File

@ -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<String> channels;
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
private AtomicBoolean isRedisOnline = new AtomicBoolean();
public RedisSub(AddonPlugin plugin, BinaryJedis j, List<String> 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();
}
}