Skip to content

Commit 10b195f

Browse files
authored
Remove JedisPoolAbstract class, hide Pool.initPool() method and related changes (#1734)
* Remove JedisPoolAbstract and related changes JedisPoolAbstract itself was doing nothing except acting as access point of Pool<Jedis> from redis.clients.jedis package. Using Pool<Jedis> directly seems better. * Update JavaDoc formatting
1 parent d26ec0d commit 10b195f

File tree

7 files changed

+28
-153
lines changed

7 files changed

+28
-153
lines changed

src/main/java/redis/clients/jedis/Jedis.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
import redis.clients.jedis.commands.*;
1818
import redis.clients.jedis.params.*;
1919
import redis.clients.jedis.resps.*;
20+
import redis.clients.jedis.util.Pool;
2021
import redis.clients.jedis.util.SafeEncoder;
2122
import redis.clients.jedis.util.Slowlog;
2223

2324
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands,
2425
AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands, SentinelCommands,
2526
ModuleCommands {
2627

27-
/**
28-
* @deprecated This will be private in future.
29-
*/
30-
@Deprecated
31-
protected JedisPoolAbstract dataSource = null;
28+
private Pool<Jedis> dataSource = null;
3229

3330
public Jedis() {
3431
super();
@@ -3944,7 +3941,7 @@ public Map<String, String> pubsubNumSub(String... channels) {
39443941
@Override
39453942
public void close() {
39463943
if (dataSource != null) {
3947-
JedisPoolAbstract pool = this.dataSource;
3944+
Pool<Jedis> pool = this.dataSource;
39483945
this.dataSource = null;
39493946
if (isBroken()) {
39503947
pool.returnBrokenResource(this);
@@ -3956,7 +3953,7 @@ public void close() {
39563953
}
39573954
}
39583955

3959-
public void setDataSource(JedisPoolAbstract jedisPool) {
3956+
public void setDataSource(Pool<Jedis> jedisPool) {
39603957
this.dataSource = jedisPool;
39613958
}
39623959

src/main/java/redis/clients/jedis/JedisPool.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import org.slf4j.LoggerFactory;
1212

1313
import redis.clients.jedis.util.JedisURIHelper;
14+
import redis.clients.jedis.util.Pool;
1415

15-
public class JedisPool extends JedisPoolAbstract {
16+
public class JedisPool extends Pool<Jedis> {
1617

1718
private static final Logger log = LoggerFactory.getLogger(JedisPool.class);
1819

@@ -29,43 +30,36 @@ public JedisPool(String host, int port) {
2930
}
3031

3132
/**
33+
* WARNING: This constructor only accepts a uri string as {@code url}.
34+
* {@link JedisURIHelper#isValid(java.net.URI)} can be used before this.
35+
* <p>
36+
* To use a host string, {@link #JedisPool(java.lang.String, int)} can be used with
37+
* {@link Protocol#DEFAULT_PORT}.
38+
*
3239
* @param url
33-
* @deprecated This constructor will not accept a host string in future. It will accept only a uri
34-
* string. You can use {@link JedisURIHelper#isValid(java.net.URI)} before this.
3540
*/
36-
@Deprecated
3741
public JedisPool(final String url) {
38-
URI uri = URI.create(url);
39-
if (JedisURIHelper.isValid(uri)) {
40-
initPool(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(uri,
41-
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null));
42-
} else {
43-
initPool(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(url, Protocol.DEFAULT_PORT,
44-
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null));
45-
}
42+
this(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(URI.create(url), Protocol.DEFAULT_TIMEOUT,
43+
Protocol.DEFAULT_TIMEOUT, null));
4644
}
4745

4846
/**
47+
* WARNING: This constructor only accepts a uri string as {@code url}.
48+
* {@link JedisURIHelper#isValid(java.net.URI)} can be used before this.
49+
* <p>
50+
* To use a host string,
51+
* {@link #JedisPool(java.lang.String, int, boolean, javax.net.ssl.SSLSocketFactory, javax.net.ssl.SSLParameters, javax.net.ssl.HostnameVerifier)}
52+
* can be used with {@link Protocol#DEFAULT_PORT} and {@code ssl=true}.
53+
*
4954
* @param url
5055
* @param sslSocketFactory
5156
* @param sslParameters
5257
* @param hostnameVerifier
53-
* @deprecated This constructor will not accept a host string in future. It will accept only a uri
54-
* string. You can use {@link JedisURIHelper#isValid(java.net.URI)} before this.
5558
*/
56-
@Deprecated
5759
public JedisPool(final String url, final SSLSocketFactory sslSocketFactory,
5860
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
59-
URI uri = URI.create(url);
60-
if (JedisURIHelper.isValid(uri)) {
61-
initPool(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(uri,
62-
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null, sslSocketFactory,
63-
sslParameters, hostnameVerifier));
64-
} else {
65-
initPool(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(url, Protocol.DEFAULT_PORT,
66-
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null,
67-
false, null, null, null));
68-
}
61+
this(new GenericObjectPoolConfig<Jedis>(), new JedisFactory(URI.create(url), Protocol.DEFAULT_TIMEOUT,
62+
Protocol.DEFAULT_TIMEOUT, null, sslSocketFactory, sslParameters, hostnameVerifier));
6963
}
7064

7165
public JedisPool(final URI uri) {

src/main/java/redis/clients/jedis/JedisPoolAbstract.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/redis/clients/jedis/JedisSentinelPool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
import redis.clients.jedis.exceptions.JedisConnectionException;
1616
import redis.clients.jedis.exceptions.JedisException;
17+
import redis.clients.jedis.util.Pool;
1718

18-
public class JedisSentinelPool extends JedisPoolAbstract {
19+
public class JedisSentinelPool extends Pool<Jedis> {
1920

2021
private static final Logger LOG = LoggerFactory.getLogger(JedisSentinelPool.class);
2122

src/main/java/redis/clients/jedis/util/Pool.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,10 @@
1414

1515
public abstract class Pool<T> implements Closeable {
1616

17-
/**
18-
* @deprecated This will be private in future.
19-
*/
20-
@Deprecated
21-
protected GenericObjectPool<T> internalPool;
22-
23-
/**
24-
* Using this constructor means you have to set and initialize the internalPool yourself.
25-
*
26-
* @deprecated This constructor will be removed in future.
27-
*/
28-
@Deprecated
29-
public Pool() {
30-
}
17+
private final GenericObjectPool<T> internalPool;
3118

3219
public Pool(final GenericObjectPoolConfig<T> poolConfig, PooledObjectFactory<T> factory) {
33-
initPool(poolConfig, factory);
20+
this.internalPool = new GenericObjectPool<>(factory, poolConfig);
3421
}
3522

3623
@Override
@@ -42,24 +29,6 @@ public boolean isClosed() {
4229
return this.internalPool.isClosed();
4330
}
4431

45-
/**
46-
* @param poolConfig
47-
* @param factory
48-
* @deprecated This method will be private in future.
49-
*/
50-
@Deprecated
51-
public void initPool(final GenericObjectPoolConfig<T> poolConfig, PooledObjectFactory<T> factory) {
52-
53-
if (this.internalPool != null) {
54-
try {
55-
closeInternalPool();
56-
} catch (Exception e) {
57-
}
58-
}
59-
60-
this.internalPool = new GenericObjectPool<>(factory, poolConfig);
61-
}
62-
6332
/**
6433
* This call only clears idle instances, not borrowed instances.
6534
*/

src/test/java/redis/clients/jedis/tests/JedisPoolTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ public void passivateObject(PooledObject<Jedis> p) throws Exception {
252252

253253
GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig<>();
254254
config.setMaxTotal(1);
255-
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");
256-
pool.initPool(config, new CrashingJedisPooledObjectFactory());
255+
JedisPool pool = new JedisPool(config, new CrashingJedisPooledObjectFactory());
257256
Jedis crashingJedis = pool.getResource();
258257

259258
try {

src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -218,62 +218,6 @@ public void ensureSafeTwiceFailover() throws InterruptedException {
218218
// you can test failover as much as possible
219219
}
220220

221-
@Test
222-
public void returnResourceDestroysResourceOnException() {
223-
class CrashingJedis extends Jedis {
224-
public CrashingJedis(final HostAndPort hp) {
225-
super(hp);
226-
}
227-
228-
@Override
229-
public void resetState() {
230-
throw new RuntimeException();
231-
}
232-
}
233-
234-
final AtomicInteger destroyed = new AtomicInteger(0);
235-
236-
class CrashingJedisPooledObjectFactory implements PooledObjectFactory<Jedis> {
237-
238-
@Override
239-
public PooledObject<Jedis> makeObject() throws Exception {
240-
return new DefaultPooledObject<Jedis>(new CrashingJedis(master));
241-
}
242-
243-
@Override
244-
public void destroyObject(PooledObject<Jedis> p) throws Exception {
245-
destroyed.incrementAndGet();
246-
}
247-
248-
@Override
249-
public boolean validateObject(PooledObject<Jedis> p) {
250-
return true;
251-
}
252-
253-
@Override
254-
public void activateObject(PooledObject<Jedis> p) throws Exception {
255-
}
256-
257-
@Override
258-
public void passivateObject(PooledObject<Jedis> p) throws Exception {
259-
}
260-
}
261-
262-
GenericObjectPoolConfig<Jedis> config = new GenericObjectPoolConfig<>();
263-
config.setMaxTotal(1);
264-
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
265-
"foobared", 2);
266-
pool.initPool(config, new CrashingJedisPooledObjectFactory());
267-
Jedis crashingJedis = pool.getResource();
268-
269-
try {
270-
crashingJedis.close();
271-
} catch (Exception ignored) {
272-
}
273-
274-
assertEquals(1, destroyed.get());
275-
}
276-
277221
private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
278222
HostAndPort oldMaster = pool.getCurrentHostMaster();
279223

0 commit comments

Comments
 (0)