Skip to content

Commit 77f53fd

Browse files
committed
Update Javadocs and add more methods
1 parent 9cb6466 commit 77f53fd

File tree

4 files changed

+680
-68
lines changed

4 files changed

+680
-68
lines changed

jda-module/src/main/java/org/botblock/javabotblockapi/jda/PostAction.java

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.json.JSONObject;
2929

3030
import javax.annotation.Nonnull;
31+
import javax.annotation.Nullable;
3132
import java.io.IOException;
3233
import java.util.ArrayList;
3334
import java.util.Arrays;
@@ -78,14 +79,73 @@ public PostAction(@Nonnull JDA jda){
7879

7980
/**
8081
* Disables the automatic posting of Stats.
81-
* <br>This essentially just performs a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}.
82-
*
83-
* @see java.util.concurrent.ScheduledExecutorService#shutdown()
82+
* <br>This essentially just performs a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
83+
* by calling the {@link #disableAutoPost(BotBlockAPI) disableAutoPost(null)} method.
84+
*
85+
* <p>Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
86+
* <br>If you want to wait for the tasks to complete use {@link #disableAutoPost(BotBlockAPI) disableAutoPost(BotBlockAPI)} or
87+
* {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
88+
*
89+
* @see java.util.concurrent.ScheduledExecutorService#shutdown()
8490
*/
8591
public void disableAutoPost(){
92+
disableAutoPost(null);
93+
}
94+
95+
/**
96+
* Disables the automatic posting of Stats.
97+
* <br>Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
98+
* finish, or to time out after n minutes by providing the {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlock instance}.
99+
*
100+
* <p>Passing null as argument will just perform a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
101+
* similar to what the disableAutoPost() method does.
102+
*
103+
* <p>If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
104+
* {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
105+
*
106+
* <p>This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
107+
*
108+
* @param botBlockAPI
109+
* The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} or null to just perform a shutdown.
110+
*
111+
* @since 6.0.0
112+
*
113+
* @see java.util.concurrent.ScheduledExecutorService#shutdown()
114+
* @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
115+
*/
116+
public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
117+
if(botBlockAPI != null){
118+
disableAutoPost(botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
119+
return;
120+
}
121+
86122
scheduler.shutdown();
87123
}
88124

125+
/**
126+
* Disables the automatic posting of Stats.
127+
* <br>Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
128+
* finish, or to time out after a specified time frame.
129+
*
130+
* <p>This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
131+
*
132+
* @param time
133+
* The amount of time to wait for scheduled executions to finish before the Scheduler would time out.
134+
* @param timeUnit
135+
* The {@link java.util.concurrent.TimeUnit TimeUnit} to use.
136+
*
137+
* @since 6.0.0
138+
*
139+
* @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
140+
*/
141+
public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
142+
try{
143+
scheduler.awaitTermination(time, timeUnit);
144+
}catch(InterruptedException ex){
145+
ex.printStackTrace();
146+
}
147+
}
148+
89149
/**
90150
* Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
91151
* task, which will post the statistics of the provided {@link net.dv8tion.jda.api.JDA JDA instance} every n minutes.

0 commit comments

Comments
 (0)