DATAGEODE-218 - Polish.

Resolves gh-26.
This commit is contained in:
John Blum
2019-08-15 00:50:07 -07:00
parent d76a21b40e
commit 4550ecb594
3 changed files with 52 additions and 46 deletions

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.config.annotation; package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@@ -23,6 +22,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanReference; import org.springframework.beans.factory.config.BeanReference;
@@ -44,14 +44,22 @@ import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
* *
* @author Udo Kohlmeyer * @author Udo Kohlmeyer
* @author John Blum * @author John Blum
* @see java.lang.annotation.Annotation
* @see org.apache.geode.cache.wan.GatewayReceiver * @see org.apache.geode.cache.wan.GatewayReceiver
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
* @see org.springframework.beans.factory.support.BeanDefinitionRegistry
* @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration * @see org.springframework.context.annotation.Configuration
* @see EnableGatewayReceiver * @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar
* @see org.springframework.core.annotation.AnnotationAttributes
* @see org.springframework.core.type.AnnotationMetadata
* @see org.springframework.data.gemfire.config.annotation.EnableGatewayReceiver
* @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @since 2.2.0 * @since 2.2.0
*/ */
public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSupport public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSupport
implements ImportBeanDefinitionRegistrar { implements ImportBeanDefinitionRegistrar {
static final boolean DEFAULT_MANUAL_START = GatewayReceiver.DEFAULT_MANUAL_START; static final boolean DEFAULT_MANUAL_START = GatewayReceiver.DEFAULT_MANUAL_START;
@@ -108,7 +116,7 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
* @param registry * @param registry
*/ */
private void registerGatewayReceiverBeanDefinition(AnnotationAttributes enableGatewayReceiverAttributes, private void registerGatewayReceiverBeanDefinition(AnnotationAttributes enableGatewayReceiverAttributes,
BeanDefinitionRegistry registry) { BeanDefinitionRegistry registry) {
BeanDefinitionBuilder gatewayReceiverBeanBuilder = BeanDefinitionBuilder gatewayReceiverBeanBuilder =
BeanDefinitionBuilder.genericBeanDefinition(GatewayReceiverFactoryBean.class); BeanDefinitionBuilder.genericBeanDefinition(GatewayReceiverFactoryBean.class);
@@ -134,7 +142,7 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
* @param gatewayReceiverBeanName * @param gatewayReceiverBeanName
*/ */
private void configureBeanFromAnnotationAttributes(AnnotationAttributes enableGatewayReceiverAttributes, private void configureBeanFromAnnotationAttributes(AnnotationAttributes enableGatewayReceiverAttributes,
BeanDefinitionBuilder gatewayReceiverBeanBuilder, String gatewayReceiverBeanName) { BeanDefinitionBuilder gatewayReceiverBeanBuilder, String gatewayReceiverBeanName) {
gatewayReceiverBeanBuilder.addConstructorArgReference(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); gatewayReceiverBeanBuilder.addConstructorArgReference(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
@@ -180,25 +188,8 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
MutablePropertyValues beanPropertyValues = MutablePropertyValues beanPropertyValues =
gatewayReceiverBeanBuilder.getRawBeanDefinition().getPropertyValues(); gatewayReceiverBeanBuilder.getRawBeanDefinition().getPropertyValues();
gatewayReceiverBeanBuilder.addPropertyValue("gatewayReceiverConfigurers", resolveGatewayReceiverConfigurers()); gatewayReceiverBeanBuilder.addPropertyValue("gatewayReceiverConfigurers",
resolveGatewayReceiverConfigurers());
configureFromProperties(gatewayReceiverBeanBuilder, START_PORT_LITERAL, START_PORT_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(START_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, END_PORT_LITERAL, END_PORT_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(END_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MANUAL_START_LITERAL, MANUAL_START_PROPERTY_LITERAL,
Boolean.class, (Boolean) beanPropertyValues.getPropertyValue(MANUAL_START_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
MAXIMUM_TIME_BETWEEN_PINGS_LITERAL, MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL,
Integer.class,
(Integer) beanPropertyValues.getPropertyValue(MAXIMUM_TIME_BETWEEN_PINGS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
SOCKET_BUFFER_SIZE_LITERAL, SOCKET_BUFFER_SIZE_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(SOCKET_BUFFER_SIZE_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, BIND_ADDRESS_LITERAL, BIND_ADDRESS_PROPERTY_LITERAL, configureFromProperties(gatewayReceiverBeanBuilder, BIND_ADDRESS_LITERAL, BIND_ADDRESS_PROPERTY_LITERAL,
String.class, (String) beanPropertyValues.getPropertyValue(BIND_ADDRESS_LITERAL).getValue()); String.class, (String) beanPropertyValues.getPropertyValue(BIND_ADDRESS_LITERAL).getValue());
@@ -207,6 +198,23 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
HOSTNAME_FOR_SENDERS_LITERAL, HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL, HOSTNAME_FOR_SENDERS_LITERAL, HOSTNAME_FOR_SENDERS_PROPERTY_LITERAL,
String.class, (String) beanPropertyValues.getPropertyValue(HOSTNAME_FOR_SENDERS_LITERAL).getValue()); String.class, (String) beanPropertyValues.getPropertyValue(HOSTNAME_FOR_SENDERS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, MANUAL_START_LITERAL, MANUAL_START_PROPERTY_LITERAL,
Boolean.class, (Boolean) beanPropertyValues.getPropertyValue(MANUAL_START_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
MAXIMUM_TIME_BETWEEN_PINGS_LITERAL, MAXIMUM_TIME_BETWEEN_PINGS_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(MAXIMUM_TIME_BETWEEN_PINGS_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, START_PORT_LITERAL, START_PORT_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(START_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder, END_PORT_LITERAL, END_PORT_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(END_PORT_LITERAL).getValue());
configureFromProperties(gatewayReceiverBeanBuilder,
SOCKET_BUFFER_SIZE_LITERAL, SOCKET_BUFFER_SIZE_PROPERTY_LITERAL,
Integer.class, (Integer) beanPropertyValues.getPropertyValue(SOCKET_BUFFER_SIZE_LITERAL).getValue());
String[] filters = resolveProperty(gatewayReceiverProperty(TRANSPORT_FILTERS_PROPERTY_LITERAL), String[].class); String[] filters = resolveProperty(gatewayReceiverProperty(TRANSPORT_FILTERS_PROPERTY_LITERAL), String[].class);
Optional.ofNullable(filters).ifPresent(transportFilters -> { Optional.ofNullable(filters).ifPresent(transportFilters -> {
@@ -218,7 +226,7 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
} }
private <T> void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder, private <T> void configureFromProperties(BeanDefinitionBuilder gatewayReceiverBeanBuilder,
String beanPropertyName, String propertyName, Class<T> propertyType, T annotationAttributeValue) { String beanPropertyName, String propertyName, Class<T> propertyType, T annotationAttributeValue) {
T propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), propertyType, T propertyValue = resolveProperty(gatewayReceiverProperty(propertyName), propertyType,
annotationAttributeValue); annotationAttributeValue);
@@ -226,8 +234,16 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue); gatewayReceiverBeanBuilder.addPropertyValue(beanPropertyName, propertyValue);
} }
private List<GatewayReceiverConfigurer> resolveGatewayReceiverConfigurers() {
return Optional.ofNullable(this.gatewayReceiverConfigurers)
.filter(gatewayReceiverConfigurers -> !gatewayReceiverConfigurers.isEmpty())
.orElseGet(() ->
Collections.singletonList(LazyResolvingComposableGatewayReceiverConfigurer.create(getBeanFactory())));
}
private ManagedList<BeanReference> resolveGatewayTransportFilterBeanReferences( private ManagedList<BeanReference> resolveGatewayTransportFilterBeanReferences(
String[] gatewayTransportFilterBeanNames) { String[] gatewayTransportFilterBeanNames) {
ManagedList<BeanReference> gatewayTransportFilterBeanReferences = new ManagedList<>(); ManagedList<BeanReference> gatewayTransportFilterBeanReferences = new ManagedList<>();
@@ -240,7 +256,7 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
} }
private void registerGatewayTransportFilterDependencies(AnnotationAttributes annotationAttributes, private void registerGatewayTransportFilterDependencies(AnnotationAttributes annotationAttributes,
BeanDefinitionBuilder gatewayReceiverBeanBuilder) { BeanDefinitionBuilder gatewayReceiverBeanBuilder) {
String[] transportFilters = annotationAttributes.getStringArray(TRANSPORT_FILTERS_LITERAL); String[] transportFilters = annotationAttributes.getStringArray(TRANSPORT_FILTERS_LITERAL);
@@ -249,18 +265,10 @@ public class GatewayReceiverConfiguration extends AbstractAnnotationConfigSuppor
} }
private <T> BeanDefinitionBuilder setPropertyValueIfNotDefault(BeanDefinitionBuilder beanDefinitionBuilder, private <T> BeanDefinitionBuilder setPropertyValueIfNotDefault(BeanDefinitionBuilder beanDefinitionBuilder,
String propertyName, T value, T defaultValue) { String propertyName, T value, T defaultValue) {
return value != null return value != null
? beanDefinitionBuilder.addPropertyValue(propertyName, value) ? beanDefinitionBuilder.addPropertyValue(propertyName, value)
: beanDefinitionBuilder.addPropertyValue(propertyName, defaultValue); : beanDefinitionBuilder.addPropertyValue(propertyName, defaultValue);
} }
private List<GatewayReceiverConfigurer> resolveGatewayReceiverConfigurers() {
return Optional.ofNullable(this.gatewayReceiverConfigurers)
.filter(gatewayReceiverConfigurers -> !gatewayReceiverConfigurers.isEmpty())
.orElseGet(() ->
Collections.singletonList(LazyResolvingComposableGatewayReceiverConfigurer.create(getBeanFactory())));
}
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.config.annotation; package org.springframework.data.gemfire.config.annotation;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
@@ -25,14 +24,14 @@ import org.springframework.lang.Nullable;
* Composition of {@link GatewayReceiverConfigurer}. * Composition of {@link GatewayReceiverConfigurer}.
* *
* @author Udo Kohlmeyer * @author Udo Kohlmeyer
* @see GatewayReceiverFactoryBean * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer
* @see GatewayReceiverConfigurer * @see org.springframework.data.gemfire.config.annotation.support.AbstractLazyResolvingComposableConfigurer
* @see AbstractLazyResolvingComposableConfigurer * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @since 2.2.0 * @since 2.2.0
*/ */
public class LazyResolvingComposableGatewayReceiverConfigurer public class LazyResolvingComposableGatewayReceiverConfigurer
extends AbstractLazyResolvingComposableConfigurer<GatewayReceiverFactoryBean, GatewayReceiverConfigurer> extends AbstractLazyResolvingComposableConfigurer<GatewayReceiverFactoryBean, GatewayReceiverConfigurer>
implements GatewayReceiverConfigurer { implements GatewayReceiverConfigurer {
public static LazyResolvingComposableGatewayReceiverConfigurer create() { public static LazyResolvingComposableGatewayReceiverConfigurer create() {
return create(null); return create(null);

View File

@@ -15,18 +15,17 @@
*/ */
package org.springframework.data.gemfire.wan; package org.springframework.data.gemfire.wan;
import static java.util.stream.StreamSupport.stream;
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.StreamSupport;
import org.apache.geode.cache.Cache; import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewayReceiverFactory; import org.apache.geode.cache.wan.GatewayReceiverFactory;
import org.apache.geode.cache.wan.GatewayTransportFilter; import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer; import org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer;
@@ -85,7 +84,7 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
GatewayReceiverFactory gatewayReceiverFactory = this.cache.createGatewayReceiverFactory(); GatewayReceiverFactory gatewayReceiverFactory = this.cache.createGatewayReceiverFactory();
stream(nullSafeIterable(this.gatewayReceiverConfigurers).spliterator(), false) StreamSupport.stream(CollectionUtils.nullSafeIterable(this.gatewayReceiverConfigurers).spliterator(), false)
.forEach(it -> it.configure(getName(), this)); .forEach(it -> it.configure(getName(), this));
Optional.ofNullable(this.bindAddress) Optional.ofNullable(this.bindAddress)