1 Reply Latest reply on Jun 14, 2007 12:12 PM by sancheski

    How could I create a new Region programmatically?

    sancheski

      Hi

      I am trying to set an eviction policy to a region that does not exit yet. I know how to set an eviction policy to a region that already exists, but my problem comes up when I have to create a new region. How could I do it?

      I am getting the region manager instance and after seeing that the region I want to configure does not exist, I try to create a region using createRegion(Fqn fqn, EvictionPolicy policy, EvictionConfiguration config).

      Does anyone know how to do it?

      Thanks in advance

        • 1. Re: How could I create a new Region programmatically?
          sancheski

          I think I found the solution, perhaps it is gonna be usefull for someone.

          The code below could be used as an example:

          //getting the cache's eviction RegionManager
          RegionManager regionMgr = cache.getEvictionRegionManager();
          
          //Creating your own EvictionConfiguration
          FIFOConfiguration config = new FIFOConfiguration();
          ((FIFOConfiguration) config).setMaxNodes(10);
          
          //New instance of an EvictionPolicy
          FIFOEviction eviction = new FIFOPolicy();
          //Configure eviction policy in the cache instance
          eviction.configure(cache);
          //finally, create the region
          regionMgr.createRegion("/foo/com", eviction, config);
          
          


          What I was missing was the eviction configuration in the cache instance (eviction.configure(cache);) so I got a NullPointerException when the Timer threads did periodic node clean up by running the eviction policy.