+ retrofitted client cache onto the master
+ the pool/client cache loop still exists
This commit is contained in:
@@ -38,6 +38,7 @@ import com.gemstone.gemfire.GemFireException;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
|
||||
import com.gemstone.gemfire.distributed.DistributedMember;
|
||||
import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
import com.gemstone.gemfire.pdx.PdxSerializable;
|
||||
@@ -61,19 +62,33 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
|
||||
private class PdxOptions implements Runnable {
|
||||
|
||||
private CacheFactory factory;
|
||||
private Object factory;
|
||||
|
||||
PdxOptions(CacheFactory factory) {
|
||||
PdxOptions(Object factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Assert.isAssignable(PdxSerializer.class, pdxSerializer.getClass(), "Invalid pdx serializer used");
|
||||
factory.setPdxSerializer((PdxSerializer) pdxSerializer);
|
||||
factory.setPdxDiskStore(pdxDiskStoreName);
|
||||
factory.setPdxIgnoreUnreadFields(pdxIgnoreUnreadFields);
|
||||
factory.setPdxPersistent(pdxPersistent);
|
||||
factory.setPdxReadSerialized(pdxReadSerialized);
|
||||
|
||||
// ugly duplication to go around the different factory hierarchy
|
||||
if (factory instanceof CacheFactory) {
|
||||
CacheFactory cf = (CacheFactory) factory;
|
||||
|
||||
cf.setPdxSerializer((PdxSerializer) pdxSerializer);
|
||||
cf.setPdxDiskStore(pdxDiskStoreName);
|
||||
cf.setPdxIgnoreUnreadFields(pdxIgnoreUnreadFields);
|
||||
cf.setPdxPersistent(pdxPersistent);
|
||||
cf.setPdxReadSerialized(pdxReadSerialized);
|
||||
}
|
||||
if (factory instanceof ClientCacheFactory) {
|
||||
ClientCacheFactory cf = (ClientCacheFactory) factory;
|
||||
cf.setPdxSerializer((PdxSerializer) pdxSerializer);
|
||||
cf.setPdxDiskStore(pdxDiskStoreName);
|
||||
cf.setPdxIgnoreUnreadFields(pdxIgnoreUnreadFields);
|
||||
cf.setPdxPersistent(pdxPersistent);
|
||||
cf.setPdxReadSerialized(pdxReadSerialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +119,6 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
factoryLocator.afterPropertiesSet();
|
||||
}
|
||||
Properties cfgProps = mergeProperties();
|
||||
CacheFactory factory = new CacheFactory(cfgProps);
|
||||
|
||||
// use the bean class loader to load Declarable classes
|
||||
Thread th = Thread.currentThread();
|
||||
@@ -115,9 +129,11 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
// first look for open caches
|
||||
String msg = null;
|
||||
try {
|
||||
cache = CacheFactory.getAnyInstance();
|
||||
cache = fetchCache();
|
||||
msg = "Retrieved existing";
|
||||
} catch (CacheClosedException ex) {
|
||||
Object factory = createFactory(cfgProps);
|
||||
|
||||
// GemFire 6.6 specific options
|
||||
if (pdxSerializer != null || pdxPersistent != null || pdxReadSerialized != null
|
||||
|| pdxIgnoreUnreadFields != null || pdxDiskStoreName != null) {
|
||||
@@ -127,7 +143,7 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
}
|
||||
|
||||
// fall back to cache creation
|
||||
cache = factory.create();
|
||||
cache = createCache(factory);
|
||||
msg = "Created";
|
||||
}
|
||||
|
||||
@@ -151,6 +167,18 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
}
|
||||
}
|
||||
|
||||
protected Object createFactory(Properties props) {
|
||||
return new CacheFactory(props);
|
||||
}
|
||||
|
||||
protected Cache fetchCache() {
|
||||
return CacheFactory.getAnyInstance();
|
||||
}
|
||||
|
||||
protected Cache createCache(Object factory) {
|
||||
return ((CacheFactory) factory).create();
|
||||
}
|
||||
|
||||
private Properties mergeProperties() {
|
||||
Properties cfgProps = (properties != null ? (Properties) properties.clone() : new Properties());
|
||||
return cfgProps;
|
||||
|
||||
@@ -16,55 +16,52 @@
|
||||
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
|
||||
/**
|
||||
* FactoryBean dedicated to creating client caches (caches for client JVMs).
|
||||
* Intended mainly for usage with GemFire 6.5 (while preserving 6.0 compatibility).
|
||||
* Acts an utility class (as client caches are a subset with a particular configuration of the generic cache).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class ClientCacheFactoryBean extends CacheFactoryBean {
|
||||
|
||||
private String poolName;
|
||||
private boolean GEMFIRE65 = false;
|
||||
|
||||
@Override
|
||||
protected Cache createCache(final DistributedSystem system) throws Exception {
|
||||
initPool();
|
||||
|
||||
if (GEMFIRE65) {
|
||||
Callable<Cache> call = new Callable<Cache>() {
|
||||
public Cache call() throws Exception {
|
||||
return (Cache) new ClientCacheFactory(system.getProperties()).create();
|
||||
}
|
||||
};
|
||||
return call.call();
|
||||
}
|
||||
return super.createCache(system);
|
||||
protected Cache createCache(Object factory) {
|
||||
return (Cache) ((ClientCacheFactory) factory).create();
|
||||
}
|
||||
|
||||
private void initPool() {
|
||||
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...");
|
||||
}
|
||||
beanFactory.getBean(poolName, Pool.class);
|
||||
}
|
||||
@Override
|
||||
protected Object createFactory(Properties props) {
|
||||
return new ClientCacheFactory(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Cache fetchCache() {
|
||||
return (Cache) ClientCacheFactory.getAnyInstance();
|
||||
}
|
||||
|
||||
// private void initPool() {
|
||||
// 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...");
|
||||
// }
|
||||
// beanFactory.getBean(poolName, Pool.class);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Sets the pool name used by this client.
|
||||
*
|
||||
@@ -84,4 +81,4 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
|
||||
Assert.notNull(pool, "pool cannot be null");
|
||||
setPoolName(pool.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
|
||||
|
||||
private static final Log log = LogFactory.getLog(PoolFactoryBean.class);
|
||||
|
||||
// whether the pool has been created internaly or not
|
||||
// whether the pool has been created internally or not
|
||||
private boolean internalPool = true;
|
||||
|
||||
private Pool pool;
|
||||
|
||||
Reference in New Issue
Block a user