use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class AttributesFactory method setPartitionAttributes.
/**
* Sets the {@code PartitionAttributes} that describe how the region is partitioned among members
* of the distributed system. This also establishes a data policy of {@link DataPolicy#PARTITION
* PARTITION}, if the data policy has not already been set.
*
* @since GemFire 5.0
*/
public void setPartitionAttributes(PartitionAttributes partition) {
if (partition != null) {
if (!this.regionAttributes.hasDataPolicy()) {
this.regionAttributes.dataPolicy = PartitionedRegionHelper.DEFAULT_DATA_POLICY;
} else if (!PartitionedRegionHelper.ALLOWED_DATA_POLICIES.contains(this.regionAttributes.dataPolicy)) {
throw new IllegalStateException(LocalizedStrings.AttributesFactory_DATA_POLICY_0_IS_NOT_ALLOWED_FOR_A_PARTITIONED_REGION_DATAPOLICIES_OTHER_THAN_1_ARE_NOT_ALLOWED.toLocalizedString(new Object[] { this.regionAttributes.dataPolicy, PartitionedRegionHelper.ALLOWED_DATA_POLICIES }));
}
if (this.regionAttributes.hasPartitionAttributes() && this.regionAttributes.partitionAttributes instanceof PartitionAttributesImpl && partition instanceof PartitionAttributesImpl) {
// Make a copy and call merge on it to prevent bug 51616
PartitionAttributesImpl copy = ((PartitionAttributesImpl) this.regionAttributes.partitionAttributes).copy();
copy.merge((PartitionAttributesImpl) partition);
this.regionAttributes.partitionAttributes = copy;
} else {
this.regionAttributes.partitionAttributes = partition;
this.regionAttributes.setHasPartitionAttributes(true);
}
((PartitionAttributesImpl) this.regionAttributes.partitionAttributes).setOffHeap(this.regionAttributes.offHeap);
} else {
this.regionAttributes.partitionAttributes = null;
this.regionAttributes.setHasPartitionAttributes(false);
}
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for a <code>PartitionAttributes</code>
*/
private void generate(PartitionAttributes pa) throws SAXException {
AttributesImpl atts = new AttributesImpl();
if (generateDefaults() || pa.getRedundantCopies() != 0)
atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies()));
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault())
atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory()));
if (generateDefaults() || pa.getTotalMaxMemory() != PartitionAttributesFactory.GLOBAL_MAX_MEMORY_DEFAULT)
atts.addAttribute("", "", TOTAL_MAX_MEMORY, "", String.valueOf(pa.getTotalMaxMemory()));
if (generateDefaults() || pa.getTotalNumBuckets() != PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT)
atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
if (pa.getColocatedWith() != null)
atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith());
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay()));
if (generateDefaults() || pa.getStartupRecoveryDelay() != PartitionAttributesFactory.STARTUP_RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", STARTUP_RECOVERY_DELAY, "", String.valueOf(pa.getStartupRecoveryDelay()));
}
if (!generateDefaults() && atts.getLength() == 0 && pa.getPartitionResolver() == null && pa.getPartitionListeners().length == 0 && (pa.getFixedPartitionAttributes() == null || pa.getFixedPartitionAttributes().isEmpty())) {
return;
}
handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts);
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
PartitionResolver rr = pa.getPartitionResolver();
if (rr != null) {
generate(PARTITION_RESOLVER, rr);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) {
PartitionListener[] listeners = pa.getPartitionListeners();
for (int i = 0; i < listeners.length; i++) {
PartitionListener listener = listeners[i];
if (listener != null) {
generate(PARTITION_LISTENER, listener);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes();
if (staticAttrs != null) {
generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) {
Properties p = pa.getLocalProperties();
generate(p, LOCAL_PROPERTIES);
p = pa.getGlobalProperties();
generate(p, GLOBAL_PROPERTIES);
}
handler.endElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES);
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class CacheXmlParser method endPartitionProperites.
/**
* Process either the <code>local-properties</code> or <code>global-properties</code> for a
* {@link org.apache.geode.internal.cache.PartitionedRegion}
*
* @param globalOrLocal either the string {@link CacheXml#LOCAL_PROPERTIES} or
* {@link CacheXml#GLOBAL_PROPERTIES}
*/
private void endPartitionProperites(String globalOrLocal) {
Properties props = new Properties();
Object top = stack.pop();
while (!top.equals(globalOrLocal)) {
if (!(top instanceof Parameter)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_ONLY_A_PARAMETER_IS_ALLOWED_IN_THE_CONTEXT_OF_0.toLocalizedString(globalOrLocal));
}
Parameter param = (Parameter) top;
props.put(param.getName(), param.getValue());
top = stack.pop();
}
if (globalOrLocal.equals(GLOBAL_PROPERTIES)) {
PartitionAttributesImpl pai = peekPartitionAttributesImpl(GLOBAL_PROPERTIES);
pai.setGlobalProperties(props);
} else if (globalOrLocal.equals(LOCAL_PROPERTIES)) {
PartitionAttributesImpl pai = peekPartitionAttributesImpl(LOCAL_PROPERTIES);
pai.setLocalProperties(props);
} else {
Assert.assertTrue(false, "Argument globalOrLocal has unexpected value " + globalOrLocal);
}
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class RestAPIOnRegionFunctionExecutionDUnitTest method createPeerWithPR.
private boolean createPeerWithPR() {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
pa.setTotalNumBuckets(17);
raf.setPartitionAttributes(pa);
Region region = CacheFactory.getAnyInstance().createRegion(PR_REGION_NAME, raf.create());
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Region Created :" + region);
assertNotNull(region);
return Boolean.TRUE;
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class CacheXmlParser method startFixedPartitionAttributes.
/**
* When a <code>fixed-partition-attributes</code> element is encountered, we create an instance of
* FixedPartitionAttributesImpl and add it to the PartitionAttributesImpl stack.
*/
private void startFixedPartitionAttributes(Attributes atts) {
FixedPartitionAttributesImpl fpai = new FixedPartitionAttributesImpl();
String partitionName = atts.getValue(PARTITION_NAME);
if (partitionName != null) {
fpai.setPartitionName(partitionName);
}
String isPrimary = atts.getValue(IS_PRIMARY);
if (isPrimary != null) {
fpai.isPrimary(parseBoolean(isPrimary));
}
String numBuckets = atts.getValue(NUM_BUCKETS);
if (numBuckets != null) {
fpai.setNumBuckets(parseInt(numBuckets));
}
Object a = stack.peek();
if (a instanceof PartitionAttributesImpl) {
((PartitionAttributesImpl) a).addFixedPartitionAttributes(fpai);
}
}
Aggregations