diff --git a/src/main/java/org/springframework/data/gemfire/PartitionAttributesFactoryBean.java b/src/main/java/org/springframework/data/gemfire/PartitionAttributesFactoryBean.java index d294e47a..9ec74b56 100644 --- a/src/main/java/org/springframework/data/gemfire/PartitionAttributesFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/PartitionAttributesFactoryBean.java @@ -16,71 +16,88 @@ package org.springframework.data.gemfire; +import java.util.List; + import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; import com.gemstone.gemfire.cache.PartitionAttributes; 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 */ -@SuppressWarnings("unchecked") -public class PartitionAttributesFactoryBean implements FactoryBean { +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class PartitionAttributesFactoryBean implements FactoryBean, InitializingBean { - private com.gemstone.gemfire.cache.PartitionAttributesFactory paf = new com.gemstone.gemfire.cache.PartitionAttributesFactory(); + private final com.gemstone.gemfire.cache.PartitionAttributesFactory paf = new com.gemstone.gemfire.cache.PartitionAttributesFactory(); + private List listeners; + + @Override public PartitionAttributes getObject() throws Exception { return paf.create(); } + @Override public Class getObjectType() { return PartitionAttributes.class; } + @Override public boolean isSingleton() { return false; } - public void setColocatedWith(String colocatedRegionFullPath) { paf.setColocatedWith(colocatedRegionFullPath); } - public void setLocalMaxMemory(int mb) { paf.setLocalMaxMemory(mb); } - public void setPartitionResolver(PartitionResolver resolver) { paf.setPartitionResolver(resolver); } + public void setPartitionListeners(List listeners) { + this.listeners = listeners; + } public void setRecoveryDelay(long recoveryDelay) { paf.setRecoveryDelay(recoveryDelay); } - public void setRedundantCopies(int redundantCopies) { paf.setRedundantCopies(redundantCopies); } - public void setStartupRecoveryDelay(long startupRecoveryDelay) { paf.setStartupRecoveryDelay(startupRecoveryDelay); } - public void setTotalMaxMemory(long mb) { paf.setTotalMaxMemory(mb); } - public void setTotalNumBuckets(int numBuckets) { paf.setTotalNumBuckets(numBuckets); } + + @Override + public void afterPropertiesSet() throws Exception { + if (listeners != null) { + for (PartitionListener listener : listeners) { + paf.addPartitionListener(listener); + } + } + + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java index 65bdec6d..6066f245 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java @@ -16,8 +16,6 @@ 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.PartitionAttributesFactoryBean; @@ -93,13 +91,20 @@ class PartitionedRegionParser extends AbstractRegionParser { parAttrBuilder.addPropertyValue("totalNumBuckets", Integer.valueOf(attr)); } // - List subElements = DomUtils.getChildElementsByTagName(element, "partition-resolver"); - // - // // parse nested cache-listener elements - for (Element subElement : subElements) { + Element subElement = DomUtils.getChildElementByTagName(element, "partition-resolver"); + // parse nested partition resolver element + if (subElement != null) { parAttrBuilder.addPropertyValue("partitionResolver", parsePartitionResolver(parserContext, subElement, builder)); } + + subElement = DomUtils.getChildElementByTagName(element, "partition-listener"); + // parse nested partition resolver element + if (subElement != null) { + parAttrBuilder.addPropertyValue("partitionListeners", + parsePartitionListeners(parserContext, subElement, builder)); + } + // // // add partition attributes attributes attrBuilder.addPropertyValue("partitionAttributes", parAttrBuilder.getBeanDefinition()); @@ -110,6 +115,11 @@ class PartitionedRegionParser extends AbstractRegionParser { } private Object parsePartitionResolver(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, subElement, builder); + } + + private Object parsePartitionListeners(ParserContext parserContext, Element subElement, + BeanDefinitionBuilder builder) { return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } } \ No newline at end of file diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd index cf137950..bf5178ed 100755 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd @@ -1106,6 +1106,22 @@ colocate data based on custom criterias (such as colocating trades by month and + + + + + + + + + + diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java index 66d26cc4..519dc5fe 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -18,6 +18,7 @@ package org.springframework.data.gemfire.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -35,7 +36,9 @@ import org.springframework.util.ObjectUtils; import com.gemstone.gemfire.cache.CacheListener; import com.gemstone.gemfire.cache.PartitionAttributes; +import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.partition.PartitionListener; /** * @author Costin Leau @@ -90,7 +93,38 @@ public class PartitionedRegionNamespaceTest { RegionAttributes attrs = TestUtils.readField("attributes", fb); PartitionAttributes pAttr = attrs.getPartitionAttributes(); - assertEquals(20, pAttr.getLocalMaxMemory()); + + assertNotNull(pAttr.getPartitionListeners()); + assertEquals(1, pAttr.getPartitionListeners().length); + assertTrue(pAttr.getPartitionListeners()[0] instanceof TestPartitionListener); + } + + public static class TestPartitionListener implements PartitionListener { + + @Override + public void afterBucketCreated(int arg0, Iterable arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void afterBucketRemoved(int arg0, Iterable arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void afterPrimary(int arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void afterRegionCreate(Region arg0) { + // TODO Auto-generated method stub + + } + } } \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml index c2a2a803..00a0bf8d 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml @@ -25,6 +25,9 @@ + + +