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");
|
||||
|
||||
Reference in New Issue
Block a user