Cancel delayed/repeating tasks at the start of the disable process (#1935)

This commit is contained in:
Luck 2020-01-25 12:38:24 +00:00
parent e9d72df890
commit 0864cf756c
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 43 additions and 9 deletions

View File

@ -73,8 +73,12 @@ public class BungeeSchedulerAdapter implements SchedulerAdapter {
}
@Override
public void shutdown() {
public void shutdownScheduler() {
Iterators.tryIterate(this.tasks, ScheduledTask::cancel);
}
@Override
public void shutdownExecutor() {
// do nothing
}
}

View File

@ -205,6 +205,11 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
}
public final void disable() {
getLogger().info("Starting shutdown process...");
// cancel delayed/repeating tasks
getBootstrap().getScheduler().shutdownScheduler();
// shutdown permission vault and verbose handler tasks
this.permissionRegistry.close();
this.verboseHandler.close();
@ -233,9 +238,8 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// unregister api
ApiRegistrationUtil.unregisterProvider();
// shutdown scheduler
getLogger().info("Shutting down internal scheduler...");
getBootstrap().getScheduler().shutdown();
// shutdown async executor pool
getBootstrap().getScheduler().shutdownExecutor();
getLogger().info("Goodbye!");
}

View File

@ -73,8 +73,17 @@ public abstract class AbstractJavaScheduler implements SchedulerAdapter {
}
@Override
public void shutdown() {
public void shutdownScheduler() {
this.scheduler.shutdown();
try {
this.scheduler.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void shutdownExecutor() {
this.schedulerWorkerPool.delegate.shutdown();
try {
this.schedulerWorkerPool.delegate.awaitTermination(1, TimeUnit.MINUTES);

View File

@ -86,8 +86,17 @@ public interface SchedulerAdapter {
SchedulerTask asyncRepeating(Runnable task, long interval, TimeUnit unit);
/**
* Shuts down this executor instance
* Shuts down the scheduler instance.
*
* <p>{@link #asyncLater(Runnable, long, TimeUnit)} and {@link #asyncRepeating(Runnable, long, TimeUnit)}.</p>
*/
void shutdown();
void shutdownScheduler();
/**
* Shuts down the executor instance.
*
* <p>{@link #async()} and {@link #executeAsync(Runnable)}.</p>
*/
void shutdownExecutor();
}

View File

@ -101,8 +101,12 @@ public class SpongeSchedulerAdapter implements SchedulerAdapter {
}
@Override
public void shutdown() {
public void shutdownScheduler() {
Iterators.tryIterate(this.tasks, Task::cancel);
}
@Override
public void shutdownExecutor() {
// do nothing
}
}

View File

@ -80,8 +80,12 @@ public class VelocitySchedulerAdapter implements SchedulerAdapter {
}
@Override
public void shutdown() {
public void shutdownScheduler() {
Iterators.tryIterate(this.tasks, ScheduledTask::cancel);
}
@Override
public void shutdownExecutor() {
// do nothing
}
}