From 0094fd6ea4465a7737303d8bdfb11210b02ec8ea Mon Sep 17 00:00:00 2001 From: John Blum Date: Fri, 20 Sep 2019 13:23:43 -0700 Subject: [PATCH] Add Environment/System property to control ClusterAwareCondition matching. Provide static method ClusterAwareConfiguration.ClusterAwareCondition.isAvailable() to assess whether the cluster was available in application components and act accordingly. Resolves gh-52. --- .../annotation/ClusterAwareConfiguration.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spring-geode/src/main/java/org/springframework/geode/config/annotation/ClusterAwareConfiguration.java b/spring-geode/src/main/java/org/springframework/geode/config/annotation/ClusterAwareConfiguration.java index 81b08dd7..d7a4f578 100644 --- a/spring-geode/src/main/java/org/springframework/geode/config/annotation/ClusterAwareConfiguration.java +++ b/spring-geode/src/main/java/org/springframework/geode/config/annotation/ClusterAwareConfiguration.java @@ -62,6 +62,7 @@ import org.springframework.util.StringUtils; * @see java.lang.annotation.Annotation * @see java.net.Socket * @see java.net.SocketAddress + * @see org.apache.geode.cache.client.ClientRegionShortcut * @see org.apache.geode.cache.server.CacheServer * @see org.springframework.context.ApplicationListener * @see org.springframework.context.ConfigurableApplicationContext @@ -73,6 +74,7 @@ import org.springframework.util.StringUtils; * @see org.springframework.core.env.ConfigurableEnvironment * @see org.springframework.core.env.Environment * @see org.springframework.core.env.PropertySource + * @see org.springframework.core.type.AnnotatedTypeMetadata * @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport * @since 1.2.0 */ @@ -90,6 +92,10 @@ public class ClusterAwareConfiguration extends AbstractAnnotationConfigSupport { static final String LOCALHOST = "localhost"; static final String MATCHING_PROPERTY_PATTERN = "spring\\.data\\.gemfire\\.pool\\..*locators|servers"; + + static final String SPRING_BOOT_DATA_GEMFIRE_CLUSTER_CONDITION_MATCH_PROPERTY = + "spring.boot.data.gemfire.cluster.condition.match"; + static final String SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY = "spring.data.gemfire.cache.client.region.shortcut"; @@ -107,6 +113,10 @@ public class ClusterAwareConfiguration extends AbstractAnnotationConfigSupport { return contextClosedEvent-> reset(); } + public static boolean isAvailable() { + return Boolean.TRUE.equals(clusterAvailable.get()); + } + public static void reset() { clusterAvailable.set(null); } @@ -119,7 +129,7 @@ public class ClusterAwareConfiguration extends AbstractAnnotationConfigSupport { doMatch(context); } - return Boolean.TRUE.equals(clusterAvailable.get()); + return isMatch(context); } ConditionContext registerApplicationListener(ConditionContext conditionContext) { @@ -134,6 +144,15 @@ public class ClusterAwareConfiguration extends AbstractAnnotationConfigSupport { return conditionContext; } + boolean isMatch(ConditionContext context) { + + Environment environment = context.getEnvironment(); + + return isAvailable() + || environment.getProperty(SPRING_BOOT_DATA_GEMFIRE_CLUSTER_CONDITION_MATCH_PROPERTY, + Boolean.class, false); + } + ConditionContext doMatch(ConditionContext conditionContext) { Environment environment = conditionContext.getEnvironment();