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 29a169a10c)

Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2015-08-10 19:20:10 -07:00
parent e37004facf
commit 0d7a2fe211
2 changed files with 13 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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";