SGF-56
+ add flag to disable bean-factory-locator
This commit is contained in:
@@ -62,17 +62,21 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
private Properties properties;
|
||||
private DistributedSystem system;
|
||||
private ClassLoader beanClassLoader;
|
||||
private GemfireBeanFactoryLocator factoryLocator = new GemfireBeanFactoryLocator();
|
||||
private GemfireBeanFactoryLocator factoryLocator;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private String beanName;
|
||||
private boolean useBeanFactoryLocator = true;
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// initialize locator
|
||||
factoryLocator.setBeanFactory(beanFactory);
|
||||
factoryLocator.setBeanName(beanName);
|
||||
factoryLocator.afterPropertiesSet();
|
||||
|
||||
if (useBeanFactoryLocator) {
|
||||
factoryLocator = new GemfireBeanFactoryLocator();
|
||||
factoryLocator.setBeanFactory(beanFactory);
|
||||
factoryLocator.setBeanName(beanName);
|
||||
factoryLocator.afterPropertiesSet();
|
||||
}
|
||||
Properties cfgProps = mergeProperties();
|
||||
system = DistributedSystem.connect(cfgProps);
|
||||
|
||||
@@ -128,7 +132,10 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
}
|
||||
system = null;
|
||||
|
||||
factoryLocator.destroy();
|
||||
if (factoryLocator != null) {
|
||||
factoryLocator.destroy();
|
||||
factoryLocator = null;
|
||||
}
|
||||
}
|
||||
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
@@ -187,4 +194,15 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
public void setCacheXml(Resource cacheXml) {
|
||||
this.cacheXml = cacheXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a bean factory locator is enabled (default) for this cache definition or not. The locator stores
|
||||
* the enclosing bean factory reference to allow auto-wiring of Spring beans into GemFire managed classes. Usually disabled
|
||||
* when the same cache is used in multiple application context/bean factories inside the same VM.
|
||||
*
|
||||
* @param usage true if the bean factory locator is used underneath or not
|
||||
*/
|
||||
public void setUseBeanFactoryLocator(boolean usage) {
|
||||
this.useBeanFactoryLocator = usage;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,8 @@ public class GemfireBeanFactoryLocator implements BeanFactoryLocator, BeanFactor
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("adding key=" + name + " w/ reference=" + beanFactory);
|
||||
|
||||
if (beanFactories.containsKey(name) || beanFactories.putIfAbsent(name, beanFactory) != null) {
|
||||
if (beanFactories.containsKey(name) && !beanFactory.equals(beanFactories.get(name))
|
||||
|| beanFactories.putIfAbsent(name, beanFactory) != null) {
|
||||
throw new IllegalArgumentException("a beanFactoryReference already exists for key " + factoryName);
|
||||
}
|
||||
}
|
||||
@@ -120,10 +121,11 @@ public class GemfireBeanFactoryLocator implements BeanFactoryLocator, BeanFactor
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
for (String name : names) {
|
||||
beanFactories.remove(name);
|
||||
if (names != null) {
|
||||
for (String name : names) {
|
||||
beanFactories.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (beanFactory == defaultFactory) {
|
||||
synchronized (GemfireBeanFactoryLocator.class) {
|
||||
defaultFactory = null;
|
||||
|
||||
Reference in New Issue
Block a user