Refactored to use DiskStoreFactory
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating a DiskStore
|
||||
* @author David Turanski
|
||||
*/
|
||||
public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, InitializingBean, BeanNameAware {
|
||||
|
||||
private DiskStoreFactory diskStoreFactory;
|
||||
|
||||
private Boolean autoCompact;
|
||||
|
||||
private Boolean allowForceCompaction;
|
||||
|
||||
private Integer maxOplogSize;
|
||||
|
||||
private Integer timeInterval;
|
||||
|
||||
private Integer queueSize;
|
||||
|
||||
private Integer compactionThreshold;
|
||||
|
||||
private Integer writeBufferSize;
|
||||
|
||||
private GemFireCache cache;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<DiskDir> diskDirs;
|
||||
|
||||
@Override
|
||||
public DiskStore getObject() throws Exception {
|
||||
return diskStoreFactory.create(name == null ? DiskStoreFactory.DEFAULT_DISK_STORE_NAME : name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return DiskStore.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(cache, "Cache property must be set");
|
||||
diskStoreFactory = cache.createDiskStoreFactory();
|
||||
|
||||
if (allowForceCompaction != null) {
|
||||
diskStoreFactory.setAllowForceCompaction(allowForceCompaction);
|
||||
}
|
||||
if (compactionThreshold != null) {
|
||||
diskStoreFactory.setCompactionThreshold(compactionThreshold);
|
||||
}
|
||||
if (autoCompact != null) {
|
||||
diskStoreFactory.setAutoCompact(autoCompact);
|
||||
}
|
||||
if (queueSize != null) {
|
||||
diskStoreFactory.setQueueSize(queueSize);
|
||||
}
|
||||
if (writeBufferSize != null) {
|
||||
diskStoreFactory.setWriteBufferSize(writeBufferSize);
|
||||
}
|
||||
if (timeInterval != null) {
|
||||
diskStoreFactory.setTimeInterval(timeInterval);
|
||||
}
|
||||
if (maxOplogSize != null) {
|
||||
diskStoreFactory.setMaxOplogSize(maxOplogSize);
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(diskDirs)) {
|
||||
File[] diskDirFiles = new File[diskDirs.size()];
|
||||
int[] diskDirSizes = new int[diskDirs.size()];
|
||||
for (int i = 0; i < diskDirs.size(); i++) {
|
||||
DiskDir diskDir = diskDirs.get(i);
|
||||
diskDirFiles[i] = new File(diskDir.location);
|
||||
diskDirSizes[i] = diskDir.maxSize == null ? DiskStoreFactory.DEFAULT_DISK_DIR_SIZE : diskDir.maxSize;
|
||||
}
|
||||
diskStoreFactory.setDiskDirsAndSizes(diskDirFiles, diskDirSizes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setCache(GemFireCache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public void setAutoCompact(Boolean autoCompact) {
|
||||
this.autoCompact = autoCompact;
|
||||
}
|
||||
|
||||
public void setAllowForceCompaction(Boolean allowForceCompaction) {
|
||||
this.allowForceCompaction = allowForceCompaction;
|
||||
}
|
||||
|
||||
public void setMaxOplogSize(Integer maxOplogSize) {
|
||||
this.maxOplogSize = maxOplogSize;
|
||||
}
|
||||
|
||||
public void setTimeInterval(Integer timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public void setQueueSize(Integer queueSize) {
|
||||
this.queueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setCompactionThreshold(Integer compactionThreshold) {
|
||||
this.compactionThreshold = compactionThreshold;
|
||||
}
|
||||
|
||||
public void setWriteBufferSize(Integer writeBufferSize) {
|
||||
this.writeBufferSize = writeBufferSize;
|
||||
}
|
||||
|
||||
public void setDiskDirs(List<DiskDir> diskDirs) {
|
||||
this.diskDirs = diskDirs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class DiskDir {
|
||||
final String location;
|
||||
|
||||
final Integer maxSize;
|
||||
|
||||
public DiskDir(String location, int maxSize) {
|
||||
this.location = location;
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public DiskDir(String location) {
|
||||
this.location = location;
|
||||
this.maxSize = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.AttributesFactory;
|
||||
import com.gemstone.gemfire.cache.AttributesMutator;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
@@ -43,11 +42,14 @@ import com.gemstone.gemfire.cache.RegionFactory;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating generic GemFire {@link Region}s. Will try to first locate the region (by name)
|
||||
* and, in case none if found, proceed to creating one using the given settings.
|
||||
* FactoryBean for creating generic GemFire {@link Region}s. Will try to first
|
||||
* locate the region (by name) and, in case none if found, proceed to creating
|
||||
* one using the given settings.
|
||||
*
|
||||
* Note that this factory bean allows for very flexible creation of GemFire {@link Region}. For "client" regions
|
||||
* however, see {@link ClientRegionFactoryBean} which offers easier configuration and defaults.
|
||||
* Note that this factory bean allows for very flexible creation of GemFire
|
||||
* {@link Region}. For "client" regions however, see
|
||||
* {@link ClientRegionFactoryBean} which offers easier configuration and
|
||||
* defaults.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@@ -56,18 +58,26 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private boolean destroy = false;
|
||||
|
||||
private boolean close = true;
|
||||
|
||||
private Resource snapshot;
|
||||
|
||||
private CacheListener<K, V> cacheListeners[];
|
||||
private CacheLoader<K, V> cacheLoader;
|
||||
private CacheWriter<K, V> cacheWriter;
|
||||
private RegionAttributes<K, V> attributes;
|
||||
private Scope scope;
|
||||
private DataPolicy dataPolicy;
|
||||
private Region<K, V> region;
|
||||
private List<Region<?, ?>> subRegions;
|
||||
|
||||
private CacheLoader<K, V> cacheLoader;
|
||||
|
||||
private CacheWriter<K, V> cacheWriter;
|
||||
|
||||
private RegionAttributes<K, V> attributes;
|
||||
|
||||
private Scope scope;
|
||||
|
||||
private DataPolicy dataPolicy;
|
||||
|
||||
private Region<K, V> region;
|
||||
|
||||
private List<Region<?, ?>> subRegions;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -85,9 +95,8 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
if (attributes != null)
|
||||
AttributesFactory.validateAttributes(attributes);
|
||||
|
||||
final RegionFactory<K, V> regionFactory = (attributes != null ? c.createRegionFactory(attributes)
|
||||
: c.<K, V> createRegionFactory());
|
||||
|
||||
final RegionFactory<K, V> regionFactory = (attributes != null ? c.createRegionFactory(attributes) : c
|
||||
.<K, V> createRegionFactory());
|
||||
|
||||
if (!ObjectUtils.isEmpty(cacheListeners)) {
|
||||
for (CacheListener<K, V> listener : cacheListeners) {
|
||||
@@ -113,13 +122,13 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
|
||||
// get underlying AttributesFactory
|
||||
postProcess(findAttrFactory(regionFactory));
|
||||
|
||||
|
||||
Region<K, V> reg = regionFactory.create(regionName);
|
||||
log.info("Created new cache region [" + regionName + "]");
|
||||
if (snapshot != null) {
|
||||
reg.loadSnapshot(snapshot.getInputStream());
|
||||
}
|
||||
|
||||
|
||||
if (subRegions != null) {
|
||||
System.out.println("**********************************************" + subRegions.get(0));
|
||||
}
|
||||
@@ -134,24 +143,24 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
return (AttributesFactory<K, V>) ReflectionUtils.getField(attrField, regionFactory);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process the attribute factory object used for configuring the region of this factory bean during the initialization process.
|
||||
* The object is already initialized and configured by the factory bean before this method
|
||||
* Post-process the attribute factory object used for configuring the region
|
||||
* of this factory bean during the initialization process. The object is
|
||||
* already initialized and configured by the factory bean before this method
|
||||
* is invoked.
|
||||
*
|
||||
* @param attrFactory attribute factory
|
||||
* @deprecated as of GemFire 6.5, the use of {@link AttributesFactory} has been deprecated
|
||||
* @deprecated as of GemFire 6.5, the use of {@link AttributesFactory} has
|
||||
* been deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
protected void postProcess(AttributesFactory<K, V> attrFactory) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process the region object for this factory bean during the initialization process.
|
||||
* The object is already initialized and configured by the factory bean before this method
|
||||
* is invoked.
|
||||
* Post-process the region object for this factory bean during the
|
||||
* initialization process. The object is already initialized and configured
|
||||
* by the factory bean before this method is invoked.
|
||||
*
|
||||
* @param region
|
||||
*/
|
||||
@@ -159,13 +168,15 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (region != null) {
|
||||
if (close) {
|
||||
if (!region.getCache().isClosed()) {
|
||||
try {
|
||||
region.close();
|
||||
} catch (CacheClosedException cce) {
|
||||
}
|
||||
catch (CacheClosedException cce) {
|
||||
// nothing to see folks, move on.
|
||||
}
|
||||
}
|
||||
@@ -178,9 +189,9 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the region referred by this factory bean,
|
||||
* will be destroyed on shutdown (default false).
|
||||
* Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other.
|
||||
* Indicates whether the region referred by this factory bean, will be
|
||||
* destroyed on shutdown (default false). Note: destroy and close are
|
||||
* mutually exclusive. Enabling one will automatically disable the other.
|
||||
*
|
||||
* @param destroy whether or not to destroy the region
|
||||
*
|
||||
@@ -195,9 +206,9 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the region referred by this factory bean,
|
||||
* will be closed on shutdown (default true).
|
||||
* Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other.
|
||||
* Indicates whether the region referred by this factory bean, will be
|
||||
* closed on shutdown (default true). Note: destroy and close are mutually
|
||||
* exclusive. Enabling one will automatically disable the other.
|
||||
*
|
||||
* @param close whether to close or not the region
|
||||
* @see #setDestroy(boolean)
|
||||
@@ -210,9 +221,9 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the snapshots used for loading a newly <i>created</i> region.
|
||||
* That is, the snapshot will be used <i>only</i> when a new region is created - if the region
|
||||
* already exists, no loading will be performed.
|
||||
* Sets the snapshots used for loading a newly <i>created</i> region. That
|
||||
* is, the snapshot will be used <i>only</i> when a new region is created -
|
||||
* if the region already exists, no loading will be performed.
|
||||
*
|
||||
* @see #setName(String)
|
||||
* @param snapshot the snapshot to set
|
||||
@@ -222,9 +233,9 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache listeners used for the region used by this factory.
|
||||
* Used only when a new region is created.Overrides the settings
|
||||
* specified through {@link #setAttributes(RegionAttributes)}.
|
||||
* Sets the cache listeners used for the region used by this factory. Used
|
||||
* only when a new region is created.Overrides the settings specified
|
||||
* through {@link #setAttributes(RegionAttributes)}.
|
||||
*
|
||||
* @param cacheListeners the cacheListeners to set on a newly created region
|
||||
*/
|
||||
@@ -237,11 +248,10 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
this.subRegions = subRegions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the cache loader used for the region used by this factory.
|
||||
* Used only when a new region is created.Overrides the settings
|
||||
* specified through {@link #setAttributes(RegionAttributes)}.
|
||||
* Sets the cache loader used for the region used by this factory. Used only
|
||||
* when a new region is created.Overrides the settings specified through
|
||||
* {@link #setAttributes(RegionAttributes)}.
|
||||
*
|
||||
* @param cacheLoader the cacheLoader to set on a newly created region
|
||||
*/
|
||||
@@ -250,9 +260,9 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache writer used for the region used by this factory.
|
||||
* Used only when a new region is created. Overrides the settings
|
||||
* specified through {@link #setAttributes(RegionAttributes)}.
|
||||
* Sets the cache writer used for the region used by this factory. Used only
|
||||
* when a new region is created. Overrides the settings specified through
|
||||
* {@link #setAttributes(RegionAttributes)}.
|
||||
*
|
||||
* @param cacheWriter the cacheWriter to set on a newly created region
|
||||
*/
|
||||
@@ -261,8 +271,8 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data policy. Used only when a new region is created.
|
||||
* Overrides the settings specified through {@link #setAttributes(RegionAttributes)}.
|
||||
* Sets the data policy. Used only when a new region is created. Overrides
|
||||
* the settings specified through {@link #setAttributes(RegionAttributes)}.
|
||||
*
|
||||
* @param dataPolicy the region data policy
|
||||
*/
|
||||
@@ -271,8 +281,8 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the region scope. Used only when a new region is created.
|
||||
* Overrides the settings specified through {@link #setAttributes(RegionAttributes)}.
|
||||
* Sets the region scope. Used only when a new region is created. Overrides
|
||||
* the settings specified through {@link #setAttributes(RegionAttributes)}.
|
||||
*
|
||||
* @see Scope
|
||||
* @param scope the region scope
|
||||
@@ -283,8 +293,8 @@ public class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V> imple
|
||||
|
||||
/**
|
||||
* Sets the region attributes used for the region used by this factory.
|
||||
* Allows maximum control in specifying the region settings.
|
||||
* Used only when a new region is created.
|
||||
* Allows maximum control in specifying the region settings. Used only when
|
||||
* a new region is created.
|
||||
*
|
||||
* @param attributes the attributes to set on a newly created region
|
||||
*/
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.springframework.data.gemfire.SubRegionFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
@@ -34,35 +32,26 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
if (element.hasAttribute("subregion")) {
|
||||
return SubRegionFactoryBean.class;
|
||||
}
|
||||
else {
|
||||
return RegionFactoryBean.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder){
|
||||
protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
boolean subRegion = element.hasAttribute("subregion");
|
||||
|
||||
boolean subRegion = isSubRegion(element);
|
||||
|
||||
doParseRegion(element, parserContext, builder, subRegion);
|
||||
|
||||
|
||||
if (subRegion) {
|
||||
builder.addPropertyValue("parent", parserContext.getContainingBeanDefinition().getAttribute("parent"));
|
||||
builder.addPropertyValue("parent", parserContext.getContainingBeanDefinition().getAttribute("parent"));
|
||||
builder.addPropertyValue("regionName", element.getAttribute(NAME_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion);
|
||||
|
||||
protected void doParseSubRegion(Element element, Element subElement, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, boolean subRegion) {
|
||||
|
||||
|
||||
String regionPath = null;
|
||||
String parentBeanName = null;
|
||||
if (subRegion) {
|
||||
@@ -71,28 +60,26 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
|
||||
else {
|
||||
parentBeanName = getRegionNameFromElement(element);
|
||||
}
|
||||
regionPath = StringUtils
|
||||
.arrayToDelimitedString(
|
||||
new String[] { parentBeanName, getRegionNameFromElement(subElement) }, "/");
|
||||
regionPath = StringUtils.arrayToDelimitedString(new String[] { parentBeanName,
|
||||
getRegionNameFromElement(subElement) }, "/");
|
||||
if (!regionPath.startsWith("/")) {
|
||||
regionPath = "/" + regionPath;
|
||||
}
|
||||
|
||||
/*
|
||||
* The Region parser needs some context to handle recursion correctly
|
||||
* The Region parser needs some context to handle recursion correctly
|
||||
*/
|
||||
builder.getBeanDefinition().setAttribute("parent",
|
||||
new BeanDefinitionHolder(builder.getBeanDefinition(), parentBeanName));
|
||||
builder.getBeanDefinition().setAttribute("regionPath",regionPath);
|
||||
builder.getBeanDefinition().setAttribute("regionPath", regionPath);
|
||||
|
||||
// Make recursive call
|
||||
BeanDefinition subRegionDef = this.parseSubRegion(subElement, parserContext, builder);
|
||||
//TODO: Is there a better work-around?
|
||||
// TODO: Is there a better work-around?
|
||||
/*
|
||||
* This setting prevents the BF from generating a name for this been
|
||||
*/
|
||||
subRegionDef.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("registering subregion as " + regionPath);
|
||||
}
|
||||
@@ -100,17 +87,13 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
|
||||
}
|
||||
|
||||
private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
/*
|
||||
* Easy way to mark this element as a subregion
|
||||
*/
|
||||
element.setAttribute("subregion", "true");
|
||||
BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(element,
|
||||
builder.getBeanDefinition());
|
||||
return beanDefinition;
|
||||
}
|
||||
|
||||
private String getRegionNameFromElement(Element element){
|
||||
|
||||
private String getRegionNameFromElement(Element element) {
|
||||
String name = element.getAttribute(NAME_ATTRIBUTE);
|
||||
return StringUtils.hasText(name)? name: element.getAttribute(ID_ATTRIBUTE);
|
||||
return StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE);
|
||||
}
|
||||
}
|
||||
@@ -26,36 +26,43 @@ import org.springframework.data.gemfire.SubRegionFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Extension class dealing with the attribute clash (name) that triggers the region name to
|
||||
* be considered a bean alias. Overrides the automatic alias detection and replaces it with its own
|
||||
* using meta attributes (since the parsing method is final).
|
||||
* Extension class dealing with the attribute clash (name) that triggers the
|
||||
* region name to be considered a bean alias. Overrides the automatic alias
|
||||
* detection and replaces it with its own using meta attributes (since the
|
||||
* parsing method is final).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
if (element.hasAttribute("subregion")){
|
||||
System.out.println("building subregion " + element.getAttribute(NAME_ATTRIBUTE));
|
||||
|
||||
if (isSubRegion(element)) {
|
||||
return SubRegionFactoryBean.class;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return RegionFactoryBean.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
|
||||
ParsingUtils.addBeanAliasAsMetadata(element, builder);
|
||||
|
||||
|
||||
doParseInternal(element, parserContext, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry) {
|
||||
// add the aliases from the metadata
|
||||
// add the aliases from the metadata
|
||||
super.registerBeanDefinition(ParsingUtils.replaceBeanAliasAsMetadata(definition), registry);
|
||||
}
|
||||
|
||||
protected boolean isSubRegion(Element element) {
|
||||
return element.getParentNode().getLocalName().endsWith("region");
|
||||
}
|
||||
|
||||
protected abstract void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DiskStoreFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
ParsingUtils.setPropertyValue(element, builder, "auto-compact");
|
||||
ParsingUtils.setPropertyValue(element, builder, "allow-force-compaction");
|
||||
ParsingUtils.setPropertyValue(element, builder, "max-oplog-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "time-interval");
|
||||
ParsingUtils.setPropertyValue(element, builder, "queue-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "compaction-threshold");
|
||||
ParsingUtils.setPropertyValue(element, builder, "write-buffer-size");
|
||||
|
||||
List<Element> diskDirElements = DomUtils.getChildElementsByTagName(element, "disk-dir");
|
||||
|
||||
if (!CollectionUtils.isEmpty(diskDirElements)) {
|
||||
ManagedList<AbstractBeanDefinition> diskDirs = new ManagedList<AbstractBeanDefinition>();
|
||||
for (Element diskDirElement : diskDirElements) {
|
||||
BeanDefinitionBuilder diskDirBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskDir.class);
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("location"));
|
||||
if (diskDirElement.hasAttribute("max-size")) {
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("max-size"));
|
||||
}
|
||||
diskDirs.add(diskDirBuilder.getBeanDefinition());
|
||||
}
|
||||
builder.addPropertyValue("diskDirs", diskDirs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,27 +23,35 @@ import com.gemstone.gemfire.cache.DiskWriteAttributes;
|
||||
import com.gemstone.gemfire.cache.DiskWriteAttributesFactory;
|
||||
|
||||
/**
|
||||
* Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans.
|
||||
* Simple utility class used for defining nested factory-method like definitions
|
||||
* w/o polluting the container with useless beans.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
class DiskWriteAttributesFactoryBean implements FactoryBean<DiskWriteAttributes>, InitializingBean {
|
||||
|
||||
private DiskWriteAttributes attributes;
|
||||
|
||||
private DiskWriteAttributesFactory attrFactory;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
attributes = attrFactory.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskWriteAttributes getObject() throws Exception {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return (attributes != null ? attributes.getClass() : DiskWriteAttributes.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.springframework.data.gemfire.repository.config.GemfireRepositoryParse
|
||||
* Namespace handler for GemFire definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
*/
|
||||
class GemfireNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("cache", new CacheParser());
|
||||
registerBeanDefinitionParser("client-cache", new ClientCacheParser());
|
||||
@@ -33,15 +35,14 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport {
|
||||
registerBeanDefinitionParser("lookup-region", new LookupRegionParser());
|
||||
registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser());
|
||||
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("local-region", new LocalRegionParser());
|
||||
registerBeanDefinitionParser("client-region", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("pool", new PoolParser());
|
||||
registerBeanDefinitionParser("index", new IndexParser());
|
||||
registerBeanDefinitionParser("disk-store", new DiskStoreParser());
|
||||
registerBeanDefinitionParser("cache-server", new CacheServerParser());
|
||||
|
||||
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
|
||||
|
||||
registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser());
|
||||
|
||||
registerBeanDefinitionParser("repositories", new GemfireRepositoryParser());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* Parser for <replicated-region;gt; definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
*/
|
||||
class LocalRegionParser extends AbstractRegionParser {
|
||||
@Override
|
||||
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
boolean subRegion) {
|
||||
|
||||
// set the data policy
|
||||
String attr = element.getAttribute("persistent");
|
||||
// if (Boolean.parseBoolean(attr)) {
|
||||
// builder.addPropertyValue("dataPolicy",
|
||||
// DataPolicy.PERSISTENT_REPLICATE);
|
||||
// }
|
||||
// else {
|
||||
// builder.addPropertyValue("dataPolicy", DataPolicy.REPLICATE);
|
||||
// }
|
||||
|
||||
builder.addPropertyValue("scope", Scope.LOCAL);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "name", "name");
|
||||
|
||||
BeanDefinitionBuilder attrBuilder = builder;
|
||||
|
||||
if (!subRegion) {
|
||||
attr = element.getAttribute("cache-ref");
|
||||
// add cache reference (fallback to default if nothing is specified)
|
||||
builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache"));
|
||||
attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class);
|
||||
}
|
||||
// add attributes
|
||||
|
||||
ParsingUtils.parseStatistics(element, attrBuilder);
|
||||
|
||||
attr = element.getAttribute("publisher");
|
||||
if (StringUtils.hasText(attr)) {
|
||||
attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr));
|
||||
}
|
||||
|
||||
ParsingUtils.parseExpiration(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseEviction(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseDiskStorage(element, attrBuilder);
|
||||
|
||||
if (!subRegion) {
|
||||
builder.addPropertyValue("attributes", attrBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
List<Element> subElements = DomUtils.getChildElements(element);
|
||||
|
||||
// parse nested elements
|
||||
for (Element subElement : subElements) {
|
||||
String name = subElement.getLocalName();
|
||||
|
||||
if ("cache-listener".equals(name)) {
|
||||
builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder));
|
||||
}
|
||||
|
||||
else if ("cache-loader".equals(name)) {
|
||||
builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder));
|
||||
}
|
||||
|
||||
else if ("cache-writer".equals(name)) {
|
||||
builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder));
|
||||
}
|
||||
// subregion
|
||||
else if (name.endsWith("region")) {
|
||||
doParseSubRegion(element, subElement, parserContext, builder, subRegion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) {
|
||||
return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder);
|
||||
}
|
||||
|
||||
private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) {
|
||||
return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder);
|
||||
}
|
||||
|
||||
private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) {
|
||||
return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,12 +30,13 @@ import org.w3c.dom.Element;
|
||||
* Parser for <lookup-region;gt; definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
*/
|
||||
class LookupRegionParser extends AbstractRegionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
if (element.hasAttribute("subregion")) {
|
||||
if (isSubRegion(element)) {
|
||||
return SubRegionFactoryBean.class;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -27,11 +27,13 @@ import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskWriteAttributesFactory;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
|
||||
@@ -44,14 +46,20 @@ abstract class ParsingUtils {
|
||||
|
||||
private static final String ALIASES_KEY = ParsingUtils.class.getName() + ":aliases";
|
||||
|
||||
static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attrName, String propertyName) {
|
||||
String attr = element.getAttribute(attrName);
|
||||
static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName,
|
||||
String propertyName) {
|
||||
String attr = element.getAttribute(attributeName);
|
||||
if (StringUtils.hasText(attr)) {
|
||||
builder.addPropertyValue(propertyName, attr);
|
||||
}
|
||||
}
|
||||
|
||||
static void setPropertyReference(Element element, BeanDefinitionBuilder builder, String attrName, String propertyName) {
|
||||
static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName) {
|
||||
setPropertyValue(element, builder, attributeName, Conventions.attributeNameToPropertyName(attributeName));
|
||||
}
|
||||
|
||||
static void setPropertyReference(Element element, BeanDefinitionBuilder builder, String attrName,
|
||||
String propertyName) {
|
||||
String attr = element.getAttribute(attrName);
|
||||
if (StringUtils.hasText(attr)) {
|
||||
builder.addPropertyReference(propertyName, attr);
|
||||
@@ -59,9 +67,11 @@ abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility for parsing bean aliases. Normally parsed by AbstractBeanDefinitionParser however due to the attribute clash
|
||||
* (bean uses 'name' for aliases while region use it to indicate their name), the parser needs to handle this differently by
|
||||
* storing them as metadata which gets deleted just before registration.
|
||||
* Utility for parsing bean aliases. Normally parsed by
|
||||
* AbstractBeanDefinitionParser however due to the attribute clash (bean
|
||||
* uses 'name' for aliases while region use it to indicate their name), the
|
||||
* parser needs to handle this differently by storing them as metadata which
|
||||
* gets deleted just before registration.
|
||||
*
|
||||
* @param element
|
||||
* @param builder
|
||||
@@ -87,10 +97,13 @@ abstract class ParsingUtils {
|
||||
|
||||
/**
|
||||
* Utility method handling parsing of nested definition of the type:
|
||||
*
|
||||
* <pre>
|
||||
* <tag ref="someBean"/>
|
||||
* </pre>
|
||||
* or
|
||||
*
|
||||
* or
|
||||
*
|
||||
* <pre>
|
||||
* <tag>
|
||||
* <bean .... />
|
||||
@@ -100,11 +113,13 @@ abstract class ParsingUtils {
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, BeanDefinitionBuilder builder) {
|
||||
static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element,
|
||||
BeanDefinitionBuilder builder) {
|
||||
return parseRefOrNestedBeanDeclaration(parserContext, element, builder, "ref");
|
||||
}
|
||||
|
||||
static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, BeanDefinitionBuilder builder, String refAttrName) {
|
||||
static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element,
|
||||
BeanDefinitionBuilder builder, String refAttrName) {
|
||||
String attr = element.getAttribute(refAttrName);
|
||||
boolean hasRef = StringUtils.hasText(attr);
|
||||
|
||||
@@ -142,10 +157,12 @@ abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses disk store sub-element. Populates the given attribute factory with the proper attributes.
|
||||
* Parses disk store sub-element. Populates the given attribute factory with
|
||||
* the proper attributes.
|
||||
*
|
||||
* @param element - element enclosing the disk-store definition
|
||||
* @param beanBuilder - beanbuilder for a RegionAttributesFactoryBean instance
|
||||
* @param beanBuilder - beanbuilder for a RegionAttributesFactoryBean
|
||||
* instance
|
||||
* @return true if parsing actually occured, false otherwise
|
||||
*/
|
||||
static boolean parseDiskStorage(Element element, BeanDefinitionBuilder beanBuilder) {
|
||||
@@ -154,14 +171,16 @@ abstract class ParsingUtils {
|
||||
if (diskStoreElement == null)
|
||||
return false;
|
||||
|
||||
BeanDefinitionBuilder diskDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskWriteAttributesFactory.class);
|
||||
setPropertyValue(diskStoreElement, diskDefBuilder, "synchronous-write", "synchronous");
|
||||
if (diskStoreElement.getParentNode().getLocalName().endsWith("region")) {
|
||||
System.out.println("This is a nested disk-store");
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder diskDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactory.class);
|
||||
setPropertyValue(diskStoreElement, diskDefBuilder, "auto-compact", "rollOplogs");
|
||||
setPropertyValue(diskStoreElement, diskDefBuilder, "max-oplog-size", "maxOplogSize");
|
||||
setPropertyValue(diskStoreElement, diskDefBuilder, "time-interval", "timeInterval");
|
||||
setPropertyValue(diskStoreElement, diskDefBuilder, "queue-size", "bytesThreshold");
|
||||
|
||||
|
||||
// parse nested disk-dir
|
||||
List<Element> list = DomUtils.getChildElementsByTagName(diskStoreElement, "disk-dir");
|
||||
ManagedList<Object> locations = new ManagedList<Object>(list.size());
|
||||
@@ -176,7 +195,7 @@ abstract class ParsingUtils {
|
||||
|
||||
// wrap up the disk attributes factory to call 'create'
|
||||
|
||||
BeanDefinitionBuilder factoryWrapper = BeanDefinitionBuilder.genericBeanDefinition(DiskWriteAttributesFactoryBean.class);
|
||||
BeanDefinitionBuilder factoryWrapper = BeanDefinitionBuilder.genericBeanDefinition(DiskStoreFactoryBean.class);
|
||||
factoryWrapper.addPropertyValue("diskAttributesFactory", diskDefBuilder.getBeanDefinition());
|
||||
beanBuilder.addPropertyValue("diskWriteAttributes", factoryWrapper.getBeanDefinition());
|
||||
beanBuilder.addPropertyValue("diskDirs", locations);
|
||||
@@ -186,7 +205,8 @@ abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the eviction sub-element. Populates the given attribute factory with the proper attributes.
|
||||
* Parses the eviction sub-element. Populates the given attribute factory
|
||||
* with the proper attributes.
|
||||
*
|
||||
* @param parserContext
|
||||
* @param element
|
||||
@@ -199,7 +219,8 @@ abstract class ParsingUtils {
|
||||
if (evictionElement == null)
|
||||
return false;
|
||||
|
||||
BeanDefinitionBuilder evictionDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(EvictionAttributesFactoryBean.class);
|
||||
BeanDefinitionBuilder evictionDefBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(EvictionAttributesFactoryBean.class);
|
||||
|
||||
// do manual conversion since the enum is not public
|
||||
String attr = evictionElement.getAttribute("type");
|
||||
@@ -210,7 +231,6 @@ abstract class ParsingUtils {
|
||||
setPropertyValue(evictionElement, evictionDefBuilder, "threshold", "threshold");
|
||||
setPropertyValue(evictionElement, evictionDefBuilder, "action", "action");
|
||||
|
||||
|
||||
// get object sizer (if declared)
|
||||
Element objectSizerElement = DomUtils.getChildElementByTagName(evictionElement, "object-sizer");
|
||||
|
||||
@@ -223,13 +243,13 @@ abstract class ParsingUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void parseStatistics(Element element, BeanDefinitionBuilder attrBuilder) {
|
||||
setPropertyValue(element, attrBuilder, "statistics", "statisticsEnabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the expiration sub-elements. Populates the given attribute factory with proper attributes.
|
||||
* Parses the expiration sub-elements. Populates the given attribute factory
|
||||
* with proper attributes.
|
||||
*
|
||||
* @param parserContext
|
||||
* @param element
|
||||
@@ -250,7 +270,25 @@ abstract class ParsingUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean parseExpiration(Element rootElement, String elementName, String propertyName, BeanDefinitionBuilder attrBuilder) {
|
||||
static void parseAdditionalAttributes(ParserContext parserContext, Element element,
|
||||
BeanDefinitionBuilder attrBuilder) {
|
||||
setPropertyValue(element, attrBuilder, "persistent", "persistBackup");
|
||||
setPropertyValue(element, attrBuilder, "ignore-jta", "ignoreJTA");
|
||||
setPropertyValue(element, attrBuilder, "key-constraint", "keyConstraint");
|
||||
setPropertyValue(element, attrBuilder, "value-constraint", "valueConstraint");
|
||||
setPropertyValue(element, attrBuilder, "lock-grantor", "lockGrantor");
|
||||
setPropertyValue(element, attrBuilder, "enable-subscription-conflation", "enableSubscriptionConflation");
|
||||
setPropertyValue(element, attrBuilder, "enable-async-conflation", "enableAsyncConflation");
|
||||
setPropertyValue(element, attrBuilder, "initial-capacity", "initialCapacity");
|
||||
String indexUpdateType = element.getAttribute("index-update-type");
|
||||
if (StringUtils.hasText(indexUpdateType)) {
|
||||
attrBuilder.addPropertyValue("indexMaintenanceSynchronous", "synchronous".equals(indexUpdateType));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean parseExpiration(Element rootElement, String elementName, String propertyName,
|
||||
BeanDefinitionBuilder attrBuilder) {
|
||||
Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
|
||||
|
||||
if (expirationElement == null)
|
||||
@@ -259,7 +297,6 @@ abstract class ParsingUtils {
|
||||
String expirationTime = null;
|
||||
ExpirationAction action = ExpirationAction.INVALIDATE;
|
||||
|
||||
|
||||
// do manual conversion since the enum is not public
|
||||
String attr = expirationElement.getAttribute("timeout");
|
||||
if (StringUtils.hasText(attr)) {
|
||||
@@ -284,7 +321,8 @@ abstract class ParsingUtils {
|
||||
action = ExpirationAction.LOCAL_INVALIDATE;
|
||||
}
|
||||
}
|
||||
BeanDefinitionBuilder expirationAttributes = BeanDefinitionBuilder.genericBeanDefinition(ExpirationAttributes.class);
|
||||
BeanDefinitionBuilder expirationAttributes = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(ExpirationAttributes.class);
|
||||
expirationAttributes.addConstructorArgValue(expirationTime);
|
||||
expirationAttributes.addConstructorArgValue(action);
|
||||
attrBuilder.addPropertyValue(propertyName, expirationAttributes.getBeanDefinition());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -61,7 +61,7 @@ class ReplicatedRegionParser extends AbstractRegionParser {
|
||||
attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class);
|
||||
}
|
||||
// add attributes
|
||||
|
||||
ParsingUtils.parseAdditionalAttributes(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseStatistics(element, attrBuilder);
|
||||
|
||||
attr = element.getAttribute("publisher");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("diskstore-ns-new.xml")
|
||||
public class DiskStoreNamespaceTest {
|
||||
private static File diskStoreDir;
|
||||
|
||||
@Autowired
|
||||
DiskStore diskStore1;
|
||||
|
||||
@Test
|
||||
public void testDiskStore() {
|
||||
assertEquals("diskStore1", diskStore1.getName());
|
||||
assertEquals(50, diskStore1.getQueueSize());
|
||||
assertEquals(true, diskStore1.getAutoCompact());
|
||||
assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold());
|
||||
assertEquals(9999, diskStore1.getTimeInterval());
|
||||
assertEquals(10, diskStore1.getMaxOplogSize());
|
||||
assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
String path = "./build/tmp";
|
||||
diskStoreDir = new File(path);
|
||||
if (!diskStoreDir.exists()) {
|
||||
diskStoreDir.mkdir();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
for (File file : diskStoreDir.listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
diskStoreDir.delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionLookupFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("local-ns.xml")
|
||||
public class LocalRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testBasicReplica() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublishingReplica() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
|
||||
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
|
||||
assertEquals("publisher", TestUtils.readField("name", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertFalse(attrs.getPublisher());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexReplica() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class);
|
||||
CacheListener[] listeners = TestUtils.readField("cacheListeners", fb);
|
||||
assertFalse(ObjectUtils.isEmpty(listeners));
|
||||
assertEquals(2, listeners.length);
|
||||
assertSame(listeners[0], context.getBean("c-listener"));
|
||||
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", fb));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
RegionLookupFactoryBean lfb = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
assertEquals("existing", TestUtils.readField("name", lfb));
|
||||
assertEquals(existing, context.getBean("lookup"));
|
||||
}
|
||||
}
|
||||
@@ -33,13 +33,13 @@
|
||||
</gfe:pool>
|
||||
|
||||
<gfe:client-region id="persistent" pool-name="gemfire-pool" persistent="true">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
|
||||
<gfe:disk-dir location="./" max-size="1"/>
|
||||
</gfe:disk-store>
|
||||
</gfe:client-region>
|
||||
|
||||
<gfe:client-region id="overflow" pool-name="gemfire-pool">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
|
||||
<gfe:disk-dir location="./" max-size="1"/>
|
||||
</gfe:disk-store>
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<gfe:cache/>
|
||||
<util:properties id="props">
|
||||
<prop key="location">./build/tmp</prop>
|
||||
<prop key="queueSize">50</prop>
|
||||
<prop key="autoCompact">true</prop>
|
||||
<prop key="maxOpLogSize">10</prop>
|
||||
<prop key="timeInterval">9999</prop>
|
||||
<prop key="maxSize">1</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<gfe:disk-store id="diskStore1" queue-size="${queueSize}" auto-compact="${autoCompact}"
|
||||
max-oplog-size="${maxOpLogSize}" time-interval="${timeInterval}">
|
||||
<gfe:disk-dir location="${location}" max-size="${maxSize}"/>
|
||||
</gfe:disk-store>
|
||||
</beans>
|
||||
@@ -24,7 +24,7 @@
|
||||
</gfe:partitioned-region>
|
||||
|
||||
<gfe:replicated-region id="replicated-data" persistent="true" close="true" destroy="false">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
|
||||
<gfe:disk-dir location="./build/tmp" max-size="1"/>
|
||||
</gfe:disk-store>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
<gfe:partitioned-region id="partition-data" persistent="false">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
|
||||
<gfe:disk-dir location="./" max-size="1"/>
|
||||
</gfe:disk-store>
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" default-lazy-init="true">
|
||||
|
||||
<gfe:cache />
|
||||
|
||||
<gfe:local-region id="simple" />
|
||||
|
||||
<gfe:local-region id="pub" name="publisher"/>
|
||||
|
||||
<gfe:local-region id="complex" close="true" destroy="false">
|
||||
<gfe:cache-listener>
|
||||
<ref bean="c-listener"/>
|
||||
<bean class="org.springframework.data.gemfire.SimpleCacheListener"/>
|
||||
</gfe:cache-listener>
|
||||
<gfe:cache-loader ref="c-loader"/>
|
||||
<gfe:cache-writer ref="c-writer"/>
|
||||
</gfe:local-region>
|
||||
|
||||
<bean id="c-listener" class="org.springframework.data.gemfire.SimpleCacheListener"/>
|
||||
<bean id="c-loader" class="org.springframework.data.gemfire.SimpleCacheLoader"/>
|
||||
<bean id="c-writer" class="org.springframework.data.gemfire.SimpleCacheWriter"/>
|
||||
|
||||
<gfe:lookup-region id="lookup" name="existing"/>
|
||||
</beans>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<gfe:replicated-region id="replicatedParent">
|
||||
<gfe:lookup-region name="lookupChild">
|
||||
<gfe:partitioned-region name="partitionedGrandchild"/>
|
||||
<gfe:partitioned-region name="partitionedGrandchild"/>
|
||||
</gfe:lookup-region>
|
||||
</gfe:replicated-region>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user