GemFire 7.0.1

Class PartitionManager

  extended by com.gemstone.gemfire.cache.partition.PartitionManager

public final class PartitionManager
extends Object

An utility class to manage partitions (aka buckets) on a Partitioned Region without requiring data (e.g. keys). Note : Please contact before using these APIs.
This is an example of how this API can be used to create a view region with redundancy 0, which is colocated with another region of redundancy 1, without using the standard gemfire colocated-with attribute, which only supports colocated regions with the same redundancy level. Note that when using this API, the data in the view region is discarded every time a primary moves.

 public class ColocatingPartitionListener implements PartitionListener,
     Declarable {
   private Cache cache;
   private List<String> viewRegionNames = new ArrayList<String>();
   public ColocatingPartitionListener() {
   public void afterPrimary(int bucketId) { 
     for (String viewRegionName : viewRegionNames) {
       Region viewRegion = cache.getRegion(viewRegionName);
       PartitionManager.createPrimaryBucket(viewRegion, bucketId, true, true);
   public void init(Properties props) {
     String viewRegions = props.getProperty("viewRegions");
     StringTokenizer tokenizer = new StringTokenizer(viewRegions, ",");
     while (tokenizer.hasMoreTokens()) {
   public void afterRegionCreate(Region<?, ?> region) {
     cache = region.getCache();
In the declaration of the parent region in cache.xml, install the ColocatedPartitionListener as follows :
 <partition-attributes redundant-copies="1">
          <parameter name="viewRegions">
If the regions needs to be rebalanced, use the RebalanceFactory.excludeRegions(Set) method to exclude the view regions.


Method Summary
static boolean createPrimaryBucket(Region<?,?> region, int bucketId, boolean destroyExistingRemote, boolean destroyExistingLocal)
          This method creates a copy of the bucket on the current node, if no copy already exists.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static boolean createPrimaryBucket(Region<?,?> region,
                                          int bucketId,
                                          boolean destroyExistingRemote,
                                          boolean destroyExistingLocal)
This method creates a copy of the bucket on the current node, if no copy already exists. Depending on the values of destroyExistingLocal and destroyExistingRemote, it will first destroy the existing primary copy of the bucket. This behavior of this method is undefined on partitioned regions with redundancy greater than 0. The behavior is also undefined for partitioned regions colocated with the colocated-with attribute. This method creates primary bucket in the following way:

If the partitioned region does not have a primary bucket for the bucketId, it creates a primary bucket on the member and returns true.

If the partitioned region does have a primary bucket for the bucketId on the member :
a) If destroyExistingLocal passed is true, it destroys the existing bucket, and then creates a new primary bucket and returns true.
b) If destroyExistingLocal passed is false, it does nothing and returns false.

If the partitioned region does have a primary bucket for the bucketId on remote members :
a) If destroyExistingRemote passed is true, it destroys the existing bucket on remote member, and then creates a new primary bucket on this member and returns true.
b) If destroyExistingRemote passed is false, it throws IllegalStateException.

region - the partitioned region on which to create the bucket
bucketId - the identifier of the bucket to create
destroyExistingRemote - whether to destroy the remote bucket if it exists
destroyExistingLocal - whether to destroy the local bucket if it exists
true when the bucket has been created otherwise false
IllegalArgumentException - if the provided region is not a partitioned region
IllegalArgumentException - if the provided bucketId is less than zero or greater than or equal to the partitioned region's total number of buckets
IllegalStateException - if the partitioned region has the primary bucket for the bucket id on a remote member and the destroyExistingRemote parameter provided is false

GemFire 7.0.1

Copyright © 1997-2013 VMware, Inc. All rights reserved.