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

removed get JedisPool, refactored jedis summoners, new SinglePoolJedisSummoner, start version 0.8.0

This commit is contained in:
mohammed jasem alaajel 2022-07-06 23:04:09 +04:00
parent 839c8cd615
commit f7285ff4f1
8 changed files with 61 additions and 33 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<version>0.7.3-SNAPSHOT</version> <version>0.8.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -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()} * @deprecated this secluded to be removed when support for redis sentinel or redis cluster is finished, use {@link RedisBungeeAPI#requestJedis()}
* @since 0.6.5 * @since 0.6.5
*/ */
@Deprecated
public JedisPool getJedisPool() {
return this.plugin.getJedisPool();
}
/** /**
* This gives you instance of Jedis * This gives you instance of Jedis

View File

@ -3,6 +3,7 @@ package com.imaginarycode.minecraft.redisbungee.internal;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator; import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator;
import redis.clients.jedis.Jedis;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
@ -19,16 +20,20 @@ import java.util.concurrent.TimeUnit;
* @since 0.7.0 * @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(); RedisBungeeConfiguration getConfiguration();
int getCount(); int getCount();

View File

@ -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.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
import java.io.Closeable;
/** /**
* This class intended for future release to support redis sentinel or redis clusters * 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 * @since 0.7.0
* *
*/ */
public interface JedisSummoner { public interface JedisSummoner extends Closeable {
Jedis requestJedis(); Jedis requestJedis();
boolean isJedisAvailable(); boolean isJedisAvailable();
@Deprecated
JedisPool getJedisPool();
} }

View File

@ -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();
}
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<version>0.7.3-SNAPSHOT</version> <version>0.8.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -13,6 +13,8 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetwork
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.internal.*; 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.IOUtil;
import com.imaginarycode.minecraft.redisbungee.internal.util.LuaManager; import com.imaginarycode.minecraft.redisbungee.internal.util.LuaManager;
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.NameFetcher; 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 static final Gson gson = new Gson();
private RedisBungeeAPI api; private RedisBungeeAPI api;
private PubSubListener psl = null; private PubSubListener psl = null;
private JedisPool jedisPool; private JedisSummoner jedisSummoner;
private UUIDTranslator uuidTranslator; private UUIDTranslator uuidTranslator;
private RedisBungeeConfiguration configuration; private RedisBungeeConfiguration configuration;
private BungeeDataManager dataManager; private BungeeDataManager dataManager;
@ -128,17 +130,12 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override @Override
public Jedis requestJedis() { public Jedis requestJedis() {
return this.jedisPool.getResource(); return this.jedisSummoner.requestJedis();
} }
@Override @Override
public boolean isJedisAvailable() { public boolean isJedisAvailable() {
return !jedisPool.isClosed(); return this.jedisSummoner.isJedisAvailable();
}
@Override
public JedisPool getJedisPool() {
return this.jedisPool;
} }
@Override @Override
@ -333,7 +330,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override @Override
public void enable() { public void start() {
ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory(); ThreadFactory factory = ((ThreadPoolExecutor) getExecutorService()).getThreadFactory();
ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory); ScheduledExecutorService service = Executors.newScheduledThreadPool(24, factory);
try { try {
@ -490,7 +487,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
} }
@Override @Override
public void disable() { public void stop() {
if (isJedisAvailable()) { if (isJedisAvailable()) {
// Poison the PubSub listener // Poison the PubSub listener
psl.poison(); psl.poison();
@ -506,8 +503,11 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
RedisUtil.cleanUpPlayer(member, tmpRsc); RedisUtil.cleanUpPlayer(member, tmpRsc);
} }
} }
try {
this.jedisPool.destroy(); this.jedisSummoner.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
} }
@ -563,7 +563,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
try { try {
JedisPoolConfig config = new JedisPoolConfig(); JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8)); 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) { } catch (JedisConnectionException e) {
throw new RuntimeException("Unable to create Redis pool", 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."); getLogger().log(Level.INFO, "Successfully connected to Redis.");
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
this.jedisPool.destroy(); this.jedisSummoner.close();
this.jedisPool = null;
throw e; throw e;
} }
} else { } else {
@ -610,12 +609,12 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override @Override
public void onEnable() { public void onEnable() {
enable(); start();
} }
@Override @Override
public void onDisable() { public void onDisable() {
disable(); stop();
} }
@Override @Override

View File

@ -7,7 +7,7 @@
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>0.7.3-SNAPSHOT</version> <version>0.8.0-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>