Skip to content

Commit 5ca4ff0

Browse files
committed
+ added debug-mode
1 parent aa83954 commit 5ca4ff0

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ A Java-library to communicate with [Redunda](https://redunda.erwaysoftware.com).
33

44
# Implementation
55

6-
## Add dependency
6+
### Add dependency
77

88
To implement this library in your Java bot, you need to add the Maven-dependency `org.sobotics.redunda-lib`.
99

10-
## Initialize
10+
### Initialize
1111

1212
Right after launching your bot, you should initialize `PingService`. This should happen before your bot fetches anything from the Stack Exchange API.
1313

@@ -18,7 +18,7 @@ redunda.start();
1818

1919
<small>You can get your API-key in the instances overview of your bot.</small>
2020

21-
## Check the standby status
21+
### Check the standby status
2222

2323
Before your scheduled executors fetch anything from the Stack Exchange API or respond to commands, you should check if the instance is on standby:
2424

@@ -27,3 +27,13 @@ boolean standbyMode = PingService.standby.get();
2727
```
2828

2929
If `standbyMode` is `true`, **DON'T** execute the code!
30+
31+
### Debug mode
32+
33+
If you don't want to use the standby mode while debugging, you can set this with the following line:
34+
35+
```
36+
redunda.setDebugging(true);
37+
```
38+
39+
This will prevent `PingService.standby` from becoming `true` and stops pinging the server.

src/main/java/org/sobotics/PingService.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class PingService {
2020
* */
2121
public String apiKey = "";
2222

23+
/**
24+
* If `true`, `standby` will always return `false` for debugging purposes!
25+
* */
26+
private boolean debugging = false;
27+
2328
/**
2429
* The executor service to ping the server
2530
* */
@@ -55,10 +60,21 @@ public PingService(String key, int pingInterval) {
5560
this.interval = pingInterval;
5661
}
5762

63+
public void setDebugging(boolean debug) {
64+
this.debugging = debug;
65+
if (this.debugging == true) {
66+
PingService.standby = new AtomicBoolean(false);
67+
}
68+
}
69+
70+
public boolean getDebugging() {
71+
return this.debugging;
72+
}
73+
5874
/**
5975
* Resets the executor services and starts pinging the server
6076
* */
61-
public void start() {
77+
public final void start() {
6278
this.executorService = null;
6379
this.executorService = Executors.newSingleThreadScheduledExecutor();
6480

@@ -82,6 +98,10 @@ private void secureExecute() {
8298
* @source https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
8399
* */
84100
private void execute() throws Throwable {
101+
//don't execute on debug-mode
102+
if(this.debugging == true)
103+
return;
104+
85105
String url = "https://redunda.erwaysoftware.com/status.json";
86106
URL obj = new URL(url);
87107
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

0 commit comments

Comments
 (0)