2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Fix replacing thread pool and move to ScheduledThreadPoolExecutor

This commit is contained in:
Tux 2016-06-28 16:39:05 -04:00
parent 8f38b5ddb8
commit 6f3a882fa2

View File

@ -59,8 +59,8 @@ public final class RedisBungee extends Plugin {
private volatile List<String> serverIds; private volatile List<String> serverIds;
private final AtomicInteger nagAboutServers = new AtomicInteger(); private final AtomicInteger nagAboutServers = new AtomicInteger();
private final AtomicInteger globalPlayerCount = new AtomicInteger(); private final AtomicInteger globalPlayerCount = new AtomicInteger();
private ScheduledTask integrityCheck; private Future<?> integrityCheck;
private ScheduledTask heartbeatTask; private Future<?> heartbeatTask;
private boolean usingLua; private boolean usingLua;
private LuaManager.Script serverToPlayersScript; private LuaManager.Script serverToPlayersScript;
private LuaManager.Script getPlayerCountScript; private LuaManager.Script getPlayerCountScript;
@ -223,12 +223,14 @@ public final class RedisBungee extends Plugin {
@Override @Override
public void onEnable() { public void onEnable() {
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory(); ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
getExecutorService().shutdownNow();
ScheduledExecutorService service;
try { try {
Field field = this.getClass().getDeclaredField("executorService"); Field field = Plugin.class.getDeclaredField("service");
field.setAccessible(true); field.setAccessible(true);
field.set(this, Executors.newFixedThreadPool(24, factory)); field.set(this, service = Executors.newScheduledThreadPool(24, factory));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Can't replace BungeeCord thread pool with our own", e);
} }
try { try {
loadConfig(); loadConfig();
@ -265,7 +267,7 @@ public final class RedisBungee extends Plugin {
} }
serverIds = getCurrentServerIds(true, false); serverIds = getCurrentServerIds(true, false);
uuidTranslator = new UUIDTranslator(this); uuidTranslator = new UUIDTranslator(this);
heartbeatTask = getProxy().getScheduler().schedule(this, new Runnable() { heartbeatTask = service.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
try (Jedis rsc = pool.getResource()) { try (Jedis rsc = pool.getResource()) {
@ -297,7 +299,7 @@ public final class RedisBungee extends Plugin {
getProxy().getPluginManager().registerListener(this, dataManager); getProxy().getPluginManager().registerListener(this, dataManager);
psl = new PubSubListener(); psl = new PubSubListener();
getProxy().getScheduler().runAsync(this, psl); getProxy().getScheduler().runAsync(this, psl);
integrityCheck = getProxy().getScheduler().schedule(this, new Runnable() { integrityCheck = service.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
try (Jedis tmpRsc = pool.getResource()) { try (Jedis tmpRsc = pool.getResource()) {
@ -367,9 +369,8 @@ public final class RedisBungee extends Plugin {
if (pool != null) { if (pool != null) {
// Poison the PubSub listener // Poison the PubSub listener
psl.poison(); psl.poison();
getProxy().getScheduler().cancel(this); integrityCheck.cancel(true);
integrityCheck.cancel(); heartbeatTask.cancel(true);
heartbeatTask.cancel();
getProxy().getPluginManager().unregisterListeners(this); getProxy().getPluginManager().unregisterListeners(this);
try (Jedis tmpRsc = pool.getResource()) { try (Jedis tmpRsc = pool.getResource()) {