mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-09 00:20:26 +00:00
move Heartbeat task into its own class
This commit is contained in:
@@ -102,4 +102,6 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
Long getRedisClusterTime();
|
||||
|
||||
void updateProxyIds();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class HeartbeatTask extends RedisTask<Void>{
|
||||
|
||||
public final static TimeUnit REPEAT_INTERVAL_TIME_UNIT = TimeUnit.SECONDS;
|
||||
public final static int INTERVAL = 1;
|
||||
private final AtomicInteger globalPlayerCount;
|
||||
|
||||
public HeartbeatTask(RedisBungeePlugin<?> plugin, AtomicInteger globalPlayerCount) {
|
||||
super(plugin);
|
||||
this.globalPlayerCount = globalPlayerCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void jedisTask(Jedis jedis) {
|
||||
try {
|
||||
long redisTime = plugin.getRedisTime(jedis.time());
|
||||
jedis.hset("heartbeats", plugin.getConfiguration().getProxyId(), String.valueOf(redisTime));
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.logFatal("Unable to update heartbeat - did your Redis server go away?");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
plugin.updateProxyIds();
|
||||
globalPlayerCount.set(plugin.getCurrentCount());
|
||||
} catch (Throwable e) {
|
||||
plugin.logFatal("Unable to update data - did your Redis server go away?");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||
try {
|
||||
long redisTime = plugin.getRedisClusterTime();
|
||||
jedisCluster.hset("heartbeats", plugin.getConfiguration().getProxyId(), String.valueOf(redisTime));
|
||||
} catch (JedisConnectionException e) {
|
||||
// Redis server has disappeared!
|
||||
plugin.logFatal("Unable to update heartbeat - did your Redis server go away?");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
plugin.updateProxyIds();
|
||||
globalPlayerCount.set(plugin.getCurrentCount());
|
||||
} catch (Throwable e) {
|
||||
plugin.logFatal("Unable to update data - did your Redis server go away?");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import java.util.concurrent.Callable;
|
||||
|
||||
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
||||
|
||||
private final Summoner<?> summoner;
|
||||
private final RedisBungeeAPI api;
|
||||
private Jedis jedis;
|
||||
private RedisBungeePlugin<?> plugin;
|
||||
protected final Summoner<?> summoner;
|
||||
protected final RedisBungeeAPI api;
|
||||
protected Jedis jedis;
|
||||
protected RedisBungeePlugin<?> plugin;
|
||||
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user