|
28 | 28 | import org.json.JSONObject; |
29 | 29 |
|
30 | 30 | import javax.annotation.Nonnull; |
| 31 | +import javax.annotation.Nullable; |
31 | 32 | import java.io.IOException; |
32 | 33 | import java.util.ArrayList; |
33 | 34 | import java.util.Arrays; |
@@ -78,14 +79,73 @@ public PostAction(@Nonnull JDA jda){ |
78 | 79 |
|
79 | 80 | /** |
80 | 81 | * 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() |
84 | 90 | */ |
85 | 91 | 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 | + |
86 | 122 | scheduler.shutdown(); |
87 | 123 | } |
88 | 124 |
|
| 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 | + |
89 | 149 | /** |
90 | 150 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate} |
91 | 151 | * task, which will post the statistics of the provided {@link net.dv8tion.jda.api.JDA JDA instance} every n minutes. |
|
0 commit comments