Remove unneeded threadpool (testing has shown for it to be unneeded)

This commit is contained in:
Govindas 2020-10-24 13:29:49 +03:00
parent afab303292
commit 8244cf4974
3 changed files with 14 additions and 20 deletions

View File

@ -39,8 +39,11 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
this.plugin = plugin; this.plugin = plugin;
Configuration config = this.plugin.getConfig(); Configuration config = this.plugin.getConfig();
JedisPoolConfig JConfig = new JedisPoolConfig(); JedisPoolConfig JConfig = new JedisPoolConfig();
JConfig.setMaxTotal(config.getInt("Redis.MaxConnections")); int maxConnections = config.getInt("Redis.MaxConnections");
JConfig.setMaxIdle(config.getInt("Redis.MaxConnections")); if (maxConnections < 2) { maxConnections = 2; }
JConfig.setMaxTotal(maxConnections);
JConfig.setMaxIdle(maxConnections);
JConfig.setMinIdle(1); JConfig.setMinIdle(1);
JConfig.setBlockWhenExhausted(true); JConfig.setBlockWhenExhausted(true);
this.jedisPool = new JedisPool(JConfig, this.jedisPool = new JedisPool(JConfig,
@ -49,7 +52,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
config.getInt("Redis.TimeOut"), config.getInt("Redis.TimeOut"),
config.getString("Redis.Password"), config.getString("Redis.Password"),
config.getBoolean("Redis.useTLS")); config.getBoolean("Redis.useTLS"));
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads")); RedisService = Executors.newSingleThreadExecutor();
try { try {
this.subscribeJedis = this.jedisPool.getResource(); this.subscribeJedis = this.jedisPool.getResource();
} catch (Exception ignored) { } catch (Exception ignored) {
@ -73,7 +76,6 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
int byteArr2dSize = 1; int byteArr2dSize = 1;
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize]; byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
boolean reInitializeByteArray; boolean reInitializeByteArray;
// Loop that reInitialize array IF array size is not enough // Loop that reInitialize array IF array size is not enough
do { do {
reInitializeByteArray = false; reInitializeByteArray = false;
@ -91,6 +93,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
} while (reInitializeByteArray); } while (reInitializeByteArray);
this.subscribeJedis.subscribe(this, channelsInByte); this.subscribeJedis.subscribe(this, channelsInByte);
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnection to redis has failed! &ereconnecting...")); plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnection to redis has failed! &ereconnecting..."));
if (this.subscribeJedis != null) { if (this.subscribeJedis != null) {
@ -157,10 +160,6 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
return jedisPool; return jedisPool;
} }
public ExecutorService getRedisService() {
return RedisService;
}
public Encryption getEncryption() { public Encryption getEncryption() {
return encryption; return encryption;
} }

View File

@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
public class EffSendMessage extends Effect { public class EffSendMessage extends Effect {
static { static {
Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with [message] %string%", "send redis message %string% to [channel] %string%"); Skript.registerEffect(EffSendMessage.class, "send redis message %string% to [channel] %string%");
} }
@ -43,7 +43,7 @@ public class EffSendMessage extends Effect {
} }
assert plugin != null; assert plugin != null;
RedisManager manager = plugin.getRm(); RedisManager manager = plugin.getRm();
manager.getRedisService().execute(() -> { //manager.getRedisService().execute(() -> {
BinaryJedis j = manager.getJedisPool().getResource(); BinaryJedis j = manager.getJedisPool().getResource();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("Message", message); json.put("Message", message);
@ -57,7 +57,7 @@ public class EffSendMessage extends Effect {
} }
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg); j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
j.close(); j.close();
}); //});
} }
@ -69,13 +69,8 @@ public class EffSendMessage extends Effect {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
if (matchedPattern == 0) {
this.channel = (Expression<String>) expressions[0];
this.message = (Expression<String>) expressions[1];
} else {
this.channel = (Expression<String>) expressions[1];
this.message = (Expression<String>) expressions[0]; this.message = (Expression<String>) expressions[0];
} this.channel = (Expression<String>) expressions[1];
return true; return true;
} }

View File

@ -3,8 +3,8 @@ Redis:
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses #it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU" Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1" Host: "127.0.0.1"
MaxConnections: 20 #must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
Threads: 10 MaxConnections: 2
#the default Redis port #the default Redis port
Port: 6379 Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message #time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message