Pivotal GemFire® v8.1

Managing Region Attributes

Managing Region Attributes

Use region attributes to fine-tune the region configuration provided by the region shortcut settings.

All region attributes have default settings, so you only need to use region attributes to set the ones you want to override. See <region-attributes>.

Define Region Attributes

Create region attributes using any of these methods:
  • Declarations inside the cache.xml <region> element:
       <region name="exampleRegion" refid="REPLICATE">
          <region-attributes statistics-enabled="true">
              <expiration-attributes timeout="10" action="destroy"/>

    When the cache.xml is loaded at startup, declared region attributes are automatically created and applied to the region.

  • RegionFactory API set* method calls:
    // Creating a partitioned region using the RegionFactory
    RegionFactory rf = cache.createRegionFactory(RegionShortcut.PARTITION);
    rf.addCacheListener(new LoggingCacheListener());
    custRegion = rf.create("customer");
    // Creating a partitioned region using the RegionFactory, with attribute modifications
    PartitionAttributesFactory paf = 
      new PartitionAttributesFactory<CustomerId, String>();
    paf.setPartitionResolver(new CustomerOrderResolver());
    RegionFactory rf = 
    rf.addCacheListener(new LoggingCacheListener());
    custRegion = rf.create("customer");
    // Creating a client with a Pool Specification Using ClientRegionFactory
    ClientRegionFactory<String,String> cRegionFactory = 
    Region<String, String> region = 
  • AttributesFactory API:
    1. Create an AttributesFactory instance
    2. Use the instance to set non-default attributes
    3. Run the factory create method to create a RegionAttributes instance
    4. Pass the RegionAttributes instance to the region create method:
    Cache cache = CacheFactory.create(system);
    AttributesFactory factory = new AttributesFactory();
    Region region = cache.createRegion("SampleRegion", factory.create());
    // Create a new region using another region's attributes
    AttributesFactory fac =
        new AttributesFactory(this.currRegion.getAttributes());
    Region nr = cache.createRegion(name, fac.create());
  • By issuing the gfsh create region command. See create region.
  • s

Modify Region Attributes

You can modify a region’s event handlers and expiration and eviction attributes after the region is created.
Note: Do not modify attributes for existing regions unless you have to. Creating the attributes you need at region creation is more efficient.
Modify attributes in one of these ways:
  • By loading a cache.xml with modified region attribute specifications:
    <!-- Change the listener for exampleRegion
        <region name="exampleRegion">
          <region-attributes statistics-enabled="true">
  • Using the AttributesMutator API:
    1. Retrieve the AttributesMutator from the region
    2. Call the mutator set methods to modify attributes:
    currRegion = cache.getRegion("root");
    AttributesMutator mutator = this.currRegion.getAttributesMutator();
    mutator.addCacheListener(new LoggingCacheListener()); 
  • By issuing the gfsh alter region command. See alter region.