mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Make summoner create customized JedisPooled that can't be closed
This commit is contained in:
parent
4d58ee1742
commit
a382a298a1
@ -63,7 +63,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>4.3.0</version>
|
<version>4.3.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -12,6 +12,7 @@ import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
|||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||||
import redis.clients.jedis.*;
|
import redis.clients.jedis.*;
|
||||||
|
import redis.clients.jedis.providers.PooledConnectionProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -113,13 +114,13 @@ public interface ConfigLoader {
|
|||||||
JedisPoolConfig config = new JedisPoolConfig();
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
config.setMaxTotal(node.getNode("compatibility-max-connections").getInt(3));
|
config.setMaxTotal(node.getNode("compatibility-max-connections").getInt(3));
|
||||||
config.setBlockWhenExhausted(true);
|
config.setBlockWhenExhausted(true);
|
||||||
jedisPool = new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL);
|
jedisPool = new JedisPool(config, redisServer, redisPort, 5000, redisPassword, useSSL);
|
||||||
plugin.logInfo("Compatibility JedisPool was created");
|
plugin.logInfo("Compatibility JedisPool was created");
|
||||||
}
|
}
|
||||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
||||||
poolConfig.setMaxTotal(maxConnections);
|
poolConfig.setMaxTotal(maxConnections);
|
||||||
poolConfig.setBlockWhenExhausted(true);
|
poolConfig.setBlockWhenExhausted(true);
|
||||||
summoner = new JedisPooledSummoner(new JedisPooled(poolConfig, redisServer, redisPort, 0, redisPassword, useSSL), jedisPool);
|
summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().timeoutMillis(5000).password(redisPassword).build()), poolConfig), jedisPool);
|
||||||
redisBungeeMode = RedisBungeeMode.SINGLE;
|
redisBungeeMode = RedisBungeeMode.SINGLE;
|
||||||
}
|
}
|
||||||
plugin.logInfo("Successfully connected to Redis.");
|
plugin.logInfo("Successfully connected to Redis.");
|
||||||
|
@ -3,16 +3,17 @@ package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
|||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPooled;
|
import redis.clients.jedis.JedisPooled;
|
||||||
|
import redis.clients.jedis.providers.PooledConnectionProvider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
||||||
|
|
||||||
private final JedisPooled jedisPooled;
|
private final PooledConnectionProvider connectionProvider;
|
||||||
private final JedisPool jedisPool;
|
private final JedisPool jedisPool;
|
||||||
|
|
||||||
public JedisPooledSummoner(JedisPooled jedisPooled, JedisPool jedisPool) {
|
public JedisPooledSummoner(PooledConnectionProvider connectionProvider, JedisPool jedisPool) {
|
||||||
this.jedisPooled = jedisPooled;
|
this.connectionProvider = connectionProvider;
|
||||||
this.jedisPool = jedisPool;
|
this.jedisPool = jedisPool;
|
||||||
// test connections
|
// test connections
|
||||||
if (jedisPool != null) {
|
if (jedisPool != null) {
|
||||||
@ -20,7 +21,9 @@ public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
|||||||
// Test the connection to make sure configuration is right
|
// Test the connection to make sure configuration is right
|
||||||
jedis.ping();
|
jedis.ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
final JedisPooled jedisPooled = this.obtainResource();
|
||||||
jedisPooled.set("random_data", "0");
|
jedisPooled.set("random_data", "0");
|
||||||
jedisPooled.del("random_data");
|
jedisPooled.del("random_data");
|
||||||
|
|
||||||
@ -28,7 +31,8 @@ public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JedisPooled obtainResource() {
|
public JedisPooled obtainResource() {
|
||||||
return this.jedisPooled;
|
// create UnClosable JedisPool *disposable*
|
||||||
|
return new NotClosableJedisPooled(this.connectionProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JedisPool getCompatibilityJedisPool() {
|
public JedisPool getCompatibilityJedisPool() {
|
||||||
@ -40,7 +44,7 @@ public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
|||||||
if (this.jedisPool != null) {
|
if (this.jedisPool != null) {
|
||||||
this.jedisPool.close();
|
this.jedisPool.close();
|
||||||
}
|
}
|
||||||
this.jedisPooled.close();
|
this.connectionProvider.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
||||||
|
|
||||||
|
import redis.clients.jedis.JedisPooled;
|
||||||
|
import redis.clients.jedis.providers.PooledConnectionProvider;
|
||||||
|
|
||||||
|
|
||||||
|
public class NotClosableJedisPooled extends JedisPooled {
|
||||||
|
NotClosableJedisPooled(PooledConnectionProvider provider) {
|
||||||
|
super(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -14,5 +14,4 @@ public interface Summoner<P> extends Closeable {
|
|||||||
|
|
||||||
P obtainResource();
|
P obtainResource();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user