SGF-36
+ pool factories force the initialization of the cache during init
This commit is contained in:
@@ -20,14 +20,19 @@ import java.util.Collection;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
import com.gemstone.gemfire.cache.client.PoolManager;
|
||||
@@ -45,7 +50,8 @@ import com.gemstone.gemfire.cache.client.PoolManager;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, DisposableBean, BeanNameAware {
|
||||
public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, DisposableBean, BeanNameAware,
|
||||
BeanClassLoaderAware, BeanFactoryAware {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PoolFactoryBean.class);
|
||||
|
||||
@@ -59,6 +65,10 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
private String name;
|
||||
private Collection<PoolConnection> locators;
|
||||
private Collection<PoolConnection> servers;
|
||||
|
||||
private ClassLoader classLoader = getClass().getClassLoader();
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private boolean keepAlive = false;
|
||||
|
||||
private int freeConnectionTimeout = PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT;
|
||||
@@ -96,6 +106,20 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
name = beanName;
|
||||
}
|
||||
|
||||
// trigger the initialization of the cache
|
||||
Class<?> cacheClass = null;
|
||||
try {
|
||||
// attempt to use the 6.5 interfaces
|
||||
cacheClass = ClassUtils.resolveClassName("com.gemstone.gemfire.cache.GemFireCache", classLoader);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// still on 6.0
|
||||
cacheClass = Cache.class;
|
||||
}
|
||||
|
||||
if (beanFactory != null) {
|
||||
beanFactory.getBean(cacheClass);
|
||||
}
|
||||
|
||||
// first check the configured pools
|
||||
Pool existingPool = PoolManager.find(name);
|
||||
if (existingPool != null) {
|
||||
@@ -310,4 +334,12 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
public void setThreadLocalConnections(boolean threadLocalConnections) {
|
||||
this.threadLocalConnections = threadLocalConnections;
|
||||
}
|
||||
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,13 @@
|
||||
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
|
||||
<!-- as there can be only one cache per VM -->
|
||||
|
||||
<gfe:cache />
|
||||
|
||||
<gfe:pool>
|
||||
<gfe:locator host="localhost" port="${gfe.port}"/>
|
||||
</gfe:pool>
|
||||
|
||||
<gfe:cache />
|
||||
|
||||
<gfe:pool id="complex" free-connection-timeout="6000" retry-attempts="30" ping-interval="5000" subscription-enabled="true">
|
||||
<gfe:server host="localhost" port="${gfe.port.4}"/>
|
||||
<gfe:server host="localhost" port="40405"/>
|
||||
|
||||
Reference in New Issue
Block a user