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

fix mess up in API

This commit is contained in:
mohammed jasem alaajel 2022-07-25 19:13:25 +04:00
parent 8f602407b5
commit 6910c96f67
5 changed files with 13 additions and 17 deletions

View File

@ -5,11 +5,13 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
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.net.InetAddress; import java.net.InetAddress;
@ -389,14 +391,15 @@ public class RedisBungeeAPI {
/** /**
* This gives you instance of Jedis Cluster * This gives you instance of Jedis Cluster
* WARNING DO NOT USE {@link JedisCluster#close()} it will break the functionally
* *
* @return {@link redis.clients.jedis.JedisCluster} * @return {@link redis.clients.jedis.JedisCluster}
* @since 0.8.0 * @since 0.8.0
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER} * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER}
*/ */
public Jedis requestClusterJedis() { public JedisCluster requestClusterJedis() {
if (getMode() == RedisBungeeMode.CLUSTER) { if (getMode() == RedisBungeeMode.CLUSTER) {
return ((JedisSummoner) this.plugin.getSummoner()).obtainResource(); return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource();
} else { } else {
throw new IllegalStateException("Mode is not " + RedisBungeeMode.CLUSTER); throw new IllegalStateException("Mode is not " + RedisBungeeMode.CLUSTER);
} }

View File

@ -4,7 +4,7 @@ package com.imaginarycode.minecraft.redisbungee.api.config;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ConfigurationNode;
@ -88,10 +88,10 @@ public interface ConfigLoader {
throw new RuntimeException("No redis cluster servers specified"); throw new RuntimeException("No redis cluster servers specified");
} }
if (redisPassword != null) { if (redisPassword != null) {
summoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, proxyId, redisPassword, poolConfig, useSSL)); summoner = new JedisClusterSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, proxyId, redisPassword, poolConfig, useSSL));
} else { } else {
plugin.logWarn("SSL option is ignored in Cluster mode if no PASSWORD is set"); plugin.logWarn("SSL option is ignored in Cluster mode if no PASSWORD is set");
summoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, poolConfig)); summoner = new JedisClusterSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, poolConfig));
} }
redisBungeeMode = RedisBungeeMode.CLUSTER; redisBungeeMode = RedisBungeeMode.CLUSTER;
} else { } else {

View File

@ -4,11 +4,11 @@ import redis.clients.jedis.JedisCluster;
import java.io.IOException; import java.io.IOException;
public class ClusterJedisSummoner implements Summoner<JedisCluster> { public class JedisClusterSummoner implements Summoner<JedisCluster> {
public final JedisCluster jedisCluster; public final JedisCluster jedisCluster;
private boolean closed = false; private boolean closed = false;
public ClusterJedisSummoner(JedisCluster jedisCluster) { public JedisClusterSummoner(JedisCluster jedisCluster) {
this.jedisCluster = jedisCluster; this.jedisCluster = jedisCluster;
// test the connection // test the connection
jedisCluster.set("random_data", "0"); jedisCluster.set("random_data", "0");

View File

@ -2,7 +2,7 @@ package com.imaginarycode.minecraft.redisbungee.api.tasks;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
@ -71,8 +71,8 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> {
} else if (api.getMode() == RedisBungeeMode.CLUSTER) { } else if (api.getMode() == RedisBungeeMode.CLUSTER) {
// Jedis cluster does not need new instance since its single instance anyways. // Jedis cluster does not need new instance since its single instance anyways.
ClusterJedisSummoner clusterJedisSummoner = (ClusterJedisSummoner) summoner; JedisClusterSummoner jedisClusterSummoner = (JedisClusterSummoner) summoner;
return this.clusterJedisTask(clusterJedisSummoner.obtainResource()); return this.clusterJedisTask(jedisClusterSummoner.obtainResource());
} }
return null; return null;
} }

View File

@ -6,12 +6,9 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.imaginarycode.minecraft.redisbungee.api.*; import com.imaginarycode.minecraft.redisbungee.api.*;
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration; import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import com.imaginarycode.minecraft.redisbungee.api.tasks.HeartbeatTask; import com.imaginarycode.minecraft.redisbungee.api.tasks.HeartbeatTask;
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
@ -40,10 +37,6 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.scheduler.ScheduledTask; import com.velocitypowered.api.scheduler.ScheduledTask;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import redis.clients.jedis.*; import redis.clients.jedis.*;
import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisConnectionException;