mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 10:38:01 +00:00
removed get JedisPool, refactored jedis summoners, new SinglePoolJedisSummoner, start version 0.8.0
This commit is contained in:
parent
839c8cd615
commit
f7285ff4f1
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<version>0.7.3-SNAPSHOT</version>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -312,11 +312,6 @@ public class RedisBungeeAPI {
|
||||
* @deprecated this secluded to be removed when support for redis sentinel or redis cluster is finished, use {@link RedisBungeeAPI#requestJedis()}
|
||||
* @since 0.6.5
|
||||
*/
|
||||
@Deprecated
|
||||
public JedisPool getJedisPool() {
|
||||
return this.plugin.getJedisPool();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gives you instance of Jedis
|
||||
|
@ -3,6 +3,7 @@ package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
@ -19,16 +20,20 @@ import java.util.concurrent.TimeUnit;
|
||||
* @since 0.7.0
|
||||
*
|
||||
*/
|
||||
public interface RedisBungeePlugin<P> extends JedisSummoner, EventsPlatform{
|
||||
public interface RedisBungeePlugin<P> extends EventsPlatform{
|
||||
|
||||
default void enable() {
|
||||
default void start() {
|
||||
|
||||
}
|
||||
|
||||
default void disable() {
|
||||
default void stop() {
|
||||
|
||||
}
|
||||
|
||||
Jedis requestJedis();
|
||||
|
||||
boolean isJedisAvailable();
|
||||
|
||||
RedisBungeeConfiguration getConfiguration();
|
||||
|
||||
int getCount();
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.summoners;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
|
||||
/**
|
||||
* This class intended for future release to support redis sentinel or redis clusters
|
||||
@ -11,13 +14,10 @@ import redis.clients.jedis.JedisPool;
|
||||
* @since 0.7.0
|
||||
*
|
||||
*/
|
||||
public interface JedisSummoner {
|
||||
public interface JedisSummoner extends Closeable {
|
||||
|
||||
Jedis requestJedis();
|
||||
|
||||
boolean isJedisAvailable();
|
||||
|
||||
@Deprecated
|
||||
JedisPool getJedisPool();
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.internal.summoners;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SinglePoolJedisSummoner implements JedisSummoner {
|
||||
final JedisPool jedisPool;
|
||||
|
||||
public SinglePoolJedisSummoner(JedisPool jedisPool) {
|
||||
this.jedisPool = jedisPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis requestJedis() {
|
||||
return this.jedisPool.getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJedisAvailable() {
|
||||
return !this.jedisPool.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
jedisPool.close();
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<version>0.7.3-SNAPSHOT</version>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -13,6 +13,8 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetwork
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.summoners.JedisSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.summoners.SinglePoolJedisSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.IOUtil;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.LuaManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.NameFetcher;
|
||||
@ -48,7 +50,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
private static final Gson gson = new Gson();
|
||||
private RedisBungeeAPI api;
|
||||
private PubSubListener psl = null;
|
||||
private JedisPool jedisPool;
|
||||
private JedisSummoner jedisSummoner;
|
||||
private UUIDTranslator uuidTranslator;
|
||||
private RedisBungeeConfiguration configuration;
|
||||
private BungeeDataManager dataManager;
|
||||
@ -128,17 +130,12 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
|
||||
@Override
|
||||
public Jedis requestJedis() {
|
||||
return this.jedisPool.getResource();
|
||||
return this.jedisSummoner.requestJedis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJedisAvailable() {
|
||||
return !jedisPool.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JedisPool getJedisPool() {
|
||||
return this.jedisPool;
|
||||
return this.jedisSummoner.isJedisAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -333,7 +330,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
public void start() {
|
||||
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
|
||||
ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory);
|
||||
try {
|
||||
@ -490,7 +487,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
public void stop() {
|
||||
if (isJedisAvailable()) {
|
||||
// Poison the PubSub listener
|
||||
psl.poison();
|
||||
@ -506,8 +503,11 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||
}
|
||||
}
|
||||
|
||||
this.jedisPool.destroy();
|
||||
try {
|
||||
this.jedisSummoner.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,7 +563,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
try {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8));
|
||||
this.jedisPool = new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL);
|
||||
this.jedisSummoner = new SinglePoolJedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL));
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
throw new RuntimeException("Unable to create Redis pool", e);
|
||||
@ -599,8 +599,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
|
||||
getLogger().log(Level.INFO, "Successfully connected to Redis.");
|
||||
} catch (JedisConnectionException e) {
|
||||
this.jedisPool.destroy();
|
||||
this.jedisPool = null;
|
||||
this.jedisSummoner.close();
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
@ -610,12 +609,12 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
enable();
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disable();
|
||||
stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user