DATAREDIS-462 - Polishing.

Updated javadoc, fixed indentation, organize imports and some minor refactoring.

Original Pull Request: #169
This commit is contained in:
Christoph Strobl
2016-02-17 14:17:12 +01:00
parent b58c18f85b
commit 1e5772d00b
26 changed files with 156 additions and 142 deletions

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.connection.lettuce;
import java.util.concurrent.TimeUnit;
import com.lambdaworks.redis.resource.ClientResources;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
@@ -31,6 +30,7 @@ import org.springframework.util.Assert;
import com.lambdaworks.redis.RedisAsyncConnection;
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.resource.ClientResources;
/**
* Default implementation of {@link LettucePool}.
@@ -41,7 +41,7 @@ import com.lambdaworks.redis.RedisURI;
*/
public class DefaultLettucePool implements LettucePool, InitializingBean {
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private GenericObjectPool<RedisAsyncConnection> internalPool;
private RedisClient client;
private int dbIndex = 0;
@@ -104,10 +104,9 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
@SuppressWarnings({ "rawtypes" })
public void afterPropertiesSet() {
if(clientResources != null) {
if (clientResources != null) {
this.client = RedisClient.create(clientResources, getRedisURI());
}
else {
} else {
this.client = RedisClient.create(getRedisURI());
}
@@ -283,19 +282,22 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
}
/**
* Returns the client resources to reuse the client infrastructure.
* @return client resources
* Get the {@link ClientResources} to reuse infrastructure.
*
* @return {@literal null} if not set.
* @since 1.7
*/
*/
public ClientResources getClientResources() {
return clientResources;
}
/**
* Sets the client resources to reuse the client infrastructure.
* @param clientResources
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
* Set to {@literal null} to not share resources.
*
* @param clientResources can be {@literal null}.
* @since 1.7
*/
*/
public void setClientResources(ClientResources clientResources) {
this.clientResources = clientResources;
}

View File

@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.lambdaworks.redis.resource.ClientResources;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
@@ -52,6 +51,7 @@ import com.lambdaworks.redis.RedisException;
import com.lambdaworks.redis.RedisFuture;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.cluster.RedisClusterClient;
import com.lambdaworks.redis.resource.ClientResources;
/**
* Connection factory creating <a href="http://github.com/mp911de/lettuce">Lettuce</a>-based connections.
@@ -390,24 +390,6 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
this.password = password;
}
/**
* Returns the client resources to reuse the client infrastructure.
* @return client resources
* @since 1.7
*/
public ClientResources getClientResources() {
return clientResources;
}
/**
* Sets the client resources to reuse the client infrastructure.
* @param clientResources
* @since 1.7
*/
public void setClientResources(ClientResources clientResources) {
this.clientResources = clientResources;
}
/**
* Returns the shutdown timeout for shutting down the RedisClient (in milliseconds).
*
@@ -428,6 +410,27 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
this.shutdownTimeout = shutdownTimeout;
}
/**
* Get the {@link ClientResources} to reuse infrastructure.
*
* @return {@literal null} if not set.
* @since 1.7
*/
public ClientResources getClientResources() {
return clientResources;
}
/**
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
* Set to {@literal null} to not share resources.
*
* @param clientResources can be {@literal null}.
* @since 1.7
*/
public void setClientResources(ClientResources clientResources) {
this.clientResources = clientResources;
}
/**
* Specifies if pipelined results should be converted to the expected data type. If false, results of
* {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the
@@ -488,8 +491,9 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
private AbstractRedisClient createRedisClient() {
if (isRedisSentinelAware()) {
RedisURI redisURI = getSentinelRedisURI();
if(clientResources == null) {
if (clientResources == null) {
return RedisClient.create(redisURI);
}
@@ -511,10 +515,9 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
}
RedisClusterClient clusterClient;
if(clientResources == null) {
if (clientResources == null) {
clusterClient = RedisClusterClient.create(initialUris);
}
else {
} else {
clusterClient = RedisClusterClient.create(clientResources, initialUris);
}
@@ -534,7 +537,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
builder.withPassword(password);
}
builder.withTimeout(timeout, TimeUnit.MILLISECONDS);
if(clientResources != null) {
if (clientResources != null) {
return RedisClient.create(clientResources, builder.build());
}

View File

@@ -18,10 +18,6 @@ package org.springframework.data.redis.connection.lettuce;
import java.io.IOException;
import java.util.List;
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.resource.ClientResources;
import org.springframework.data.redis.ExceptionTranslationStrategy;
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
import org.springframework.data.redis.connection.NamedNode;
@@ -30,6 +26,11 @@ import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.util.Assert;
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisSentinelAsyncConnection;
import com.lambdaworks.redis.RedisURI.Builder;
import com.lambdaworks.redis.resource.ClientResources;
/**
* @author Christoph Strobl
* @author Mark Paluch
@@ -45,6 +46,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
/**
* Creates a {@link LettuceSentinelConnection} with a dedicated client for a supplied {@link RedisNode}.
*
* @param sentinel The sentinel to connect to.
*/
public LettuceSentinelConnection(RedisNode sentinel) {
@@ -53,31 +55,38 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
/**
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port}.
* @param host hostname must not be {@literal null}
* @param port sentinel port
*
* @param host must not be {@literal null}.
* @param port sentinel port.
*/
public LettuceSentinelConnection(String host, int port) {
Assert.notNull(host, "Cannot create LettuceSentinelConnection using 'null' as host.");
redisClient = RedisClient.create(new RedisURI.Builder().redis(host, port).build());
redisClient = RedisClient.create(Builder.redis(host, port).build());
init();
}
/**
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port} and reuse
* existing {@code clientResources}.
* @param clientResources must not be {@literal null}
* @param host hostname must not be {@literal null}
* @param port sentinel port
* existing {@link ClientResources}.
*
* @param host must not be {@literal null}.
* @param port sentinel port.
* @param clientResources must not be {@literal null}.
*/
public LettuceSentinelConnection(ClientResources clientResources, String host, int port) {
public LettuceSentinelConnection(String host, int port, ClientResources clientResources) {
Assert.notNull(clientResources, "Cannot create LettuceSentinelConnection using 'null' as ClientResources.");
Assert.notNull(host, "Cannot create LettuceSentinelConnection using 'null' as host.");
redisClient = RedisClient.create(clientResources, new RedisURI.Builder().redis(host, port).build());
redisClient = RedisClient.create(clientResources, Builder.redis(host, port).build());
init();
}
/**
* Creates a {@link LettuceSentinelConnection} using a supplied {@link RedisClient}.
*
* @param redisClient
*/
public LettuceSentinelConnection(RedisClient redisClient) {
@@ -89,6 +98,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
/**
* Creates a {@link LettuceSentinelConnection} using a supplied redis connection.
*
* @param connection native Lettuce connection, must not be {@literal null}
*/
protected LettuceSentinelConnection(RedisSentinelAsyncConnection<String, String> connection) {
@@ -181,8 +191,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
Assert.hasText(server.getHost(), "Host must not be 'null' for server to monitor.");
Assert.notNull(server.getPort(), "Port must not be 'null' for server to monitor.");
Assert.notNull(server.getQuorum(), "Quorum must not be 'null' for server to monitor.");
connection.monitor(server.getName(), server.getHost(), server.getPort().intValue(), server.getQuorum()
.intValue());
connection.monitor(server.getName(), server.getHost(), server.getPort().intValue(), server.getQuorum().intValue());
}
/*
@@ -194,7 +203,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
connection.close();
connection = null;
if(redisClient != null) {
if (redisClient != null) {
redisClient.shutdown();
}
}
@@ -209,7 +218,6 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
return redisClient.connectSentinelAsync();
}
@Override
public boolean isOpen() {
return connection != null && connection.isOpen();