public final class PartitionManager extends Object
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()) {
viewRegionNames.add(tokenizer.nextToken());
}
}
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">
<partition-listener>
<class-name>com.myCompany.ColocatingPartitionListener</class-name>
<parameter name="viewRegions">
<string>/customer/ViewA,/customer/ViewB</string>
</parameter>
</partition-listener>
</partition-attributes>
If the regions needs to be rebalanced, use the RebalanceFactory.excludeRegions(Set)
method to exclude the view regions.| Modifier and Type | Method and Description |
|---|---|
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.
|
public static boolean createPrimaryBucket(Region<?,?> region, int bucketId, boolean destroyExistingRemote, boolean destroyExistingLocal)
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 bucketbucketId - the identifier of the bucket to createdestroyExistingRemote - whether to destroy the remote bucket if it existsdestroyExistingLocal - whether to destroy the local bucket if it existsIllegalArgumentException - if the provided region is not a partitioned regionIllegalArgumentException - if the provided bucketId is less than zero or greater than or
equal to the partitioned region's total number of bucketsIllegalStateException - if the partitioned region has the primary bucket for the bucket
id on a remote member and the destroyExistingRemote parameter
provided is falseCopyright © 1997-2017 Pivotal Software, Inc. All rights reserved.