Skip to content

Commit 1e5772d

Browse files
DATAREDIS-462 - Polishing.
Updated javadoc, fixed indentation, organize imports and some minor refactoring. Original Pull Request: #169
1 parent b58c18f commit 1e5772d

26 files changed

+156
-142
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.concurrent.TimeUnit;
1919

20-
import com.lambdaworks.redis.resource.ClientResources;
2120
import org.apache.commons.pool2.BasePooledObjectFactory;
2221
import org.apache.commons.pool2.PooledObject;
2322
import org.apache.commons.pool2.impl.DefaultPooledObject;
@@ -31,6 +30,7 @@
3130
import com.lambdaworks.redis.RedisAsyncConnection;
3231
import com.lambdaworks.redis.RedisClient;
3332
import com.lambdaworks.redis.RedisURI;
33+
import com.lambdaworks.redis.resource.ClientResources;
3434

3535
/**
3636
* Default implementation of {@link LettucePool}.
@@ -41,7 +41,7 @@
4141
*/
4242
public class DefaultLettucePool implements LettucePool, InitializingBean {
4343

44-
@SuppressWarnings("rawtypes")//
44+
@SuppressWarnings("rawtypes") //
4545
private GenericObjectPool<RedisAsyncConnection> internalPool;
4646
private RedisClient client;
4747
private int dbIndex = 0;
@@ -104,10 +104,9 @@ public boolean isRedisSentinelAware() {
104104
@SuppressWarnings({ "rawtypes" })
105105
public void afterPropertiesSet() {
106106

107-
if(clientResources != null) {
107+
if (clientResources != null) {
108108
this.client = RedisClient.create(clientResources, getRedisURI());
109-
}
110-
else {
109+
} else {
111110
this.client = RedisClient.create(getRedisURI());
112111
}
113112

@@ -283,19 +282,22 @@ public void setTimeout(long timeout) {
283282
}
284283

285284
/**
286-
* Returns the client resources to reuse the client infrastructure.
287-
* @return client resources
285+
* Get the {@link ClientResources} to reuse infrastructure.
286+
*
287+
* @return {@literal null} if not set.
288288
* @since 1.7
289-
*/
289+
*/
290290
public ClientResources getClientResources() {
291291
return clientResources;
292292
}
293293

294294
/**
295-
* Sets the client resources to reuse the client infrastructure.
296-
* @param clientResources
295+
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
296+
* Set to {@literal null} to not share resources.
297+
*
298+
* @param clientResources can be {@literal null}.
297299
* @since 1.7
298-
*/
300+
*/
299301
public void setClientResources(ClientResources clientResources) {
300302
this.clientResources = clientResources;
301303
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.List;
2121
import java.util.concurrent.TimeUnit;
2222

23-
import com.lambdaworks.redis.resource.ClientResources;
2423
import org.apache.commons.logging.Log;
2524
import org.apache.commons.logging.LogFactory;
2625
import org.springframework.beans.factory.DisposableBean;
@@ -52,6 +51,7 @@
5251
import com.lambdaworks.redis.RedisFuture;
5352
import com.lambdaworks.redis.RedisURI;
5453
import com.lambdaworks.redis.cluster.RedisClusterClient;
54+
import com.lambdaworks.redis.resource.ClientResources;
5555

5656
/**
5757
* Connection factory creating <a href="http://github.com/mp911de/lettuce">Lettuce</a>-based connections.
@@ -390,24 +390,6 @@ public void setPassword(String password) {
390390
this.password = password;
391391
}
392392

393-
/**
394-
* Returns the client resources to reuse the client infrastructure.
395-
* @return client resources
396-
* @since 1.7
397-
*/
398-
public ClientResources getClientResources() {
399-
return clientResources;
400-
}
401-
402-
/**
403-
* Sets the client resources to reuse the client infrastructure.
404-
* @param clientResources
405-
* @since 1.7
406-
*/
407-
public void setClientResources(ClientResources clientResources) {
408-
this.clientResources = clientResources;
409-
}
410-
411393
/**
412394
* Returns the shutdown timeout for shutting down the RedisClient (in milliseconds).
413395
*
@@ -428,6 +410,27 @@ public void setShutdownTimeout(long shutdownTimeout) {
428410
this.shutdownTimeout = shutdownTimeout;
429411
}
430412

413+
/**
414+
* Get the {@link ClientResources} to reuse infrastructure.
415+
*
416+
* @return {@literal null} if not set.
417+
* @since 1.7
418+
*/
419+
public ClientResources getClientResources() {
420+
return clientResources;
421+
}
422+
423+
/**
424+
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
425+
* Set to {@literal null} to not share resources.
426+
*
427+
* @param clientResources can be {@literal null}.
428+
* @since 1.7
429+
*/
430+
public void setClientResources(ClientResources clientResources) {
431+
this.clientResources = clientResources;
432+
}
433+
431434
/**
432435
* Specifies if pipelined results should be converted to the expected data type. If false, results of
433436
* {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the
@@ -488,8 +491,9 @@ protected RedisAsyncConnection<byte[], byte[]> createLettuceConnector() {
488491
private AbstractRedisClient createRedisClient() {
489492

490493
if (isRedisSentinelAware()) {
494+
491495
RedisURI redisURI = getSentinelRedisURI();
492-
if(clientResources == null) {
496+
if (clientResources == null) {
493497
return RedisClient.create(redisURI);
494498
}
495499

@@ -511,10 +515,9 @@ private AbstractRedisClient createRedisClient() {
511515
}
512516

513517
RedisClusterClient clusterClient;
514-
if(clientResources == null) {
518+
if (clientResources == null) {
515519
clusterClient = RedisClusterClient.create(initialUris);
516-
}
517-
else {
520+
} else {
518521
clusterClient = RedisClusterClient.create(clientResources, initialUris);
519522
}
520523

@@ -534,7 +537,7 @@ private AbstractRedisClient createRedisClient() {
534537
builder.withPassword(password);
535538
}
536539
builder.withTimeout(timeout, TimeUnit.MILLISECONDS);
537-
if(clientResources != null) {
540+
if (clientResources != null) {
538541
return RedisClient.create(clientResources, builder.build());
539542
}
540543

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
import java.io.IOException;
1919
import java.util.List;
2020

21-
import com.lambdaworks.redis.RedisClient;
22-
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
23-
import com.lambdaworks.redis.RedisURI;
24-
import com.lambdaworks.redis.resource.ClientResources;
2521
import org.springframework.data.redis.ExceptionTranslationStrategy;
2622
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
2723
import org.springframework.data.redis.connection.NamedNode;
@@ -30,6 +26,11 @@
3026
import org.springframework.data.redis.connection.RedisServer;
3127
import org.springframework.util.Assert;
3228

29+
import com.lambdaworks.redis.RedisClient;
30+
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
31+
import com.lambdaworks.redis.RedisURI.Builder;
32+
import com.lambdaworks.redis.resource.ClientResources;
33+
3334
/**
3435
* @author Christoph Strobl
3536
* @author Mark Paluch
@@ -45,6 +46,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
4546

4647
/**
4748
* Creates a {@link LettuceSentinelConnection} with a dedicated client for a supplied {@link RedisNode}.
49+
*
4850
* @param sentinel The sentinel to connect to.
4951
*/
5052
public LettuceSentinelConnection(RedisNode sentinel) {
@@ -53,31 +55,38 @@ public LettuceSentinelConnection(RedisNode sentinel) {
5355

5456
/**
5557
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port}.
56-
* @param host hostname must not be {@literal null}
57-
* @param port sentinel port
58+
*
59+
* @param host must not be {@literal null}.
60+
* @param port sentinel port.
5861
*/
5962
public LettuceSentinelConnection(String host, int port) {
63+
6064
Assert.notNull(host, "Cannot create LettuceSentinelConnection using 'null' as host.");
61-
redisClient = RedisClient.create(new RedisURI.Builder().redis(host, port).build());
65+
66+
redisClient = RedisClient.create(Builder.redis(host, port).build());
6267
init();
6368
}
6469

6570
/**
6671
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port} and reuse
67-
* existing {@code clientResources}.
68-
* @param clientResources must not be {@literal null}
69-
* @param host hostname must not be {@literal null}
70-
* @param port sentinel port
72+
* existing {@link ClientResources}.
73+
*
74+
* @param host must not be {@literal null}.
75+
* @param port sentinel port.
76+
* @param clientResources must not be {@literal null}.
7177
*/
72-
public LettuceSentinelConnection(ClientResources clientResources, String host, int port) {
78+
public LettuceSentinelConnection(String host, int port, ClientResources clientResources) {
79+
7380
Assert.notNull(clientResources, "Cannot create LettuceSentinelConnection using 'null' as ClientResources.");
7481
Assert.notNull(host, "Cannot create LettuceSentinelConnection using 'null' as host.");
75-
redisClient = RedisClient.create(clientResources, new RedisURI.Builder().redis(host, port).build());
82+
83+
redisClient = RedisClient.create(clientResources, Builder.redis(host, port).build());
7684
init();
7785
}
7886

7987
/**
8088
* Creates a {@link LettuceSentinelConnection} using a supplied {@link RedisClient}.
89+
*
8190
* @param redisClient
8291
*/
8392
public LettuceSentinelConnection(RedisClient redisClient) {
@@ -89,6 +98,7 @@ public LettuceSentinelConnection(RedisClient redisClient) {
8998

9099
/**
91100
* Creates a {@link LettuceSentinelConnection} using a supplied redis connection.
101+
*
92102
* @param connection native Lettuce connection, must not be {@literal null}
93103
*/
94104
protected LettuceSentinelConnection(RedisSentinelAsyncConnection<String, String> connection) {
@@ -181,8 +191,7 @@ public void monitor(RedisServer server) {
181191
Assert.hasText(server.getHost(), "Host must not be 'null' for server to monitor.");
182192
Assert.notNull(server.getPort(), "Port must not be 'null' for server to monitor.");
183193
Assert.notNull(server.getQuorum(), "Quorum must not be 'null' for server to monitor.");
184-
connection.monitor(server.getName(), server.getHost(), server.getPort().intValue(), server.getQuorum()
185-
.intValue());
194+
connection.monitor(server.getName(), server.getHost(), server.getPort().intValue(), server.getQuorum().intValue());
186195
}
187196

188197
/*
@@ -194,7 +203,7 @@ public void close() throws IOException {
194203
connection.close();
195204
connection = null;
196205

197-
if(redisClient != null) {
206+
if (redisClient != null) {
198207
redisClient.shutdown();
199208
}
200209
}
@@ -209,7 +218,6 @@ private RedisSentinelAsyncConnection<String, String> connectSentinel() {
209218
return redisClient.connectSentinelAsync();
210219
}
211220

212-
213221
@Override
214222
public boolean isOpen() {
215223
return connection != null && connection.isOpen();

0 commit comments

Comments
 (0)