From 0d7a2fe211fec710f4d5c52e86335e2b68cedaa5 Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 10 Aug 2015 19:20:10 -0700 Subject: [PATCH] SGF-425 - Allow early initialization and re-initialization of LazyWiringDeclarableSupport instances. Deprecated org.springframework.data.gemfire.WiringDeclarableSupport in favor of LazyWiringDeclarableSupport and modified LazyWiringDeclarableSupport to 'release' the BeanFactory reference. (cherry picked from commit 29a169a10cd78d451f4d84227e8058be68d0d6be) Signed-off-by: John Blum --- .../data/gemfire/LazyWiringDeclarableSupport.java | 12 ++++++++++-- .../data/gemfire/WiringDeclarableSupport.java | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java b/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java index 9040c296..77271e7f 100644 --- a/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java +++ b/src/main/java/org/springframework/data/gemfire/LazyWiringDeclarableSupport.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.access.BeanFactoryReference; import org.springframework.beans.factory.wiring.BeanConfigurerSupport; import org.springframework.beans.factory.wiring.BeanWiringInfo; import org.springframework.beans.factory.wiring.BeanWiringInfoResolver; @@ -67,6 +68,8 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener // condition determining the initialization state of this Declarable volatile boolean initialized = false; + private BeanFactoryReference beanFactoryReference = null; + private String factoryKey = null; /** @@ -137,7 +140,7 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener protected void assertUninitialized() { Assert.state(!isInitialized(), String.format( "This Declarable object (%1$s) has already been configured and initialized", - getClass().getName())); + getClass().getName())); } /** @@ -261,7 +264,11 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener * @see org.springframework.beans.factory.BeanFactory */ protected BeanFactory locateBeanFactory(String factoryKey) { - return new GemfireBeanFactoryLocator().useBeanFactory(factoryKey).getFactory(); + if (beanFactoryReference == null) { + beanFactoryReference = new GemfireBeanFactoryLocator().useBeanFactory(factoryKey); + } + + return beanFactoryReference.getFactory(); } /** @@ -310,6 +317,7 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener @Override public void destroy() throws Exception { SpringContextBootstrappingInitializer.unregister(this); + beanFactoryReference.release(); parametersReference.set(null); initialized = false; } diff --git a/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java b/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java index 17f0f6b0..baf18c42 100644 --- a/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java +++ b/src/main/java/org/springframework/data/gemfire/WiringDeclarableSupport.java @@ -38,8 +38,11 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils; * @see org.springframework.beans.factory.wiring.BeanConfigurerSupport * @see org.springframework.beans.factory.wiring.BeanWiringInfo * @see org.springframework.data.gemfire.DeclarableSupport + * @see org.springframework.data.gemfire.LazyWiringDeclarableSupport * @see com.gemstone.gemfire.cache.Declarable + * @deprecated please use LazyWiringDeclarableSupport instead. */ +@Deprecated public class WiringDeclarableSupport extends DeclarableSupport { private static final String BEAN_NAME_PROPERTY = "bean-name";