From cf794fc1c94221ee2d51600a43c9569650b01d81 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Sun, 7 Feb 2021 16:28:37 +0600 Subject: [PATCH] added logs and removed unnecessary repeated codes --- src/main/java/redis/clients/jedis/Jedis.java | 5 ++--- src/main/java/redis/clients/jedis/JedisPool.java | 14 +++++--------- .../redis/clients/jedis/JedisSentinelPool.java | 16 +++++++--------- .../redis/clients/jedis/ShardedJedisPool.java | 7 ------- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 5f745d9704..e605484ac9 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -29,7 +29,6 @@ import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; import redis.clients.jedis.params.LPosParams; -import redis.clients.jedis.util.Pool; import redis.clients.jedis.util.SafeEncoder; import redis.clients.jedis.util.Slowlog; @@ -40,7 +39,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand * @deprecated This will be private in future. */ @Deprecated - protected Pool dataSource = null; + protected JedisPoolAbstract dataSource = null; public Jedis() { super(); @@ -3608,7 +3607,7 @@ public Map pubsubNumSub(String... channels) { @Override public void close() { if (dataSource != null) { - Pool pool = this.dataSource; + JedisPoolAbstract pool = this.dataSource; this.dataSource = null; if (client.isBroken()) { pool.returnBrokenResource(this); diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index fb53789113..d7f9bdbb40 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -1,18 +1,20 @@ package redis.clients.jedis; import java.net.URI; - import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocketFactory; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.JedisURIHelper; public class JedisPool extends JedisPoolAbstract { + private static final Logger log = LoggerFactory.getLogger(JedisPool.class); + public JedisPool() { this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT); } @@ -329,13 +331,6 @@ public Jedis getResource() { return jedis; } - @Override - public void returnBrokenResource(final Jedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } - } - @Override public void returnResource(final Jedis resource) { if (resource != null) { @@ -344,6 +339,7 @@ public void returnResource(final Jedis resource) { returnResourceObject(resource); } catch (Exception e) { returnBrokenResource(resource); + log.debug("Resource is returned to the pool as broken", e); } } } diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index f830c2c24c..768b3da0c4 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -14,7 +14,12 @@ import redis.clients.jedis.exceptions.JedisException; public class JedisSentinelPool extends JedisPoolAbstract { - protected Logger log = LoggerFactory.getLogger(getClass().getName()); + + /** + * @deprecated This will be private in future. + */ + @Deprecated + protected static Logger log = LoggerFactory.getLogger(JedisSentinelPool.class); protected final GenericObjectPoolConfig poolConfig; @@ -309,13 +314,6 @@ public Jedis getResource() { } } - @Override - public void returnBrokenResource(final Jedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } - } - @Override public void returnResource(final Jedis resource) { if (resource != null) { @@ -324,7 +322,7 @@ public void returnResource(final Jedis resource) { returnResourceObject(resource); } catch (Exception e) { returnBrokenResource(resource); - throw new JedisException("Resource is returned to the pool as broken", e); + log.debug("Resource is returned to the pool as broken", e); } } } diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPool.java b/src/main/java/redis/clients/jedis/ShardedJedisPool.java index 89c671ec52..81e01b122a 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPool.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPool.java @@ -38,13 +38,6 @@ public ShardedJedis getResource() { return jedis; } - @Override - public void returnBrokenResource(final ShardedJedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } - } - @Override public void returnResource(final ShardedJedis resource) { if (resource != null) {