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:
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
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.BeanConfigurerSupport;
|
||||||
import org.springframework.beans.factory.wiring.BeanWiringInfo;
|
import org.springframework.beans.factory.wiring.BeanWiringInfo;
|
||||||
import org.springframework.beans.factory.wiring.BeanWiringInfoResolver;
|
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
|
// condition determining the initialization state of this Declarable
|
||||||
volatile boolean initialized = false;
|
volatile boolean initialized = false;
|
||||||
|
|
||||||
|
private BeanFactoryReference beanFactoryReference = null;
|
||||||
|
|
||||||
private String factoryKey = null;
|
private String factoryKey = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +140,7 @@ public abstract class LazyWiringDeclarableSupport implements ApplicationListener
|
|||||||
protected void assertUninitialized() {
|
protected void assertUninitialized() {
|
||||||
Assert.state(!isInitialized(), String.format(
|
Assert.state(!isInitialized(), String.format(
|
||||||
"This Declarable object (%1$s) has already been configured and initialized",
|
"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
|
* @see org.springframework.beans.factory.BeanFactory
|
||||||
*/
|
*/
|
||||||
protected BeanFactory locateBeanFactory(String factoryKey) {
|
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
|
@Override
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
SpringContextBootstrappingInitializer.unregister(this);
|
SpringContextBootstrappingInitializer.unregister(this);
|
||||||
|
beanFactoryReference.release();
|
||||||
parametersReference.set(null);
|
parametersReference.set(null);
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.BeanConfigurerSupport
|
||||||
* @see org.springframework.beans.factory.wiring.BeanWiringInfo
|
* @see org.springframework.beans.factory.wiring.BeanWiringInfo
|
||||||
* @see org.springframework.data.gemfire.DeclarableSupport
|
* @see org.springframework.data.gemfire.DeclarableSupport
|
||||||
|
* @see org.springframework.data.gemfire.LazyWiringDeclarableSupport
|
||||||
* @see com.gemstone.gemfire.cache.Declarable
|
* @see com.gemstone.gemfire.cache.Declarable
|
||||||
|
* @deprecated please use LazyWiringDeclarableSupport instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class WiringDeclarableSupport extends DeclarableSupport {
|
public class WiringDeclarableSupport extends DeclarableSupport {
|
||||||
|
|
||||||
private static final String BEAN_NAME_PROPERTY = "bean-name";
|
private static final String BEAN_NAME_PROPERTY = "bean-name";
|
||||||
|
|||||||
Reference in New Issue
Block a user