fixed ClientCacheParser

This commit is contained in:
David Turanski
2013-02-12 09:14:18 -05:00
9 changed files with 138 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolManager;
@@ -38,6 +39,7 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
* configuration of the generic cache).
*
* @author Costin Leau
* @author Lyndon Adams
*/
public class ClientCacheFactoryBean extends CacheFactoryBean {
@@ -78,12 +80,22 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
private String poolName;
private Pool pool;
protected Boolean readyForEvents = false;
@Override
protected GemFireCache createCache(Object factory) {
ClientCacheFactory ccf = (ClientCacheFactory) factory;
initializePool(ccf);
return ccf.create();
// Now create the cache
GemFireCache cache = ccf.create();
// Register for events after pool/regions been created and iff non-durable client
readyForEvents();
// Return the cache
return cache;
}
@Override
@@ -176,6 +188,20 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
}
}
/**
* Inform cluster client cache is ready to receive events.
*/
private void readyForEvents(){
ClientCache clientCache = ClientCacheFactory.getAnyInstance();
if( readyForEvents != null && readyForEvents.booleanValue() && !clientCache.isClosed()){
try {
clientCache.readyForEvents();
}catch(IllegalStateException ex){
// Cannot be called for a non-durable client so exception is throw
}
}
}
/**
* Sets the pool name used by this client.
*
@@ -186,6 +212,19 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
this.poolName = poolName;
}
/**
* Set the readyForEvents event flag.
*
* @param readyForEvents
*/
public void setReadyForEvents(Boolean readyForEvents){
this.readyForEvents = readyForEvents;
}
public Boolean getReadyForEvents(){
return this.readyForEvents;
}
/**
* Sets the pool used by this client.
*
@@ -202,4 +241,5 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
new PdxOptions((ClientCacheFactory) factory).run();
}
}
}

View File

@@ -26,6 +26,7 @@ import org.w3c.dom.Element;
*
* @author Costin Leau
* @author David Turanski
* @author Lyndon Adams
*/
class ClientCacheParser extends CacheParser {
@@ -37,12 +38,12 @@ class ClientCacheParser extends CacheParser {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, parserContext, builder);
//ParsingUtils.setPropertyValue(element, builder, "pool-name","poolName",GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
ParsingUtils.setPropertyValue(element, builder, "pool-name", "poolName");
ParsingUtils.setPropertyValue(element, builder, "ready-for-events");
}
@Override
protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) {
ParsingUtils.setPropertyValue(element, dynamicRegionSupport, "pool-name");
ParsingUtils.setPropertyValue(element, dynamicRegionSupport, "pool-name");
}
}
}