DATAGEODE-136 - Replace all BeanPostProcessors setting GemFire/Geode Properties using SDG service enabling annotations with Configurers.

This commit is contained in:
John Blum
2018-07-30 21:01:57 -07:00
parent 29b47ccd0b
commit 390b9031d1
14 changed files with 91 additions and 58 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Properties;
@@ -61,11 +62,10 @@ public class AuthConfiguration extends EmbeddedServiceConfigurationSupport {
* @see org.springframework.data.gemfire.config.annotation.EnableAuth
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableAuth.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -47,7 +47,6 @@ import org.springframework.util.StringUtils;
* @see org.springframework.core.env.Environment
* @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator
* @see org.springframework.data.gemfire.config.annotation.support.AutoConfiguredAuthenticationInitializer
* @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport
* @see org.springframework.data.gemfire.util.PropertiesBuilder
* @since 2.0.0
*/

View File

@@ -88,9 +88,6 @@ public class GemFirePropertiesConfiguration extends EmbeddedServiceConfiguration
return EnableGemFireProperties.class;
}
/**
* {@inheritDoc}
*/
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -81,7 +81,6 @@ public class GeodeIntegratedSecurityConfiguration extends EmbeddedServiceConfigu
return !isShiroSecurityConfigured();
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -51,11 +52,10 @@ public class HttpServiceConfiguration extends EmbeddedServiceConfigurationSuppor
* @see org.springframework.data.gemfire.config.annotation.EnableHttpService
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableHttpService.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -52,11 +53,10 @@ public class LocatorConfiguration extends EmbeddedServiceConfigurationSupport {
* @see org.springframework.data.gemfire.config.annotation.EnableLocator
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableLocator.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Properties;
@@ -49,11 +50,10 @@ public class LoggingConfiguration extends EmbeddedServiceConfigurationSupport {
* @see org.springframework.data.gemfire.config.annotation.EnableLogging
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableLogging.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -17,7 +17,9 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
@@ -46,46 +48,52 @@ public class ManagerConfiguration extends EmbeddedServiceConfigurationSupport {
* @see org.springframework.data.gemfire.config.annotation.EnableManager
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableManager.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {
PropertiesBuilder gemfireProperties = PropertiesBuilder.create();
return Optional.of(resolveProperty(managerProperty("enabled"), Boolean.TRUE))
.filter(Boolean.TRUE::equals)
.map(enabled -> {
gemfireProperties.setProperty("jmx-manager",
resolveProperty(managerProperty("enabled"), Boolean.TRUE));
PropertiesBuilder gemfireProperties = PropertiesBuilder.create();
gemfireProperties.setProperty("jmx-manager-access-file",
resolveProperty(managerProperty("access-file"),
(String) annotationAttributes.get("accessFile")));
gemfireProperties.setProperty("jmx-manager",
resolveProperty(managerProperty("enabled"), Boolean.TRUE));
gemfireProperties.setProperty("jmx-manager-bind-address",
resolveProperty(managerProperty("bind-address"),
(String) annotationAttributes.get("bindAddress")));
gemfireProperties.setProperty("jmx-manager-access-file",
resolveProperty(managerProperty("access-file"),
(String) annotationAttributes.get("accessFile")));
gemfireProperties.setProperty("jmx-manager-hostname-for-clients",
resolveProperty(managerProperty("hostname-for-clients"),
(String) annotationAttributes.get("hostnameForClients")));
gemfireProperties.setProperty("jmx-manager-bind-address",
resolveProperty(managerProperty("bind-address"),
(String) annotationAttributes.get("bindAddress")));
gemfireProperties.setProperty("jmx-manager-password-file",
resolveProperty(managerProperty("password-file"),
(String) annotationAttributes.get("passwordFile")));
gemfireProperties.setProperty("jmx-manager-hostname-for-clients",
resolveProperty(managerProperty("hostname-for-clients"),
(String) annotationAttributes.get("hostnameForClients")));
gemfireProperties.setProperty("jmx-manager-port",
resolvePort(resolveProperty(managerProperty("port"),
(Integer) annotationAttributes.get("port")), DEFAULT_JMX_MANAGER_PORT));
gemfireProperties.setProperty("jmx-manager-password-file",
resolveProperty(managerProperty("password-file"),
(String) annotationAttributes.get("passwordFile")));
gemfireProperties.setProperty("jmx-manager-start",
resolveProperty(managerProperty("start"), (Boolean) annotationAttributes.get("start")));
gemfireProperties.setProperty("jmx-manager-port",
resolvePort(resolveProperty(managerProperty("port"),
(Integer) annotationAttributes.get("port")), DEFAULT_JMX_MANAGER_PORT));
gemfireProperties.setProperty("jmx-manager-update-rate",
resolveProperty(managerProperty("update-rate"),
(Integer) annotationAttributes.get("updateRate")));
gemfireProperties.setProperty("jmx-manager-start",
resolveProperty(managerProperty("start"), (Boolean) annotationAttributes.get("start")));
return gemfireProperties.build();
gemfireProperties.setProperty("jmx-manager-update-rate",
resolveProperty(managerProperty("update-rate"),
(Integer) annotationAttributes.get("updateRate")));
return gemfireProperties.build();
})
.orElseGet(Properties::new);
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Properties;
@@ -50,11 +51,10 @@ public class McastConfiguration extends EmbeddedServiceConfigurationSupport {
* @see org.springframework.data.gemfire.config.annotation.EnableMcast
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableMcast.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -47,11 +48,10 @@ public class MemcachedServerConfiguration extends EmbeddedServiceConfigurationSu
* @see org.springframework.data.gemfire.config.annotation.EnableMemcachedServer
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableMemcachedServer.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -72,7 +72,6 @@ public class OffHeapConfiguration extends EmbeddedServiceConfigurationSupport {
return EnableOffHeap.class;
}
/* (non-Javadoc) */
@Override
protected void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
Map<String, Object> annotationAttributes, BeanDefinitionRegistry registry) {
@@ -87,7 +86,6 @@ public class OffHeapConfiguration extends EmbeddedServiceConfigurationSupport {
builder.getBeanDefinition());
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {
@@ -98,7 +96,6 @@ public class OffHeapConfiguration extends EmbeddedServiceConfigurationSupport {
.build();
}
/* (non-Javadoc) */
@SuppressWarnings("unused")
protected static class OffHeapBeanFactoryPostProcessor extends AbstractAnnotationConfigSupport
implements BeanFactoryPostProcessor {

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -47,11 +48,10 @@ public class RedisServerConfiguration extends EmbeddedServiceConfigurationSuppor
* @see org.springframework.data.gemfire.config.annotation.EnableRedisServer
*/
@Override
protected Class getAnnotationType() {
protected Class<? extends Annotation> getAnnotationType() {
return EnableRedisServer.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {

View File

@@ -55,7 +55,6 @@ public class SslConfiguration extends EmbeddedServiceConfigurationSupport {
return EnableSsl.class;
}
/* (non-Javadoc) */
@Override
protected Properties toGemFireProperties(Map<String, Object> annotationAttributesMap) {

View File

@@ -35,7 +35,11 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration;
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer;
import org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -64,8 +68,8 @@ public abstract class EmbeddedServiceConfigurationSupport extends AbstractAnnota
public static final Integer DEFAULT_PORT = 0;
public static final String DEFAULT_HOST = "localhost";
@Autowired
@SuppressWarnings("all")
@Autowired(required = false)
private AbstractCacheConfiguration cacheConfiguration;
/**
@@ -83,9 +87,6 @@ public abstract class EmbeddedServiceConfigurationSupport extends AbstractAnnota
.orElseThrow(() -> newIllegalStateException("AbstractCacheConfiguration is required"));
}
/**
* {@inheritDoc}
*/
@Override
public final void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
@@ -112,17 +113,14 @@ public abstract class EmbeddedServiceConfigurationSupport extends AbstractAnnota
getCacheConfiguration().add(gemfireProperties);
}
catch (Exception ignore) {
registerGemFirePropertiesBeanPostProcessor(registry, gemfireProperties);
//registerGemFirePropertiesBeanPostProcessor(registry, gemfireProperties);
registerGemFirePropertiesConfigurer(registry, gemfireProperties);
}
}
}
protected abstract Properties toGemFireProperties(Map<String, Object> annotationAttributes);
protected boolean isAnnotationPresent(AnnotationMetadata importingClassMetadata) {
return importingClassMetadata.hasAnnotation(getAnnotationTypeName());
}
protected boolean hasProperties(Properties properties) {
return !CollectionUtils.isEmpty(properties);
}
@@ -138,6 +136,16 @@ public abstract class EmbeddedServiceConfigurationSupport extends AbstractAnnota
BeanDefinitionReaderUtils.registerBeanDefinition(newBeanDefinitionHolder(builder), registry);
}
protected void registerGemFirePropertiesConfigurer(BeanDefinitionRegistry registry, Properties gemfireProperties) {
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.genericBeanDefinition(GemFirePropertiesConfigurer.class);
builder.addConstructorArgValue(gemfireProperties);
BeanDefinitionReaderUtils.registerBeanDefinition(newBeanDefinitionHolder(builder), registry);
}
protected BeanDefinitionHolder newBeanDefinitionHolder(BeanDefinitionBuilder builder) {
return new BeanDefinitionHolder(builder.getBeanDefinition(), generateBeanName());
}
@@ -205,6 +213,32 @@ public abstract class EmbeddedServiceConfigurationSupport extends AbstractAnnota
return Optional.ofNullable(port).orElse(defaultPort);
}
protected static class GemFirePropertiesConfigurer implements PeerCacheConfigurer, ClientCacheConfigurer {
private final Properties gemfireProperties;
public GemFirePropertiesConfigurer(Properties gemfireProperties) {
Assert.notEmpty(gemfireProperties, "GemFire Properties are required");
this.gemfireProperties = gemfireProperties;
}
@Override
public void configure(String beanName, CacheFactoryBean bean) {
configureGemFireProperties(bean);
}
@Override
public void configure(String beanName, ClientCacheFactoryBean bean) {
configureGemFireProperties(bean);
}
private void configureGemFireProperties(CacheFactoryBean bean) {
bean.getProperties().putAll(this.gemfireProperties);
}
}
/**
* Spring {@link BeanPostProcessor} used to process before initialization Pivotal GemFire or Apache Geode
* {@link Properties} defined as a bean in the Spring application context.