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"> <component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="SkLimework:jar"> <artifact type="jar" name="SkLimework:jar">
<output-path>$PROJECT_DIR$</output-path> <output-path>$PROJECT_DIR$/../FallBack/plugins</output-path>
<root id="archive" name="SkLimework.jar"> <root id="archive" name="SkLimework.jar">
<element id="module-output" name="SkLimework" /> <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$/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/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/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/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="directory" name="sourcecode">
<element id="module-source" name="SkLimework" /> <element id="module-source" name="SkLimework" />
</element> </element>

View File

@ -7,17 +7,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="61139119-6327-48a6-9183-0df6346ed8d8" name="Default Changelist" comment=""> <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/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/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> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -62,6 +55,18 @@
<recent name="net.limework.skLimework.elements" /> <recent name="net.limework.skLimework.elements" />
</key> </key>
</component> </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"> <component name="RunManager">
<configuration name="Tester" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Tester" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="net.limework.skLimework.DoNotUse.Tester" /> <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 org.json.JSONObject;
import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub; import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.exceptions.JedisConnectionException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class RedisSub extends BinaryJedisPubSub implements Runnable{ public class RedisSub extends BinaryJedisPubSub implements Runnable{
private AddonPlugin plugin; private AddonPlugin plugin;
private BinaryJedis j; private BinaryJedis j;
private Boolean isShuttingDown = false;
private List<String> channels; private List<String> channels;
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
private AtomicBoolean isRedisOnline = new AtomicBoolean();
public RedisSub(AddonPlugin plugin, BinaryJedis j, List<String> channels) { public RedisSub(AddonPlugin plugin, BinaryJedis j, List<String> channels) {
this.plugin = plugin; this.plugin = plugin;
@ -29,35 +30,34 @@ public class RedisSub extends BinaryJedisPubSub implements Runnable{
@Override @Override
public void run(){ public void run(){
while (!isShuttingDown.get()){
try { 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()); message("&e[Jedis] &cConnecting to redis...........");
if (!this.j.isConnected()) this.j = plugin.getJedisPool().getResource();
} catch (Exception je){ isRedisOnline.set(true);
plugin.getLogger().warning("Lost connection to redis!"); message("&e[Jedis] &aRedis Connected");
newJedis(); this.j.subscribe(this,
} channels.get(0).getBytes(),
} channels.get(1).getBytes(),
channels.get(2).getBytes(),
channels.get(3).getBytes(),
private void newJedis() { channels.get(4).getBytes());
//this.unsubscribe();
this.j.close();
while (!isShuttingDown){
try {
plugin.getLogger().info("reconnecting to Redis!");
this.j = plugin.getJedisPool().getResource();
plugin.getLogger().info("Connected!");
break;
} catch (Exception e){ } catch (Exception e){
plugin.getLogger().warning("reconnecting to Redis has Failed! retrying in 4 seconds!"); message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
try { Thread.sleep(4000);}catch (InterruptedException ignored){} 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 @Override
public void onMessage(byte[] channel, byte[] message) { public void onMessage(byte[] channel, byte[] message) {
@ -83,9 +83,13 @@ public class RedisSub extends BinaryJedisPubSub implements Runnable{
} }
public void shutdown(){ public void shutdown(){
isShuttingDown = true; this.isShuttingDown.set(true);
this.unsubscribe(); this.unsubscribe();
j.close(); j.close();
} }
public boolean IsRedisOnline() {
return isRedisOnline.get();
}
} }