SGF-122 - Added namespace support for FixedPartitionAttributes

This commit is contained in:
David Turanski
2012-08-30 13:54:54 -04:00
parent 1c411fd479
commit 1f0ae2b2ef
6 changed files with 190 additions and 6 deletions

View File

@@ -0,0 +1,98 @@
/*
* Copyright 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;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import com.gemstone.gemfire.cache.FixedPartitionAttributes;
/**
* @author David Turanski
*
*/
public class FixedPartitionAttributesFactoryBean implements FactoryBean<FixedPartitionAttributes>, InitializingBean {
private Boolean primary;
private String partitionName;
private Integer numBuckets;
private FixedPartitionAttributes fixedPartitionAttributes;
/**
* @param primary
*/
public void setPrimary(boolean primary) {
this.primary = primary;
}
/**
* @param partitionName the partitionName to set
*/
public void setPartitionName(String partitionName) {
this.partitionName = partitionName;
}
/**
* @param numBuckets the numBuckets to set
*/
public void setNumBuckets(Integer numBuckets) {
this.numBuckets = numBuckets;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
@Override
public FixedPartitionAttributes getObject() throws Exception {
return fixedPartitionAttributes;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
public Class<?> getObjectType() {
return FixedPartitionAttributes.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
@Override
public boolean isSingleton() {
return true;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.hasText(partitionName,"partitionName cannot be empty or null");
fixedPartitionAttributes = null;
if (primary == null && numBuckets == null){
fixedPartitionAttributes = FixedPartitionAttributes.createFixedPartition(partitionName);
} else if (primary == null && numBuckets != null){
fixedPartitionAttributes = FixedPartitionAttributes.createFixedPartition(partitionName, numBuckets);
} else if (primary != null && numBuckets == null) {
fixedPartitionAttributes = FixedPartitionAttributes.createFixedPartition(partitionName, primary);
} else {
fixedPartitionAttributes = FixedPartitionAttributes.createFixedPartition(partitionName,primary,numBuckets);
}
}
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import com.gemstone.gemfire.cache.FixedPartitionAttributes;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.PartitionResolver;
import com.gemstone.gemfire.cache.partition.PartitionListener;
@@ -58,6 +59,12 @@ public class PartitionAttributesFactoryBean implements FactoryBean<PartitionAttr
public void setColocatedWith(String colocatedRegionFullPath) {
paf.setColocatedWith(colocatedRegionFullPath);
}
public void setFixedPartitionAttributes(List<FixedPartitionAttributes> fixedPartitionAttributes) {
for (FixedPartitionAttributes fpa: fixedPartitionAttributes) {
paf.addFixedPartitionAttributes(fpa);
}
}
public void setLocalMaxMemory(int mb) {
paf.setLocalMaxMemory(mb);

View File

@@ -16,12 +16,17 @@
package org.springframework.data.gemfire.config;
import java.util.List;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.data.gemfire.FixedPartitionAttributesFactoryBean;
import org.springframework.data.gemfire.PartitionAttributesFactoryBean;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
import org.springframework.util.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
@@ -40,6 +45,7 @@ class PartitionedRegionParser extends AbstractRegionParser {
return PartitionedRegionFactoryBean.class;
}
@SuppressWarnings("unchecked")
@Override
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
boolean subRegion) {
@@ -104,8 +110,22 @@ class PartitionedRegionParser extends AbstractRegionParser {
parAttrBuilder.addPropertyValue("partitionListeners",
parsePartitionListeners(parserContext, subElement, builder));
}
List<Element> fixedPartitions = DomUtils.getChildElementsByTagName(element, "fixed-partition");
if (! CollectionUtils.isEmpty(fixedPartitions)){
@SuppressWarnings("rawtypes")
ManagedList fixedPartitionAttributes = new ManagedList();
for (Element fp: fixedPartitions) {
BeanDefinitionBuilder fpaBuilder = BeanDefinitionBuilder.genericBeanDefinition(FixedPartitionAttributesFactoryBean.class);
ParsingUtils.setPropertyValue(fp, fpaBuilder, "partition-name");
ParsingUtils.setPropertyValue(fp, fpaBuilder, "num-buckets");
ParsingUtils.setPropertyValue(fp, fpaBuilder, "primary");
fixedPartitionAttributes.add(fpaBuilder.getBeanDefinition());
}
parAttrBuilder.addPropertyValue("fixedPartitionAttributes", fixedPartitionAttributes);
}
//
// // add partition attributes attributes
attrBuilder.addPropertyValue("partitionAttributes", parAttrBuilder.getBeanDefinition());
// add partition/overflow settings as attributes