-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic reconnection and some new settings
- Loading branch information
Showing
6 changed files
with
149 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/java/com/denizenscript/depenizen/common/socket/client/ReconnectTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.denizenscript.depenizen.common.socket.client; | ||
|
||
import com.denizenscript.depenizen.common.Depenizen; | ||
|
||
import java.io.IOException; | ||
|
||
public class ReconnectTask implements Runnable { | ||
|
||
private SocketClient client; | ||
private int attemptsLeft; | ||
private long reconnectDelay; | ||
|
||
public ReconnectTask(SocketClient client, int attempts, long reconnectDelay) { | ||
this.client = client; | ||
this.attemptsLeft = attempts; | ||
this.reconnectDelay = reconnectDelay; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (attemptsLeft > 0 && !client.isConnected()) { | ||
try { | ||
Thread.sleep(reconnectDelay); | ||
} | ||
catch (InterruptedException e) { | ||
Depenizen.getImplementation().debugError("BungeeCord Socket failed to reconnect due to an exception."); | ||
Depenizen.getImplementation().debugException(e); | ||
} | ||
try { | ||
attemptsLeft--; | ||
client.connect(); | ||
} | ||
catch (IOException e) { | ||
if (attemptsLeft <= 0) { | ||
Depenizen.getImplementation().debugError("Failed to reconnect to BungeeCord Socket."); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters