mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
fix Velocity plugin startup / shutdown issues, java docs notes for some classes and logs for shutdown / startup (#73)
closes #71
This commit is contained in:
parent
9a583369e8
commit
265933f36e
@ -35,6 +35,8 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord or another forks of RedisBungee
|
* This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord or another forks of RedisBungee
|
||||||
|
* <p>
|
||||||
|
* Reason this is interface because some proxies implementations require the user to extend class for plugins for example bungeecord.
|
||||||
*
|
*
|
||||||
* @author Ham1255
|
* @author Ham1255
|
||||||
* @since 0.7.0
|
* @since 0.7.0
|
||||||
|
@ -12,8 +12,6 @@ package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
|||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil;
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisCluster;
|
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
import redis.clients.jedis.UnifiedJedis;
|
||||||
|
|
||||||
@ -28,12 +26,11 @@ public class InitialUtils {
|
|||||||
@Override
|
@Override
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||||
// This is more portable than INFO <section>
|
// This is more portable than INFO <section>
|
||||||
|
|
||||||
String info = new String((byte[]) unifiedJedis.sendCommand(Protocol.Command.INFO));
|
String info = new String((byte[]) unifiedJedis.sendCommand(Protocol.Command.INFO));
|
||||||
for (String s : info.split("\r\n")) {
|
for (String s : info.split("\r\n")) {
|
||||||
if (s.startsWith("redis_version:")) {
|
if (s.startsWith("redis_version:")) {
|
||||||
String version = s.split(":")[1];
|
String version = s.split(":")[1];
|
||||||
plugin.logInfo(version + " <- redis version");
|
plugin.logInfo("Redis server version: " + version);
|
||||||
if (!RedisUtil.isRedisVersionRight(version)) {
|
if (!RedisUtil.isRedisVersionRight(version)) {
|
||||||
plugin.logFatal("Your version of Redis (" + version + ") is not at least version 3.0 RedisBungee requires a newer version of Redis.");
|
plugin.logFatal("Your version of Redis (" + version + ") is not at least version 3.0 RedisBungee requires a newer version of Redis.");
|
||||||
throw new RuntimeException("Unsupported Redis version detected");
|
throw new RuntimeException("Unsupported Redis version detected");
|
||||||
@ -62,7 +59,7 @@ public class InitialUtils {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
plugin.logInfo("crash file was deleted");
|
plugin.logInfo("crash file was deleted continuing RedisBungee startup ");
|
||||||
} else if (unifiedJedis.hexists("heartbeats", plugin.getConfiguration().getProxyId())) {
|
} else if (unifiedJedis.hexists("heartbeats", plugin.getConfiguration().getProxyId())) {
|
||||||
try {
|
try {
|
||||||
long value = Long.parseLong(unifiedJedis.hget("heartbeats", plugin.getConfiguration().getProxyId()));
|
long value = Long.parseLong(unifiedJedis.hget("heartbeats", plugin.getConfiguration().getProxyId()));
|
||||||
|
@ -20,6 +20,10 @@ import redis.clients.jedis.UnifiedJedis;
|
|||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since Jedis now have UnifiedJedis which basically extended by cluster / single connections classes
|
||||||
|
* can help us to have shared code.
|
||||||
|
*/
|
||||||
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
||||||
|
|
||||||
protected final Summoner<?> summoner;
|
protected final Summoner<?> summoner;
|
||||||
|
@ -198,6 +198,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
logInfo("Initializing RedisBungee.....");
|
||||||
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
|
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
|
||||||
ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory);
|
ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory);
|
||||||
try {
|
try {
|
||||||
@ -266,10 +267,12 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
|||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this));
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this));
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlistCommand(this));
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlistCommand(this));
|
||||||
}
|
}
|
||||||
|
logInfo("RedisBungee initialized successfully ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
logInfo("Turning off redis connections.....");
|
||||||
// Poison the PubSub listener
|
// Poison the PubSub listener
|
||||||
if (psl != null) {
|
if (psl != null) {
|
||||||
psl.poison();
|
psl.poison();
|
||||||
@ -287,7 +290,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
logInfo("RedisBungee shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,6 +34,7 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
|||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||||
import com.squareup.okhttp.Dispatcher;
|
import com.squareup.okhttp.Dispatcher;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
@ -245,6 +246,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
logInfo("Initializing RedisBungee.....");
|
||||||
updateProxiesIds();
|
updateProxiesIds();
|
||||||
// start heartbeat task
|
// start heartbeat task
|
||||||
heartbeatTask = getProxy().getScheduler().buildTask(this, new HeartbeatTask(this, this.globalPlayerCount)).repeat(HeartbeatTask.INTERVAL, HeartbeatTask.REPEAT_INTERVAL_TIME_UNIT).schedule();
|
heartbeatTask = getProxy().getScheduler().buildTask(this, new HeartbeatTask(this, this.globalPlayerCount)).repeat(HeartbeatTask.INTERVAL, HeartbeatTask.REPEAT_INTERVAL_TIME_UNIT).schedule();
|
||||||
@ -283,10 +285,12 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
|||||||
getProxy().getCommandManager().register("ip", new RedisBungeeCommands.IpCommand(this), "playerip", "rip", "rplayerip");
|
getProxy().getCommandManager().register("ip", new RedisBungeeCommands.IpCommand(this), "playerip", "rip", "rplayerip");
|
||||||
getProxy().getCommandManager().register("find", new RedisBungeeCommands.FindCommand(this), "rfind");
|
getProxy().getCommandManager().register("find", new RedisBungeeCommands.FindCommand(this), "rfind");
|
||||||
}
|
}
|
||||||
|
logInfo("RedisBungee initialized successfully ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
logInfo("Turning off redis connections.....");
|
||||||
// Poison the PubSub listener
|
// Poison the PubSub listener
|
||||||
if (psl != null) {
|
if (psl != null) {
|
||||||
psl.poison();
|
psl.poison();
|
||||||
@ -306,10 +310,12 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
|||||||
|
|
||||||
this.httpClient.getDispatcher().getExecutorService().shutdown();
|
this.httpClient.getDispatcher().getExecutorService().shutdown();
|
||||||
try {
|
try {
|
||||||
|
logInfo("waiting for httpclient thread-pool termination.....");
|
||||||
this.httpClient.getDispatcher().getExecutorService().awaitTermination(20, TimeUnit.SECONDS);
|
this.httpClient.getDispatcher().getExecutorService().awaitTermination(20, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
logInfo("RedisBungee shutdown complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -330,13 +336,13 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
|||||||
this.proxiesIds = this.getCurrentProxiesIds(false);
|
this.proxiesIds = this.getCurrentProxiesIds(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public void proxyInit(ProxyInitializeEvent event) {
|
public void onProxyInitializeEvent(ProxyInitializeEvent event) {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(order = PostOrder.LAST)
|
||||||
public void proxyShutdownEvent(ProxyShutdownEvent event) {
|
public void onProxyShutdownEvent(ProxyShutdownEvent event) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
group = com.imaginarycode.minecraft
|
group = com.imaginarycode.minecraft
|
||||||
version = 0.11.0-SNAPSHOT
|
version = 0.11.1-SNAPSHOT
|
Loading…
Reference in New Issue
Block a user