+ try to break up cycle between pools and client caches
This commit is contained in:
Costin Leau
2011-08-24 22:12:42 +03:00
parent 1c1f40d2df
commit 01a4d29fa4
3 changed files with 20 additions and 29 deletions

View File

@@ -20,14 +20,13 @@ import java.net.InetSocketAddress;
import java.util.List;
import java.util.Properties;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolManager;
import com.gemstone.gemfire.pdx.PdxSerializer;
/**
@@ -85,18 +84,9 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
private void initializePool(ClientCacheFactory ccf) {
Pool p = pool;
if (p == null && StringUtils.hasText(poolName)) {
BeanFactory beanFactory = getBeanFactory();
// try to eagerly initialize the pool name, if defined as a bean
if (beanFactory.isTypeMatch(poolName, Pool.class)) {
if (log.isDebugEnabled()) {
log.debug("Found bean definition for pool '" + poolName + "'. Eagerly initializing it...");
}
p = beanFactory.getBean(poolName, Pool.class);
}
}
p = PoolManager.find(poolName);
System.out.println("*** Pool found " + p);
if (p != null) {
// copy the pool settings - this way if the pool is not found, at least the cache will have a similar config
ccf.setPoolFreeConnectionTimeout(p.getFreeConnectionTimeout());

View File

@@ -23,16 +23,17 @@ 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.BeanFactoryUtils;
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.beans.factory.config.ConfigurableListableBeanFactory;
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.GemFireCache;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolFactory;
import com.gemstone.gemfire.cache.client.PoolManager;
@@ -106,18 +107,18 @@ 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);
if (beanFactory instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory lbf = (ConfigurableListableBeanFactory) beanFactory;
String[] caches = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(lbf, GemFireCache.class, false,
false);
for (String bn : caches) {
if (!lbf.isCurrentlyInCreation(bn)) {
beanFactory.getBean(bn);
}
}
}
}
// first check the configured pools