1 Reply Latest reply on Nov 16, 2012 2:45 AM by Thomas Hofmann

    Using ExpirationAlgorithm in EvictionConfig not working in JBoss 5.1

    Thomas Hofmann Newbie

      I'm using JBoss Cache Malagueta 3.2.5.GA in JBoss 5.1. There is a cache configuration without any eviction config:

      <entry><key>prodb-expiration-cache</key>

         <value>

           <bean name="ProDBExpirationCacheConfig" class="org.jboss.cache.config.Configuration">

               <property name="transactionManagerLookupClass">org.jboss.cache.transaction.JBossTransactionManagerLookup</property>

               <property name="clusterName">${jboss.partition.name:DefaultPartition}-ProDBExpirationCache</property>

               <property name="multiplexerStack">${jboss.default.jgroups.stack:udp}</property>

               <property name="fetchInMemoryState">true</property>

               <property name="nodeLockingScheme">MVCC</property>

               <property name="isolationLevel">REPEATABLE_READ</property>

               <property name="useLockStriping">false</property>

               <property name="cacheMode">REPL_SYNC</property>

               <property name="syncReplTimeout">17500</property>

               <property name="lockAcquisitionTimeout">15000</property>

               <property name="stateRetrievalTimeout">60000</property>

               <property name="exposeManagementStatistics">true</property>

           </bean>

        </value>

      </entry>

       

       

      The eviction is configured dynamically, and following entries are put into the cache: Key_1=value_1, Key_2=value_2,Key_3=value_3

       

       

      CacheManager cacheManager = com.bspartners.util.ServiceLocator.getCacheManager();

      Cache expirationCache = cacheManager.getCache("prodb-expiration-cache", true);

       

      Node rootNode = expirationCache.getRoot();

      Fqn cacheFqn = Fqn.fromString("/OTTO");

      Region region = expirationCache.getRegion(cacheFqn, true);

      ExpirationAlgorithmConfig expirationAlgorithmConfig = new ExpirationAlgorithmConfig();

      expirationAlgorithmConfig.setExpirationKeyName(ExpirationAlgorithmConfig.EXPIRATION_KEY);

      EvictionRegionConfig erc = new EvictionRegionConfig(cacheFqn, expirationAlgorithmConfig);

      region.setEvictionRegionConfig(erc);

      EvictionConfig evictionConfig = new EvictionConfig();

      List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();

      ercs.add(erc);

      evictionConfig.setEvictionRegionConfigs(ercs);

      evictionConfig.setWakeupInterval(500);

      expirationCache.getConfiguration().setEvictionConfig(evictionConfig);

       

      Node cacheNode = rootNode.getChild(cacheFqn);

      Long future = new Long(System.currentTimeMillis() + 10000);

       

      // put value into cache

      Fqn keyFqn = Fqn.fromElements("key_1");

      cacheNode.addChild(keyFqn).put(ExpirationAlgorithmConfig.EXPIRATION_KEY, future);

      cacheNode.getChild(keyFqn).put("key_1", "value_1");

      keyFqn = Fqn.fromElements("key_2");

      cacheNode.addChild(keyFqn).put(ExpirationAlgorithmConfig.EXPIRATION_KEY, future);

      cacheNode.getChild(keyFqn).put("key_2", "value_2");

      keyFqn = Fqn.fromElements("key_3");

      cacheNode.addChild(keyFqn).put(ExpirationAlgorithmConfig.EXPIRATION_KEY, future);

      cacheNode.getChild(keyFqn).put("key_3", "value_3");

       

      Thread.sleep(15000);

       

      // get value from cache -> should be evicted because value is expired!

      Object value = rootNode.getChild(cacheFqn).getChild(Fqn.fromElements("key_1)).get("key_1");

       

      After getting the value for key "key_1" after 15 seconds there is the value in the cache. The expiration or the eviction respectively did not start.

       

      The RegionManager in JBoss web-console dumps the region. Why is evitionQueueSize 0?

       

      Region RegionImpl{fqn=/OTTO; classloader=null; status=ACTIVE; eviction=true; evictionQueueSize=0}

       

      Dumping the cache in JBoss web-console lists

       

      --- Cache1 ---

      /  null

        /OTTO  null

          /key_2  {expiration=1352982716472, key_2=value_2}

          /key_0  {expiration=1352982716472, key_0=value_0}

          /key_1  {expiration=1352982716472, key_1=value_1}

       

      ------------

        • 1. Re: Using ExpirationAlgorithm in EvictionConfig not working in JBoss 5.1
          Thomas Hofmann Newbie

          Sorry, missed some lines in the code. Here is the complete code:

           

          CacheManager cacheManager = com.bspartners.util.ServiceLocator.getCacheManager();

          Cache expirationCache = cacheManager.getCache("prodb-expiration-cache", true);

           

          Node rootNode = expirationCache.getRoot();

          Fqn cacheFqn = Fqn.fromString("/OTTO");

          Region region = expirationCache.getRegion(cacheFqn, true);

          ExpirationAlgorithmConfig expirationAlgorithmConfig = new ExpirationAlgorithmConfig();

          expirationAlgorithmConfig.setExpirationKeyName(ExpirationAlgorithmConfig.EXPIRATION_KEY);

          EvictionRegionConfig erc = new EvictionRegionConfig(cacheFqn, expirationAlgorithmConfig);

          region.setEvictionRegionConfig(erc);

          EvictionConfig evictionConfig = new EvictionConfig();

          List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();

          ercs.add(erc);

          evictionConfig.setEvictionRegionConfigs(ercs);

          evictionConfig.setWakeupInterval(500);

          expirationCache.getConfiguration().setEvictionConfig(evictionConfig);

          Node cacheNode = rootNode.getChild(cacheFqn);

          Long future = new Long(System.currentTimeMillis() + 10000);

          Fqn keyFqn = Fqn.fromElements(key);

          cacheNode.addChild(keyFqn).put(ExpirationAlgorithmConfig.EXPIRATION_KEY, future);

          cacheNode.getChild(keyFqn).put("key_1", "value_1");

           

          Object value = rootNode.getChild(cacheFqn).getChild(Fqn.fromElements("key_1)).get("key_1");

           

          Would be very appreciate for any hint, which will do that stuff work!!