From c34067f6d4c125657eeb4f9a3937c53cc21d0b48 Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 11 Aug 2016 17:09:02 -0700 Subject: [PATCH] SGF-508 - Fixup and polish Redis Server Java configuration meta-data using @Enable annotations. --- .../config/annotation/EnableRedisServer.java | 4 ++-- .../annotation/RedisServerConfiguration.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableRedisServer.java b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableRedisServer.java index af91dc86..bbef33d9 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableRedisServer.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableRedisServer.java @@ -50,13 +50,13 @@ public @interface EnableRedisServer { * * Defaults to {@literal localhost}. */ - String bindAddress() default "localhost"; + String bindAddress() default ""; /** * Configures the Network port on which the Redis server will listen for Redis client connections. * * Defaults to {@literal 6379}. */ - int port() default 6379; + int port() default RedisServerConfiguration.DEFAULT_REDIS_PORT; } diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/RedisServerConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/RedisServerConfiguration.java index 1de73adc..8d8cbe42 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/RedisServerConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/RedisServerConfiguration.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Properties; import org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport; +import org.springframework.data.gemfire.util.PropertiesBuilder; /** * The RedisServerConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} @@ -28,11 +29,14 @@ import org.springframework.data.gemfire.config.annotation.support.EmbeddedServic * an embedded Redis server. * * @author John Blum + * @see org.springframework.data.gemfire.config.annotation.EnableRedisServer * @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport * @since 1.9.0 */ public class RedisServerConfiguration extends EmbeddedServiceConfigurationSupport { + protected static final int DEFAULT_REDIS_PORT = 6379; + @Override protected Class getAnnotationType() { return EnableRedisServer.class; @@ -40,11 +44,9 @@ public class RedisServerConfiguration extends EmbeddedServiceConfigurationSuppor @Override protected Properties toGemFireProperties(Map annotationAttributes) { - Properties gemfireProperties = new Properties(); - - setProperty(gemfireProperties, "redis-bind-address", annotationAttributes.get("bindAddress")); - setProperty(gemfireProperties, "redis-port", annotationAttributes.get("port")); - - return gemfireProperties; + return new PropertiesBuilder() + .setProperty("redis-bind-address", annotationAttributes.get("bindAddress")) + .setProperty("redis-port", resolvePort((Integer)annotationAttributes.get("port"), DEFAULT_REDIS_PORT)) + .build(); } }