Fixes JIRA bug SGF-312 allowing developers to declare/define and register multiple PartitionListeners on a Partitioned Region using nested inner bean and bean reference elements inside the <gfe:partition-listener> sub-element of the <gfe:partitioned-region> element in the SDG XML namespace (XSD).

This commit is contained in:
John Blum
2014-08-27 23:08:39 -07:00
parent 299dd49a79
commit b9a966e11a
6 changed files with 225 additions and 111 deletions

View File

@@ -27,23 +27,24 @@ import com.gemstone.gemfire.cache.PartitionResolver;
import com.gemstone.gemfire.cache.partition.PartitionListener;
/**
* Spring-friendly bean for creating {@link PartitionAttributes}. Eliminates the
* need of using a XML 'factory-method' tag and allows the attributes properties
* to be set directly.
* Spring-friendly bean for creating {@link PartitionAttributes}. Eliminates the need of using
* a XML 'factory-method' tag and allows the attributes properties to be set directly.
*
* @author Costin Leau
* @author David Turanski
* @author John Blum
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public class PartitionAttributesFactoryBean implements FactoryBean<PartitionAttributes>, InitializingBean {
private final com.gemstone.gemfire.cache.PartitionAttributesFactory paf = new com.gemstone.gemfire.cache.PartitionAttributesFactory();
private final com.gemstone.gemfire.cache.PartitionAttributesFactory partitionAttributesFactory =
new com.gemstone.gemfire.cache.PartitionAttributesFactory();
private List<PartitionListener> listeners;
@Override
public PartitionAttributes getObject() throws Exception {
return paf.create();
return partitionAttributesFactory.create();
}
@Override
@@ -57,21 +58,21 @@ public class PartitionAttributesFactoryBean implements FactoryBean<PartitionAttr
}
public void setColocatedWith(String colocatedRegionFullPath) {
paf.setColocatedWith(colocatedRegionFullPath);
partitionAttributesFactory.setColocatedWith(colocatedRegionFullPath);
}
public void setFixedPartitionAttributes(List<FixedPartitionAttributes> fixedPartitionAttributes) {
for (FixedPartitionAttributes fpa : fixedPartitionAttributes) {
paf.addFixedPartitionAttributes(fpa);
partitionAttributesFactory.addFixedPartitionAttributes(fpa);
}
}
public void setLocalMaxMemory(int mb) {
paf.setLocalMaxMemory(mb);
partitionAttributesFactory.setLocalMaxMemory(mb);
}
public void setPartitionResolver(PartitionResolver resolver) {
paf.setPartitionResolver(resolver);
partitionAttributesFactory.setPartitionResolver(resolver);
}
public void setPartitionListeners(List<PartitionListener> listeners) {
@@ -79,32 +80,33 @@ public class PartitionAttributesFactoryBean implements FactoryBean<PartitionAttr
}
public void setRecoveryDelay(long recoveryDelay) {
paf.setRecoveryDelay(recoveryDelay);
partitionAttributesFactory.setRecoveryDelay(recoveryDelay);
}
public void setRedundantCopies(int redundantCopies) {
paf.setRedundantCopies(redundantCopies);
partitionAttributesFactory.setRedundantCopies(redundantCopies);
}
public void setStartupRecoveryDelay(long startupRecoveryDelay) {
paf.setStartupRecoveryDelay(startupRecoveryDelay);
partitionAttributesFactory.setStartupRecoveryDelay(startupRecoveryDelay);
}
public void setTotalMaxMemory(long mb) {
paf.setTotalMaxMemory(mb);
partitionAttributesFactory.setTotalMaxMemory(mb);
}
public void setTotalNumBuckets(int numBuckets) {
paf.setTotalNumBuckets(numBuckets);
partitionAttributesFactory.setTotalNumBuckets(numBuckets);
}
@Override
public void afterPropertiesSet() throws Exception {
if (listeners != null) {
for (PartitionListener listener : listeners) {
paf.addPartitionListener(listener);
partitionAttributesFactory.addPartitionListener(listener);
}
}
}
}
}

View File

@@ -111,7 +111,7 @@ abstract class ParsingUtils {
if (StringUtils.hasText(refAttributeValue)) {
if (!childElements.isEmpty()) {
parserContext.getReaderContext().error(String.format(
"Use either the '%1$s' attribute or a nested bean declaration for '%2$s' element, but not both",
"Use either the '%1$s' attribute or a nested bean declaration for '%2$s' element, but not both.",
refAttributeName, element.getLocalName()), element);
}
@@ -163,7 +163,7 @@ abstract class ParsingUtils {
// TODO also triggered when there are no child elements; need to change the message...
if (single) {
parserContext.getReaderContext().error(String.format(
"The element '%1$s' does not support multiple nested bean definitions",
"The element '%1$s' does not support multiple nested bean definitions.",
element.getLocalName()), element);
}
}

View File

@@ -48,24 +48,24 @@ class PartitionedRegionParser extends AbstractRegionParser {
@Override
@SuppressWarnings("unchecked")
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder,
boolean subRegion) {
validateDataPolicyShortcutAttributesMutualExclusion(element, parserContext);
super.doParse(element, builder);
super.doParse(element, regionBuilder);
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
RegionAttributesFactoryBean.class);
super.doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion);
super.doParseCommonRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion);
builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
regionBuilder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
BeanDefinitionBuilder partitionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
PartitionAttributesFactoryBean.class);
parseColocatedWith(element, builder, partitionAttributesBuilder, "colocated-with");
parseColocatedWith(element, regionBuilder, partitionAttributesBuilder, "colocated-with");
ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "copies", "redundantCopies");
ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "local-max-memory");
ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "recovery-delay");
@@ -77,14 +77,14 @@ class PartitionedRegionParser extends AbstractRegionParser {
if (partitionResolverSubElement != null) {
partitionAttributesBuilder.addPropertyValue("partitionResolver",
parsePartitionResolver(partitionResolverSubElement, parserContext, builder));
parsePartitionResolver(partitionResolverSubElement, parserContext, regionBuilder));
}
Element partitionListenerSubElement = DomUtils.getChildElementByTagName(element, "partition-listener");
if (partitionListenerSubElement != null) {
partitionAttributesBuilder.addPropertyValue("partitionListeners",
parsePartitionListeners(partitionListenerSubElement, parserContext, builder));
parsePartitionListeners(partitionListenerSubElement, parserContext, regionBuilder));
}
List<Element> fixedPartitionSubElements = DomUtils.getChildElementsByTagName(element, "fixed-partition");