SGF-35
+ possible fix breaking Pool/ClientCacheFactory cycle + initialization
This commit is contained in:
@@ -28,6 +28,7 @@ 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.core.Ordered;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
@@ -58,7 +59,7 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, DisposableBean,
|
||||
InitializingBean, FactoryBean<GemFireCache>, PersistenceExceptionTranslator {
|
||||
InitializingBean, FactoryBean<GemFireCache>, PersistenceExceptionTranslator, Ordered {
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on the GemFire 6.6 API.
|
||||
@@ -158,6 +159,7 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
th.setContextClassLoader(oldTCCL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PDX properties for the given object. Note this is implementation specific as it depends on the type
|
||||
* of the factory passed in.
|
||||
@@ -182,7 +184,7 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
return ((CacheFactory) factory).create();
|
||||
}
|
||||
|
||||
private Properties mergeProperties() {
|
||||
protected Properties mergeProperties() {
|
||||
Properties cfgProps = (properties != null ? (Properties) properties.clone() : new Properties());
|
||||
return cfgProps;
|
||||
}
|
||||
@@ -320,4 +322,8 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
protected BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,13 @@ import java.util.Properties;
|
||||
|
||||
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.distributed.DistributedSystem;
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
/**
|
||||
@@ -84,9 +86,25 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
|
||||
private void initializePool(ClientCacheFactory ccf) {
|
||||
Pool p = pool;
|
||||
|
||||
p = PoolManager.find(poolName);
|
||||
if (p == null && StringUtils.hasText(poolName)) {
|
||||
p = PoolManager.find(poolName);
|
||||
|
||||
// initialize a client-like Distributed System before initializing the pool
|
||||
if (p == null) {
|
||||
Properties prop = mergeProperties();
|
||||
prop.setProperty("mcast-port", "0");
|
||||
prop.setProperty("locators", "");
|
||||
|
||||
DistributedSystem system = DistributedSystem.connect(prop);
|
||||
}
|
||||
|
||||
// trigger pool initialization
|
||||
Assert.isTrue(getBeanFactory().isTypeMatch(poolName, Pool.class), "No bean named " + poolName + " of type "
|
||||
+ Pool.class.getName() + " found");
|
||||
|
||||
p = getBeanFactory().getBean(poolName, Pool.class);
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
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;
|
||||
@@ -105,10 +104,6 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
name = beanName;
|
||||
}
|
||||
|
||||
if (beanFactory != null) {
|
||||
beanFactory.getBean(GemFireCache.class);
|
||||
}
|
||||
|
||||
// first check the configured pools
|
||||
Pool existingPool = PoolManager.find(name);
|
||||
if (existingPool != null) {
|
||||
|
||||
Reference in New Issue
Block a user