SGF-735 - RegionAttributes.offHeap is improperly overridden by RegionFactoryBean.offHeap.
This commit is contained in:
@@ -28,9 +28,10 @@ public class PartitionedRegionFactoryBean<K, V> extends RegionFactoryBean<K, V>
|
||||
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) {
|
||||
|
||||
// First, verify the GemFire version is 6.5 or Higher when Persistence is specified...
|
||||
Assert.isTrue(!DataPolicy.PERSISTENT_PARTITION.equals(dataPolicy) || GemfireUtils.isGemfireVersion65OrAbove(),
|
||||
String.format("Persistent PARTITION Regions can only be used from GemFire 6.5 onwards; current version is [%1$s].",
|
||||
String.format("Persistent PARTITION Regions can only be used from GemFire 6.5 onwards; current version is [%s].",
|
||||
CacheFactory.getVersion()));
|
||||
|
||||
if (dataPolicy == null) {
|
||||
@@ -52,6 +53,7 @@ public class PartitionedRegionFactoryBean<K, V> extends RegionFactoryBean<K, V>
|
||||
|
||||
@Override
|
||||
protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, String dataPolicy) {
|
||||
|
||||
DataPolicy resolvedDataPolicy = null;
|
||||
|
||||
if (dataPolicy != null) {
|
||||
@@ -61,5 +63,4 @@ public class PartitionedRegionFactoryBean<K, V> extends RegionFactoryBean<K, V>
|
||||
|
||||
resolveDataPolicy(regionFactory, persistent, resolvedDataPolicy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RegionAttributesFactoryBean extends AttributesFactory
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setIndexUpdateType(final IndexMaintenancePolicyType indexUpdateType) {
|
||||
public void setIndexUpdateType(IndexMaintenancePolicyType indexUpdateType) {
|
||||
indexUpdateType.setIndexMaintenance(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ public abstract class RegionFactoryBean<K, V> extends RegionLookupFactoryBean<K,
|
||||
*/
|
||||
protected RegionFactory<K, V> postProcess(RegionFactory<K, V> regionFactory) {
|
||||
|
||||
regionFactory.setOffHeap(Boolean.TRUE.equals(this.offHeap));
|
||||
Optional.ofNullable(this.offHeap).ifPresent(regionFactory::setOffHeap);
|
||||
|
||||
return regionFactory;
|
||||
}
|
||||
|
||||
@@ -91,11 +91,9 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
doParseRegion(element, parserContext, builder, isSubRegion(element));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected abstract void doParseRegion(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, boolean subRegion);
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void doParseRegionConfiguration(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder, boolean subRegion) {
|
||||
|
||||
@@ -156,7 +154,6 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
void mergeRegionTemplateAttributes(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder) {
|
||||
|
||||
@@ -164,6 +161,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
if (StringUtils.hasText(regionTemplateName)) {
|
||||
if (parserContext.getRegistry().containsBeanDefinition(regionTemplateName)) {
|
||||
|
||||
BeanDefinition templateRegion = parserContext.getRegistry().getBeanDefinition(regionTemplateName);
|
||||
|
||||
BeanDefinition templateRegionAttributes = getRegionAttributesBeanDefinition(templateRegion);
|
||||
@@ -183,8 +181,8 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
BeanDefinition getRegionAttributesBeanDefinition(BeanDefinition region) {
|
||||
|
||||
Assert.notNull(region, "BeanDefinition must not be null");
|
||||
|
||||
Object regionAttributes = null;
|
||||
@@ -197,14 +195,14 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return (regionAttributes instanceof BeanDefinition ? (BeanDefinition) regionAttributes : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void parseCollectionOfCustomSubElements(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder, String className, String subElementName, String propertyName) {
|
||||
|
||||
List<Element> subElements = DomUtils.getChildElementsByTagName(
|
||||
element, subElementName, subElementName + "-ref");
|
||||
List<Element> subElements =
|
||||
DomUtils.getChildElementsByTagName(element, subElementName, subElementName + "-ref");
|
||||
|
||||
if (!CollectionUtils.isEmpty(subElements)) {
|
||||
|
||||
ManagedArray array = new ManagedArray(className, subElements.size());
|
||||
|
||||
for (Element subElement : subElements) {
|
||||
@@ -215,9 +213,9 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void parseSubRegions(Element element, ParserContext parserContext, String resolvedCacheRef) {
|
||||
Map<String, Element> allSubRegionElements = new HashMap<String, Element>();
|
||||
|
||||
Map<String, Element> allSubRegionElements = new HashMap<>();
|
||||
|
||||
findSubRegionElements(element, getRegionNameFromElement(element), allSubRegionElements);
|
||||
|
||||
@@ -228,30 +226,36 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void findSubRegionElements(Element parent, String parentPath, Map<String, Element> allSubRegionElements) {
|
||||
|
||||
for (Element element : DomUtils.getChildElements(parent)) {
|
||||
if (element.getLocalName().endsWith("region")) {
|
||||
|
||||
String subRegionName = getRegionNameFromElement(element);
|
||||
String subRegionPath = buildSubRegionPath(parentPath, subRegionName);
|
||||
|
||||
allSubRegionElements.put(subRegionPath, element);
|
||||
|
||||
findSubRegionElements(element, subRegionPath, allSubRegionElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String getRegionNameFromElement(Element element) {
|
||||
|
||||
String name = element.getAttribute(NAME_ATTRIBUTE);
|
||||
|
||||
return (StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String buildSubRegionPath(String parentName, String regionName) {
|
||||
|
||||
String regionPath = StringUtils.arrayToDelimitedString(new String[] { parentName, regionName }, "/");
|
||||
|
||||
if (!regionPath.startsWith("/")) {
|
||||
regionPath = "/" + regionPath;
|
||||
}
|
||||
|
||||
return regionPath;
|
||||
}
|
||||
|
||||
@@ -276,16 +280,21 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private String getParentRegionPathFrom(String regionPath) {
|
||||
|
||||
int index = regionPath.lastIndexOf("/");
|
||||
|
||||
String parentPath = regionPath.substring(0, index);
|
||||
|
||||
if (parentPath.lastIndexOf("/") == 0) {
|
||||
parentPath = parentPath.substring(1);
|
||||
}
|
||||
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void validateDataPolicyShortcutAttributesMutualExclusion(Element element, ParserContext parserContext) {
|
||||
|
||||
if (element.hasAttribute("data-policy") && element.hasAttribute("shortcut")) {
|
||||
parserContext.getReaderContext().error(String.format(
|
||||
"Only one of [data-policy, shortcut] may be specified with element '%1$s'.", element.getTagName()),
|
||||
|
||||
@@ -63,15 +63,15 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
|
||||
validateDataPolicyShortcutAttributesMutualExclusion(element, parserContext);
|
||||
|
||||
BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
RegionAttributesFactoryBean.class);
|
||||
BeanDefinitionBuilder regionAttributesBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class);
|
||||
|
||||
doParseRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion);
|
||||
|
||||
regionBuilder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition());
|
||||
|
||||
BeanDefinitionBuilder partitionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
PartitionAttributesFactoryBean.class);
|
||||
BeanDefinitionBuilder partitionAttributesBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(PartitionAttributesFactoryBean.class);
|
||||
|
||||
mergeTemplateRegionPartitionAttributes(element, parserContext, regionBuilder, partitionAttributesBuilder);
|
||||
|
||||
@@ -83,13 +83,6 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-buckets", "totalNumBuckets");
|
||||
ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-max-memory");
|
||||
|
||||
Element partitionResolverSubElement = DomUtils.getChildElementByTagName(element, "partition-resolver");
|
||||
|
||||
if (partitionResolverSubElement != null) {
|
||||
partitionAttributesBuilder.addPropertyValue("partitionResolver",
|
||||
parsePartitionResolver(partitionResolverSubElement, parserContext, regionBuilder));
|
||||
}
|
||||
|
||||
Element partitionListenerSubElement = DomUtils.getChildElementByTagName(element, "partition-listener");
|
||||
|
||||
if (partitionListenerSubElement != null) {
|
||||
@@ -97,18 +90,29 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
parsePartitionListeners(partitionListenerSubElement, parserContext, regionBuilder));
|
||||
}
|
||||
|
||||
Element partitionResolverSubElement = DomUtils.getChildElementByTagName(element, "partition-resolver");
|
||||
|
||||
if (partitionResolverSubElement != null) {
|
||||
partitionAttributesBuilder.addPropertyValue("partitionResolver",
|
||||
parsePartitionResolver(partitionResolverSubElement, parserContext, regionBuilder));
|
||||
}
|
||||
|
||||
List<Element> fixedPartitionSubElements = DomUtils.getChildElementsByTagName(element, "fixed-partition");
|
||||
|
||||
if (!CollectionUtils.isEmpty(fixedPartitionSubElements)){
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ManagedList fixedPartitionAttributes = new ManagedList();
|
||||
|
||||
for (Element fixedPartition : fixedPartitionSubElements) {
|
||||
BeanDefinitionBuilder fixedPartitionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
FixedPartitionAttributesFactoryBean.class);
|
||||
|
||||
BeanDefinitionBuilder fixedPartitionAttributesBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(FixedPartitionAttributesFactoryBean.class);
|
||||
|
||||
ParsingUtils.setPropertyValue(fixedPartition, fixedPartitionAttributesBuilder, "partition-name");
|
||||
ParsingUtils.setPropertyValue(fixedPartition, fixedPartitionAttributesBuilder, "num-buckets");
|
||||
ParsingUtils.setPropertyValue(fixedPartition, fixedPartitionAttributesBuilder, "primary");
|
||||
|
||||
fixedPartitionAttributes.add(fixedPartitionAttributesBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
@@ -126,20 +130,22 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
|
||||
if (StringUtils.hasText(regionTemplateName)) {
|
||||
if (parserContext.getRegistry().containsBeanDefinition(regionTemplateName)) {
|
||||
|
||||
BeanDefinition templateRegion = parserContext.getRegistry().getBeanDefinition(regionTemplateName);
|
||||
|
||||
BeanDefinition templateRegionAttributes = getRegionAttributesBeanDefinition(templateRegion);
|
||||
|
||||
if (templateRegionAttributes != null) {
|
||||
if (templateRegionAttributes.getPropertyValues().contains("partitionAttributes")) {
|
||||
|
||||
PropertyValue partitionAttributesProperty = templateRegionAttributes.getPropertyValues()
|
||||
.getPropertyValue("partitionAttributes");
|
||||
|
||||
Object partitionAttributes = partitionAttributesProperty.getValue();
|
||||
|
||||
if (partitionAttributes instanceof BeanDefinition) {
|
||||
partitionAttributesBuilder.getRawBeanDefinition().overrideFrom(
|
||||
(BeanDefinition) partitionAttributes);
|
||||
partitionAttributesBuilder.getRawBeanDefinition()
|
||||
.overrideFrom((BeanDefinition) partitionAttributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,6 +161,7 @@ class PartitionedRegionParser extends AbstractRegionParser {
|
||||
/* (non-Javadoc) */
|
||||
private void parseColocatedWith(Element element, BeanDefinitionBuilder regionBuilder,
|
||||
BeanDefinitionBuilder partitionAttributesBuilder, String attributeName) {
|
||||
|
||||
// NOTE rather than using a dependency (with depends-on) we could also set the colocatedWith property of the
|
||||
// PartitionAttributesFactoryBean with a reference to the Region "this" Partitioned Region will be colocated
|
||||
// with, where the colocated-with attribute refers to the the bean name/alias of the other, depended on Region
|
||||
|
||||
Reference in New Issue
Block a user