forked from Limework/RediSkript
Reload redis in a separate thread to not lag the main thread
This commit is contained in:
parent
2d5d281fe4
commit
c6900e352f
@ -7,6 +7,8 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class CommandReloadRedis implements CommandExecutor {
|
public class CommandReloadRedis implements CommandExecutor {
|
||||||
private RediSkript plugin;
|
private RediSkript plugin;
|
||||||
public CommandReloadRedis(RediSkript plugin) {
|
public CommandReloadRedis(RediSkript plugin) {
|
||||||
@ -20,7 +22,15 @@ public class CommandReloadRedis implements CommandExecutor {
|
|||||||
, "&2[&aRediSkript&2] &cThis command can only be executed in console.")));
|
, "&2[&aRediSkript&2] &cThis command can only be executed in console.")));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//reload redis asynchronously to not lag the main thread (was doing a few seconds lagspike at most)
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
plugin.getRedisManager().reload();
|
plugin.getRedisManager().reload();
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(plugin);
|
||||||
|
|
||||||
//not sending to sender, because this command can only be executed via console
|
//not sending to sender, because this command can only be executed via console
|
||||||
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!"));
|
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!"));
|
||||||
|
|
||||||
|
@ -236,7 +236,9 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
|
||||||
this.isShuttingDown.set(true);
|
this.isShuttingDown.set(true);
|
||||||
|
|
||||||
if (this.subscribeJedis != null) {
|
if (this.subscribeJedis != null) {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
this.subscribeJedis.close();
|
this.subscribeJedis.close();
|
||||||
@ -244,13 +246,9 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
|
|
||||||
if (this.jedisPool != null) {
|
if (this.jedisPool != null) {
|
||||||
jedisPool.close();
|
jedisPool.close();
|
||||||
jedisPool = null;
|
|
||||||
}
|
}
|
||||||
this.RedisReconnector.shutdown();
|
this.RedisReconnector.shutdown();
|
||||||
this.RedisService.shutdown();
|
this.RedisService.shutdown();
|
||||||
this.RedisService = null;
|
|
||||||
this.RedisReconnector = null;
|
|
||||||
encryption = null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
Loading…
Reference in New Issue
Block a user