[exo-jcr-commits] exo-jcr SVN: r2039 - in kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src: main/java/org/exoplatform/services/cache/impl/jboss/ea and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 8 06:16:33 EST 2010


Author: nfilotto
Date: 2010-03-08 06:16:32 -0500 (Mon, 08 Mar 2010)
New Revision: 2039

Added:
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestEACache.java
Modified:
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml
Log:
EXOJCR-576

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java	2010-03-08 11:16:14 UTC (rev 2038)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java	2010-03-08 11:16:32 UTC (rev 2039)
@@ -245,7 +245,7 @@
    /**
     * Only puts the data into the cache nothing more
     */
-   private V putOnly(K key, V value)
+   protected V putOnly(K key, V value)
    {
       return cache.put(getFqn(key), key, value);
    }
@@ -428,7 +428,7 @@
    /**
     * Returns the Fqn related to the given name
     */
-   private Fqn<Serializable> getFqn(Serializable name)
+   protected Fqn<Serializable> getFqn(Serializable name)
    {
       return Fqn.fromElements(name);
    }

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java	2010-03-08 11:16:32 UTC (rev 2039)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+package org.exoplatform.services.cache.impl.jboss.ea;
+
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.jboss.cache.eviction.ExpirationAlgorithm;
+
+
+/**
+ * The {@link org.exoplatform.services.cache.ExoCacheConfig} for the {@link ExpirationAlgorithm} 
+ * implementation
+ * 
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto 
+ *          nicolas.filotto at exoplatform.com
+ * 8 mars 2010  
+ */
+public class EAExoCacheConfig extends ExoCacheConfig
+{
+
+   private int maxNodes;
+   
+   private long minTimeToLive;
+   
+   private long expirationTimeout;
+
+   public int getMaxNodes()
+   {
+      return maxNodes;
+   }
+
+   public void setMaxNodes(int maxNodes)
+   {
+      this.maxNodes = maxNodes;
+   }
+
+   public long getMinTimeToLive()
+   {
+      return minTimeToLive;
+   }
+
+   public void setMinTimeToLive(long minTimeToLive)
+   {
+      this.minTimeToLive = minTimeToLive;
+   }
+   
+   public long getExpirationTimeout()
+   {
+      return expirationTimeout;
+   }
+
+   public void setExpirationTimeout(long expirationTimeout)
+   {
+      this.expirationTimeout = expirationTimeout;
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheCreator.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheCreator.java	2010-03-08 11:16:32 UTC (rev 2039)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see&lt;http://www.gnu.org/licenses/&gt;.
+ */
+package org.exoplatform.services.cache.impl.jboss.ea;
+
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.annotations.ManagedName;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCache;
+import org.exoplatform.services.cache.impl.jboss.ExoCacheCreator;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.ExpirationAlgorithm;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+
+import java.io.Serializable;
+
+/**
+ * The {@link ExpirationAlgorithm} Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto 
+ *          nicolas.filotto at exoplatform.com
+ * 8 mars 2010  
+ */
+public class EAExoCacheCreator implements ExoCacheCreator
+{
+
+   /**
+    * The expected implementation name
+    */
+   public static final String EXPECTED_IMPL = "EA";
+
+   /**
+    * The default value for the parameter expirationTimeout
+    */
+   protected long defaultExpirationTimeout;
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getExpectedImplementation()
+   {
+      return EXPECTED_IMPL;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Class<? extends ExoCacheConfig> getExpectedConfigType()
+   {
+      return EAExoCacheConfig.class;
+   }
+
+   /**
+    * @see org.exoplatform.services.cache.impl.jboss.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig, org.jboss.cache.Cache)
+    */
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache)
+      throws ExoCacheInitException
+   {
+      if (config instanceof EAExoCacheConfig)
+      {
+         final EAExoCacheConfig eaConfig = (EAExoCacheConfig)config;
+         return create(config, cache, eaConfig.getMaxNodes(), eaConfig.getMinTimeToLive(), eaConfig
+            .getExpirationTimeout());
+      }
+      else
+      {
+         final long period = config.getLiveTime();
+         return create(config, cache, config.getMaxSize(), period > 0 ? period * 1000 : 0, defaultExpirationTimeout);
+      }
+   }
+
+   /**
+    * Creates a new ExoCache instance with the relevant parameters
+    */
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache,
+      int maxNodes, long minTimeToLive, long expirationTimeout) throws ExoCacheInitException
+   {
+      final Configuration configuration = cache.getConfiguration();
+      final ExpirationAlgorithmConfig ea = new ExpirationAlgorithmConfig();
+      ea.setMaxNodes(maxNodes);
+      ea.setMinTimeToLive(minTimeToLive);
+      ea.setExpirationKeyName(ExpirationAlgorithmConfig.EXPIRATION_KEY);
+      // Create an eviction region config
+      final EvictionRegionConfig erc = new EvictionRegionConfig(Fqn.ROOT, ea);
+
+      final EvictionConfig evictionConfig = configuration.getEvictionConfig();
+      evictionConfig.setDefaultEvictionRegionConfig(erc);
+
+      return new EAExoCache(config, cache, ea, expirationTimeout);
+   }
+
+   /**
+    * The {@link ExpirationAlgorithm} implementation of an ExoCache
+    */
+   public static class EAExoCache extends AbstractExoCache<Serializable, Object>
+   {
+      private long expirationTimeout;
+
+      private final ExpirationAlgorithmConfig ea;
+
+      public EAExoCache(ExoCacheConfig config, Cache<Serializable, Object> cache, ExpirationAlgorithmConfig ea,
+         long expirationTimeout)
+      {
+         super(config, cache);
+         this.ea = ea;
+         this.expirationTimeout = expirationTimeout;
+      }
+
+      /**
+       * We set the <code>ExpirationAlgorithmConfig.EXPIRATION_KEY</code> based on the <code>expirationTimeout</code>
+       * @see org.exoplatform.services.cache.impl.jboss.AbstractExoCache#putOnly(java.io.Serializable, java.lang.Object)
+       */
+      @Override
+      protected Object putOnly(Serializable key, Object value)
+      {
+         Fqn<Serializable> fqn = getFqn(key);
+         Long future = new Long(System.currentTimeMillis() + expirationTimeout);
+         cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
+         return cache.put(fqn, key, value);
+      }
+
+      public void setMaxSize(int max)
+      {
+         ea.setMaxNodes(max);
+      }
+
+      public void setLiveTime(long period)
+      {
+         ea.setMinTimeToLive(period);
+      }
+
+      @ManagedName("MaxNodes")
+      @ManagedDescription("This is the maximum number of nodes allowed in this region. 0 denotes immediate expiry, -1 denotes no limit.")
+      public int getMaxSize()
+      {
+         return ea.getMaxNodes();
+      }
+
+      @ManagedName("MinTimeToLive")
+      @ManagedDescription("the minimum amount of time a node must be allowed to live after being accessed before it is allowed to be considered for eviction. 0 denotes that this feature is disabled, which is the default value.")
+      public long getLiveTime()
+      {
+         return ea.getMinTimeToLive();
+      }
+
+      @Managed
+      @ManagedName("ExpirationTimeout")
+      @ManagedDescription("This is the timeout after which the cache entry must be evicted.")
+      public long getExpirationTimeout()
+      {
+         return expirationTimeout;
+      }
+
+      @Managed
+      public void setExpirationTimeout(long expirationTimeout)
+      {
+         this.expirationTimeout = expirationTimeout;
+      }
+   }
+}

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java	2010-03-08 11:16:14 UTC (rev 2038)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java	2010-03-08 11:16:32 UTC (rev 2039)
@@ -51,7 +51,7 @@
    public static final String EXPECTED_IMPL = "LFU";
 
    /**
-    * The default value for the parameter maxAge
+    * The default value for the parameter minNodes
     */
    protected int defaultMinNodes;
 

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestEACache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestEACache.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestEACache.java	2010-03-08 11:16:32 UTC (rev 2039)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.cache.impl.jboss;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.impl.jboss.ea.EAExoCacheCreator.EAExoCache;
+import org.exoplatform.test.BasicTestCase;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : eXoPlatform
+ *          exo at exoplatform.com
+ * 21 juil. 2009  
+ */
+public class TestEACache extends BasicTestCase
+{
+
+   CacheService service_;
+
+   public TestEACache(String name)
+   {
+      super(name);
+   }
+
+   public void setUp() throws Exception
+   {
+      service_ = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
+   }
+
+   public void testPolicy() throws Exception
+   {
+      testPolicy("test-ea");
+      testPolicy("test-ea-with-old-config");
+   }
+
+   private void testPolicy(String cacheName) throws Exception
+   {
+      EAExoCache cache = (EAExoCache)service_.getCacheInstance(cacheName);
+      cache.put("a", "a");
+      cache.put("b", "a");
+      cache.put("c", "a");
+      cache.put("d", "a");
+      Thread.sleep(1000);
+      assertEquals(4, cache.getCacheSize());
+      cache.put("e", "a");
+      assertEquals(5, cache.getCacheSize());
+      cache.put("f", "a");
+      assertEquals(6, cache.getCacheSize());
+      Thread.sleep(1100);
+      assertEquals(2, cache.getCacheSize());
+      Thread.sleep(1000);
+      assertEquals(0, cache.getCacheSize());
+      cache.setMaxSize(3);
+      cache.setLiveTime(400);
+      cache.setExpirationTimeout(500);
+      cache.put("a", "a");
+      cache.put("b", "a");
+      cache.put("c", "a");
+      cache.put("d", "a");
+      assertEquals(4, cache.getCacheSize());
+      cache.put("e", "a");
+      assertEquals(5, cache.getCacheSize());
+      cache.put("f", "a");
+      Thread.sleep(600);
+      assertEquals(0, cache.getCacheSize());
+   }
+}

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml	2010-03-08 11:16:14 UTC (rev 2038)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml	2010-03-08 11:16:32 UTC (rev 2039)
@@ -122,7 +122,27 @@
           <field name="maxAge"><long>2000</long></field>
           <field name="timeToLive"><long>1500</long></field>
         </object>
-      </object-param>                                  
+      </object-param>    
+       <object-param>
+        <name>test-ea-with-old-config</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.ExoCacheConfig">
+          <field name="name"><string>test-ea-with-old-config</string></field>
+          <field name="maxSize"><int>5</int></field>
+          <field name="liveTime"><long>1</long></field>
+          <field name="implementation"><string>EA</string></field>
+        </object>
+      </object-param> 
+       <object-param>
+        <name>test-ea</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.impl.jboss.ea.EAExoCacheConfig">
+          <field name="name"><string>test-ea</string></field>
+          <field name="maxNodes"><int>5</int></field>
+          <field name="minTimeToLive"><long>1000</long></field>
+          <field name="expirationTimeout"><long>2000</long></field>
+        </object>
+      </object-param>                                   
     </init-params>	
   </component>  
   
@@ -174,7 +194,14 @@
 		        	<field name="defaultTimeToLive"><long>1500</long></field>
 		        	<field name="defaultMaxAge"><long>2000</long></field>	
 		        </object>
-		    </object-param>  		          
+		    </object-param>  
+	      <object-param>
+		        <name>EA</name>
+		        <description>The ea cache creator</description>
+		        <object type="org.exoplatform.services.cache.impl.jboss.ea.EAExoCacheCreator">
+		        	<field name="defaultExpirationTimeout"><long>2000</long></field>	
+		        </object>
+		    </object-param>		    		          
       </init-params>	
     </component-plugin>
   </external-component-plugins>  



More information about the exo-jcr-commits mailing list