org.apache.geode.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 is created/deleted or any bucket in a partitioned region becomes primary.
  It is highly recommended that implementations of this listener should be quick and not try to manipulate regions and data because the the callbacks are invoked while holding locks that may block region operations.

       package com.myCompany.MyPartitionListener;

       public class MyPartitionListener extends PartitionListenerAdapter implements Declarable {
         private String regionName;

         public MyPartitionListener() {}

         public void afterPrimary(int bucketId) {
           System.out.println("bucket:" + bucketId + " has become primary on " + this.regionName);
         }

         public void afterRegionCreate(Region<?, ?> region) {
           this.regionName = region.getName();
         }
       }

  A sample declaration of the MyPartitionListener in cache.xml as follows :

       <partition-attributes redundant-copies="1">
           <partition-listener>
               <class-name>com.myCompany.MyPartitionListener</class-name>
           </partition-listener>
       </partition-attributes>

  Since:
    GemFire 6.5
  See Also:
    `PartitionAttributesFactory.addPartitionListener(PartitionListener)`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterBucketCreated(int bucketId, java.lang.Iterable<?> keys)` Callback invoked after a bucket has been created in a member (e.g.
    `void` | `afterBucketRemoved(int bucketId, java.lang.Iterable<?> keys)` Callback invoked after a bucket has been removed from a member (e.g.
    `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
    `default void` | `afterSecondary(int bucketId)` Callback invoked when any bucket in a partitioned region stops being primary

- - ### 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:
        GemFire 6.5

    - #### afterSecondary

          default void afterSecondary(int bucketId)

      Callback invoked when any bucket in a partitioned region stops being primary
      Parameters:
        `bucketId` - id of the bucket which stopped being primary
      Since:
        Geode 1.1

    - #### afterRegionCreate

          void afterRegionCreate(Region<?,?> region)

      Callback invoked when a partition region is created
      Parameters:
        `region` - handle of the region which is created
      Since:
        GemFire 6.5

    - #### afterBucketRemoved

          void afterBucketRemoved(int bucketId,
                                  java.lang.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:
        GemFire 6.6.1

    - #### afterBucketCreated

          void afterBucketCreated(int bucketId,
                                  java.lang.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:
        GemFire 6.6.1