diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/LazyResolvingComposableLocatorConfigurer.java b/src/main/java/org/springframework/data/gemfire/config/annotation/LazyResolvingComposableLocatorConfigurer.java new file mode 100644 index 00000000..d1860e1f --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/LazyResolvingComposableLocatorConfigurer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.annotation; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.data.gemfire.LocatorFactoryBean; +import org.springframework.data.gemfire.config.annotation.support.AbstractLazyResolvingComposableConfigurer; +import org.springframework.lang.Nullable; + +/** + * Composition for {@link LocatorConfigurer}. + * + * @author John Blum + * @see org.springframework.data.gemfire.LocatorFactoryBean + * @see org.springframework.data.gemfire.config.annotation.LocatorConfigurer + * @see org.springframework.data.gemfire.config.annotation.support.AbstractLazyResolvingComposableConfigurer + * @since 2.2.0 + */ +public class LazyResolvingComposableLocatorConfigurer + extends AbstractLazyResolvingComposableConfigurer + implements LocatorConfigurer { + + public static LazyResolvingComposableLocatorConfigurer create() { + return create(null); + } + + public static LazyResolvingComposableLocatorConfigurer create(@Nullable BeanFactory beanFactory) { + return new LazyResolvingComposableLocatorConfigurer().with(beanFactory); + } + + @Override + protected Class getConfigurerType() { + return LocatorConfigurer.class; + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfiguration.java index 7f264a43..8c9e6604 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfiguration.java @@ -16,20 +16,17 @@ package org.springframework.data.gemfire.config.annotation; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; -import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeMap; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import org.apache.geode.cache.GemFireCache; import org.apache.geode.distributed.Locator; + import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.context.annotation.Bean; @@ -181,20 +178,7 @@ public class LocatorApplicationConfiguration extends AbstractAnnotationConfigSup return Optional.ofNullable(this.locatorConfigurers) .filter(locatorConfigurers -> !locatorConfigurers.isEmpty()) .orElseGet(() -> - - Optional.of(getBeanFactory()) - .filter(beanFactory -> beanFactory instanceof ListableBeanFactory) - .map(beanFactory -> { - - Map beansOfType = ((ListableBeanFactory) beanFactory) - .getBeansOfType(LocatorConfigurer.class, true, false); - - return nullSafeMap(beansOfType).values().stream() - .collect(Collectors.toList()); - - }) - .orElseGet(Collections::emptyList) - ); + Collections.singletonList(LazyResolvingComposableLocatorConfigurer.create(getBeanFactory()))); } public void setBindAddress(String bindAddress) { diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorConfigurer.java b/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorConfigurer.java index cdd46a28..e4455159 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorConfigurer.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorConfigurer.java @@ -16,7 +16,9 @@ package org.springframework.data.gemfire.config.annotation; import org.apache.geode.distributed.Locator; + import org.springframework.data.gemfire.LocatorFactoryBean; +import org.springframework.data.gemfire.config.annotation.support.Configurer; /** * A Spring Configurer used to apply additional, customized configuration for an Apache Geode or Pivotal GemFire @@ -32,19 +34,10 @@ import org.springframework.data.gemfire.LocatorFactoryBean; * @see java.lang.FunctionalInterface * @see org.apache.geode.distributed.Locator * @see org.springframework.data.gemfire.LocatorFactoryBean + * @see org.springframework.data.gemfire.config.annotation.support.Configurer * @since 2.2.0 */ @FunctionalInterface -public interface LocatorConfigurer { - - /** - * Customizes the configuration of the {@link LocatorFactoryBean}. - * - * @param beanName {@link String name} of the bean in the Spring context. - * @param bean {@link LocatorFactoryBean} used to configure and bootstrap an Apache Geode or Pivotal GemFire - * {@link Locator} using Spring. - * @see org.springframework.data.gemfire.LocatorFactoryBean - */ - void configure(String beanName, LocatorFactoryBean bean); +public interface LocatorConfigurer extends Configurer { }