GemFire 6.5

com.gemstone.gemfire.cache.partition
Class PartitionRegionHelper

java.lang.Object
  extended by com.gemstone.gemfire.cache.partition.PartitionRegionHelper

public final class PartitionRegionHelper
extends Object

Utility methods for handling partitioned Regions, for example during execution of Functions on a Partitioned Region.

Example of a Function using utility methods:

  public Serializable execute(FunctionContext context) {
     if (context instanceof RegionFunctionContext) {
         RegionFunctionContext rc = (RegionFunctionContext) context;
         if (PartitionRegionHelper.isPartitionedRegion(rc.getDataSet())) {
             Region efficientReader =
              PartitionRegionHelper.getLocalDataForContext(rc);
             efficientReader.get("someKey");
             // ...
         }
      }
  // ...
 

Since:
6.0
See Also:
FunctionService.onRegion(Region)

Method Summary
static void assignBucketsToPartitions(Region<?,?> region)
          Decide which partitions will host which buckets.
static
<K,V> Set<DistributedMember>
getAllMembersForKey(Region<K,V> r, K key)
          Get all potential owners for a key.
static Map<String,Region<?,?>> getColocatedRegions(Region<?,?> r)
          Given a partitioned Region, return a map of colocated Regions.
static Map<String,Region<?,?>> getLocalColocatedRegions(RegionFunctionContext c)
          Given a RegionFunctionContext for a partitioned Region, return a map of colocated Regions with read access limited to the context of the function.
static
<K,V> Region<K,V>
getLocalData(Region<K,V> r)
          Given a partitioned Region return a Region providing read access limited to the local heap, writes using this Region have no constraints and behave the same as a partitioned Region.
static
<K,V> Region<K,V>
getLocalDataForContext(RegionFunctionContext c)
          Given a RegionFunctionContext for a partitioned Region, return a Region providing read access limited to the function context.
static
<K,V> Region<K,V>
getLocalPrimaryData(Region<K,V> r)
          Given a partitioned Region return a Region providing read access to primary copy of the data which is limited to the local heap, writes using this Region have no constraints and behave the same as a partitioned Region.
static Set<PartitionRegionInfo> getPartitionRegionInfo(Cache cache)
          Gathers a set of details about all partitioned regions in the local Cache.
static PartitionRegionInfo getPartitionRegionInfo(Region<?,?> region)
          Gathers details about the specified partitioned region.
static
<K,V> DistributedMember
getPrimaryMemberForKey(Region<K,V> r, K key)
          Get the current primary owner for a key.
static
<K,V> Set<DistributedMember>
getRedundantMembersForKey(Region<K,V> r, K key)
          Get all potential redundant owners for a key.
static boolean isPartitionedRegion(Region<?,?> r)
          Test a Region to see if it is a partitioned Region
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getColocatedRegions

public static Map<String,Region<?,?>> getColocatedRegions(Region<?,?> r)
Given a partitioned Region, return a map of colocated Regions. Given a local data reference to a partitioned region, return a map of local colocated Regions. If there are no colocated regions, return an empty map.

Parameters:
r - a partitioned Region
Returns:
an unmodifiable map of region name to Region
Throws:
IllegalStateException - if the Region is not a partitioned Region
Since:
6.0

isPartitionedRegion

public static boolean isPartitionedRegion(Region<?,?> r)
Test a Region to see if it is a partitioned Region

Parameters:
r -
Returns:
true if it is a partitioned Region
Since:
6.0

getPartitionRegionInfo

public static Set<PartitionRegionInfo> getPartitionRegionInfo(Cache cache)
Gathers a set of details about all partitioned regions in the local Cache. If there are no partitioned regions then an empty set will be returned.

Parameters:
cache - the cache which has the regions
Returns:
set of details about all locally defined partitioned regions
Since:
6.0

getPartitionRegionInfo

public static PartitionRegionInfo getPartitionRegionInfo(Region<?,?> region)
Gathers details about the specified partitioned region. Returns null if the partitioned region is not locally defined.

Parameters:
region - the region to get info about
Returns:
details about the specified partitioned region
Since:
6.0

assignBucketsToPartitions

public static void assignBucketsToPartitions(Region<?,?> region)
Decide which partitions will host which buckets. Gemfire normally assigns buckets to partitions as needed when data is added to a partitioned region. This method provides way to assign all of the buckets without putting any data in partition region. This method should not be called until all of the partitions are running because it will divide the buckets between the running partitions. If the buckets are already assigned this method will have no effect. This method will block until all buckets are assigned.

Parameters:
region - The region which should have it's buckets assigned.
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.0

getPrimaryMemberForKey

public static <K,V> DistributedMember getPrimaryMemberForKey(Region<K,V> r,
                                                             K key)
Get the current primary owner for a key. Upon return there is no guarantee that primary owner remains the primary owner, or that the member is still alive.

This method is not a substitute for Region.containsKey(Object).

Parameters:
r - a PartitionedRegion
key - the key to evaluate
Returns:
the primary member for the key, possibly null if a primary is not yet determined
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.0

getRedundantMembersForKey

public static <K,V> Set<DistributedMember> getRedundantMembersForKey(Region<K,V> r,
                                                                     K key)
Get all potential redundant owners for a key. If the key exists in the Region, upon return there is no guarantee that key has not been moved or that the members are still alive.

This method is not a substitute for Region.containsKey(Object).

This method is equivalent to: DistributedMember primary = getPrimaryMemberForKey(r, key); Set allMembers = getAllMembersForKey(r, key); allMembers.remove(primary);

Parameters:
r - a PartitionedRegion
key - the key to evaluate
Returns:
an unmodifiable set of members minus the primary
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.0

getAllMembersForKey

public static <K,V> Set<DistributedMember> getAllMembersForKey(Region<K,V> r,
                                                               K key)
Get all potential owners for a key. If the key exists in the Region, upon return there is no guarantee that it has not moved nor does it guarantee all members are still alive.

This method is not a substitute for Region.containsKey(Object).

Parameters:
r - PartitionedRegion
key - the key to evaluate
Returns:
an unmodifiable set of all members
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.0

getLocalColocatedRegions

public static Map<String,Region<?,?>> getLocalColocatedRegions(RegionFunctionContext c)
Given a RegionFunctionContext for a partitioned Region, return a map of colocated Regions with read access limited to the context of the function.

Writes using these Region have no constraints and behave the same as a partitioned Region.

If there are no colocated regions, return an empty map.

Parameters:
c - the region function context
Returns:
an unmodifiable map of region name to Region
Throws:
IllegalStateException - if the Region is not a partitioned Region
Since:
6.0

getLocalDataForContext

public static <K,V> Region<K,V> getLocalDataForContext(RegionFunctionContext c)
Given a RegionFunctionContext for a partitioned Region, return a Region providing read access limited to the function context.
Returned Region provides only one copy of the data although redundantCopies configured is more than 0. If the invoking Function is configured to have optimizeForWrite as true,the returned Region will only contain primary copy of the data.

Writes using this Region have no constraints and behave the same as a partitioned Region.

Parameters:
c - a functions context
Returns:
a Region for efficient reads
Throws:
IllegalStateException - if RegionFunctionContext.getDataSet() returns something other than a partitioned Region
Since:
6.0

getLocalData

public static <K,V> Region<K,V> getLocalData(Region<K,V> r)
Given a partitioned Region return a Region providing read access limited to the local heap, writes using this Region have no constraints and behave the same as a partitioned Region.

Parameters:
r - a partitioned region
Returns:
a Region for efficient reads
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.0

getLocalPrimaryData

public static <K,V> Region<K,V> getLocalPrimaryData(Region<K,V> r)
Given a partitioned Region return a Region providing read access to primary copy of the data which is limited to the local heap, writes using this Region have no constraints and behave the same as a partitioned Region.

Parameters:
r - a partitioned region
Returns:
a Region for efficient reads
Throws:
IllegalStateException - if the provided region is something other than a partitioned Region
Since:
6.5

GemFire 6.5

Copyright © 2002-2010 GemStone Systems, Inc. All Rights Reserved.