Apache Geode CHANGELOG

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:

    <cache>
       <region name="exampleRegion" refid="REPLICATE">
          <region-attributes statistics-enabled="true">
            <entry-idle-time>
              <expiration-attributes timeout="10" action="destroy"/>
            </entry-idle-time>
            <cache-listener>
              <class-name>quickstart.SimpleCacheListener</class-name>
            </cache-listener>
          </region-attributes>
        </region>
    </cache>
    

    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
    RegionFactory rf = 
      cache.createRegionFactory(RegionShortcut.PARTITION);
    rf.setPartitionResolver(new CustomerOrderResolver());
    rf.addCacheListener(new LoggingCacheListener());
    custRegion = rf.create("customer");
    
    // Creating a client with a Pool Specification Using ClientRegionFactory
    ClientRegionFactory<String,String> cRegionFactory = 
        cache.createClientRegionFactory(PROXY);
    Region<String, String> region = 
        cRegionFactory.setPoolName("Pool3").create("DATA");
    
  • By issuing the gfsh create region command.

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 absolutely necessary. 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">
            <cache-listener>
              <class-name>quickstart.ComplicatedCacheListener</class-name>
            </cache-listener>
          </region-attributes>
        </region>
    ... 
    
  • 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.