DATAGEODE-198 - Adapt LocatorApplication configuration and Configurer to implement the Configurer interface/contract and employ the lazy-resolving, composable Configurer implementation.

This commit is contained in:
John Blum
2019-05-28 16:16:25 -07:00
parent 1370ff1089
commit 9d69a14d64
3 changed files with 54 additions and 29 deletions

View File

@@ -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<LocatorFactoryBean, LocatorConfigurer>
implements LocatorConfigurer {
public static LazyResolvingComposableLocatorConfigurer create() {
return create(null);
}
public static LazyResolvingComposableLocatorConfigurer create(@Nullable BeanFactory beanFactory) {
return new LazyResolvingComposableLocatorConfigurer().with(beanFactory);
}
@Override
protected Class<LocatorConfigurer> getConfigurerType() {
return LocatorConfigurer.class;
}
}

View File

@@ -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<String, LocatorConfigurer> 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) {

View File

@@ -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<LocatorFactoryBean> {
}