GemFire 7.0.1

com.gemstone.gemfire.cache.partition
Interface PartitionListener

All Known Implementing Classes:
PartitionListenerAdapter

public interface PartitionListener

A callback for partitioned regions, invoked when a partition region is created or any bucket in a partitioned region becomes primary.

A sample implementation of this interface to colocate partition regions using a primary key without having to honor the redundancy contract for every colocate partition regions is as follows :

 public class ColocatingPartitionListener extends PartitionListenerAdapter
     implements 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()) {
       viewRegionNames.add(tokenizer.nextToken());
     }
   }
 
   public void afterRegionCreate(Region<?, ?> region) {
     cache = region.getCache();
   }
 }
 
A sample declaration of the ColocatingPartitionListener in cache.xml as follows :
 <partition-attributes redundant-copies="1">
     <partition-listener>
         <class-name>com.myCompany.ColocatingPartitionListener</class-name>
          <parameter name="viewRegions">
              <string>/customer/ViewA,/customer/ViewB</string>
          </parameter>             
     </partition-listener>
 </partition-attributes>
 

Since:
6.5
See Also:
Note : Please contact support@gemstone.com before using these APIs

Method Summary
 void afterBucketCreated(int bucketId, Iterable<?> keys)
          Callback invoked after a bucket has been created in a member (e.g. during rebalancing).
 void afterBucketRemoved(int bucketId, Iterable<?> keys)
          Callback invoked after a bucket has been removed from a member (e.g. during rebalancing).
 void afterPrimary(int bucketId)
          Callback invoked when any bucket in a partitioned region becomes primary
 void afterRegionCreate(Region<?,?> region)
          Callback invoked when a partition region is created
 

Method Detail

afterPrimary

void afterPrimary(int bucketId)
Callback invoked when any bucket in a partitioned region becomes primary

Parameters:
bucketId - id of the bucket which became primary
Since:
6.5

afterRegionCreate

void afterRegionCreate(Region<?,?> region)
Callback invoked when a partition region is created

Parameters:
region - handle of the region which is created
Since:
6.5

afterBucketRemoved

void afterBucketRemoved(int bucketId,
                        Iterable<?> keys)
Callback invoked after a bucket has been removed from a member (e.g. during rebalancing). This API is useful for maintaining external data structures by bucket id or key.

Parameters:
bucketId - id of the bucket removed
keys - keys in the bucket removed
Since:
6.6.1

afterBucketCreated

void afterBucketCreated(int bucketId,
                        Iterable<?> keys)
Callback invoked after a bucket has been created in a member (e.g. during rebalancing). This API is useful for maintaining external data structures by bucket id or key. Note that this API is invoked after the initial image has been completed so creates and destroys may occur in the keys. It is best to use this API during periods of no cache activity.

Parameters:
bucketId - id of the bucket created
keys - keys in the bucket created
Since:
6.6.1

GemFire 7.0.1

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