[exo-jcr-commits] exo-jcr SVN: r959 - in kernel/trunk: exo.kernel.component.ext.cache.impl.jboss.v3 and 6 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 9 05:30:42 EST 2009


Author: nfilotto
Date: 2009-12-09 05:30:42 -0500 (Wed, 09 Dec 2009)
New Revision: 959

Modified:
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
   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/ExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.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/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
   kernel/trunk/pom.xml
Log:
EXOJCR-296: Apply some remarks after the work done for KER-119

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml	2009-12-09 10:30:42 UTC (rev 959)
@@ -8,7 +8,7 @@
    </parent>
 
    <artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
-
+   <name>eXo Kernel :: Cache Extension :: JBoss Cache Implementation</name>
    <description>JBoss Cache Implementation for the Cache Service</description>
 
    <dependencies>

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	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,15 +18,9 @@
  */
 package org.exoplatform.services.cache.impl.jboss;
 
-import java.io.Serializable;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
-
+import org.exoplatform.services.cache.CacheInfo;
 import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CacheListenerContext;
 import org.exoplatform.services.cache.CachedObjectSelector;
 import org.exoplatform.services.cache.ExoCache;
 import org.exoplatform.services.cache.ExoCacheConfig;
@@ -37,13 +31,20 @@
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
-import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.notifications.annotation.NodeEvicted;
 import org.jboss.cache.notifications.annotation.NodeModified;
 import org.jboss.cache.notifications.annotation.NodeRemoved;
 import org.jboss.cache.notifications.event.EventImpl;
 import org.jboss.cache.notifications.event.NodeEvent;
 
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
 /**
  * An {@link org.exoplatform.services.cache.ExoCache} implementation based on {@link org.jboss.cache.Node}.
  * Created by The eXo Platform SAS
@@ -51,7 +52,7 @@
  *          exo at exoplatform.com
  * 20 juil. 2009  
  */
-public abstract class AbstractExoCache implements ExoCache
+public abstract class AbstractExoCache<K extends Serializable, V> implements ExoCache<K, V>
 {
 
    /**
@@ -59,12 +60,10 @@
     */
    private static final Log LOG = ExoLogger.getLogger(AbstractExoCache.class);
 
-   protected final AtomicInteger size = new AtomicInteger();
+   private final AtomicInteger hits = new AtomicInteger(0);
 
-   private volatile int hits;
+   private final AtomicInteger misses = new AtomicInteger(0);
 
-   private volatile int misses;
-
    private String label;
 
    private String name;
@@ -75,34 +74,33 @@
 
    private boolean logEnabled;
 
-   private final CopyOnWriteArrayList<CacheListener> listeners;
+   private final CopyOnWriteArrayList<ListenerContext<K, V>> listeners;
 
-   protected final CacheSPI<Serializable, Object> cache;
+   protected final CacheSPI<K, V> cache;
 
-   @SuppressWarnings("unchecked")
-   public AbstractExoCache(ExoCacheConfig config, CacheSPI<Serializable, Object> cache)
+   public AbstractExoCache(ExoCacheConfig config, Cache<K, V> cache)
    {
-      this.cache = cache;
-      this.listeners = new CopyOnWriteArrayList<CacheListener>();
+      this.cache = (CacheSPI<K, V>)cache;
+      this.listeners = new CopyOnWriteArrayList<ListenerContext<K, V>>();
       setDistributed(config.isDistributed());
       setLabel(config.getLabel());
       setName(config.getName());
       setLogEnabled(config.isLogEnabled());
       setReplicated(config.isRepicated());
       cache.getConfiguration().setInvocationBatchingEnabled(true);
-      cache.addCacheListener(new SizeManager());
+      cache.addCacheListener(new CacheEventListener());
    }
 
    /**
     * {@inheritDoc}
     */
-   public void addCacheListener(CacheListener listener)
+   public void addCacheListener(CacheListener<? super K, ? super V> listener)
    {
       if (listener == null)
       {
-         return;
+         throw new NullPointerException();
       }
-      listeners.add(listener);
+      listeners.add(new ListenerContext<K, V>(listener, this));
    }
 
    /**
@@ -110,8 +108,8 @@
     */
    public void clearCache() throws Exception
    {
-      final Node<Serializable, Object> rootNode = cache.getRoot();
-      for (Node<Serializable, Object> node : rootNode.getChildren())
+      final Node<K, V> rootNode = cache.getRoot();
+      for (Node<K, V> node : rootNode.getChildren())
       {
          if (node == null)
          {
@@ -125,18 +123,23 @@
    /**
     * {@inheritDoc}
     */
-   public Object get(Serializable name) throws Exception
+   @SuppressWarnings("unchecked")
+   public V get(Serializable name) throws Exception
    {
-      final Object result = cache.get(Fqn.fromElements(name), name);
+      if (name == null)
+      {
+         return null;
+      }      
+      final V result = cache.get(getFqn(name), (K)name);
       if (result == null)
       {
-         misses++;
+         misses.incrementAndGet();
       }
       else
       {
-         hits++;
+         hits.incrementAndGet();
       }
-      onGet(name, result);
+      onGet((K)name, result);
       return result;
    }
 
@@ -145,7 +148,7 @@
     */
    public int getCacheHit()
    {
-      return hits;
+      return hits.get();
    }
 
    /**
@@ -153,13 +156,12 @@
     */
    public int getCacheMiss()
    {
-      return misses;
+      return misses.get();
    }
 
    /**
     * {@inheritDoc}
     */
-   @SuppressWarnings("unchecked")
    public int getCacheSize()
    {
       return cache.getNumberOfNodes();
@@ -168,16 +170,16 @@
    /**
     * {@inheritDoc}
     */
-   public List<Object> getCachedObjects()
+   public List<V> getCachedObjects()
    {
-      final LinkedList<Object> list = new LinkedList<Object>();
-      for (Node<Serializable, Object> node : cache.getRoot().getChildren())
+      final LinkedList<V> list = new LinkedList<V>();
+      for (Node<K, V> node : cache.getRoot().getChildren())
       {
          if (node == null)
          {
             continue;
          }
-         final Object value = node.get(getKey(node));
+         final V value = node.get(getKey(node));
          if (value != null)
          {
             list.add(value);
@@ -229,33 +231,48 @@
    /**
     * {@inheritDoc}
     */
-   public void put(Serializable name, Object obj) throws Exception
+   public void put(K key, V value) throws Exception
    {
-      putOnly(name, obj);
-      onPut(name, obj);
+      if (key == null)
+      {
+         throw new NullPointerException("No null cache key accepted");
+      }      
+      putOnly(key, value);
+      onPut(key, value);
    }
 
    /**
     * Only puts the data into the cache nothing more
     */
-   private Object putOnly(Serializable name, Object obj) throws Exception
+   private V putOnly(K key, V value) throws Exception
    {
-      return cache.put(Fqn.fromElements(name), name, obj);
+      return cache.put(getFqn(key), key, value);
    }
 
    /**
     * {@inheritDoc}
     */
-   public void putMap(Map<Serializable, Object> objs) throws Exception
+   public void putMap(Map<? extends K, ? extends V> objs) throws NullPointerException, IllegalArgumentException
    {
+      if (objs == null)
+      {
+         throw new NullPointerException("No null map accepted");
+      }
+      for (Serializable name : objs.keySet())
+      {
+         if (name == null)
+         {
+            throw new IllegalArgumentException("No null cache key accepted");
+         }
+      }      
       cache.startBatch();
       int total = 0;
       try
       {
          // Start transaction
-         for (Entry<Serializable, Object> entry : objs.entrySet())
+         for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
          {
-            Object value = putOnly(entry.getKey(), entry.getValue());
+            V value = putOnly(entry.getKey(), entry.getValue());
             if (value == null)
             {
                total++;
@@ -263,7 +280,7 @@
          }
          cache.endBatch(true);
          // End transaction
-         for (Entry<Serializable, Object> entry : objs.entrySet())
+         for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
          {
             onPut(entry.getKey(), entry.getValue());
          }
@@ -271,35 +288,40 @@
       catch (Exception e)
       {
          cache.endBatch(false);
-         throw e;
+         LOG.warn("An error occurs while executing the putMap method", e);
       }
    }
 
    /**
     * {@inheritDoc}
     */
-   public Object remove(Serializable name) throws Exception
+   @SuppressWarnings("unchecked")
+   public V remove(Serializable name) throws Exception
    {
-      final Fqn<Serializable> fqn = Fqn.fromElements(name);
-      final Node<Serializable, Object> node = cache.getNode(fqn);
+      if (name == null)
+      {
+         throw new NullPointerException("No null cache key accepted");
+      }      
+      final Fqn<Serializable> fqn = getFqn(name);
+      final NodeSPI<K, V> node = cache.getNode(fqn);
+      V result = null;
       if (node != null)
       {
-         final Object result = node.get(name);
+         result = node.getDirect((K)name);
          if (cache.removeNode(fqn))
          {
-            onRemove(name, result);
+            onRemove((K)name, result);
          }
-         return result;
       }
-      return null;
+      return result;
    }
 
    /**
     * {@inheritDoc}
     */
-   public List<Object> removeCachedObjects() throws Exception
+   public List<V> removeCachedObjects() throws Exception
    {
-      final List<Object> list = getCachedObjects();
+      final List<V> list = getCachedObjects();
       clearCache();
       return list;
    }
@@ -307,19 +329,23 @@
    /**
     * {@inheritDoc}
     */
-   public void select(CachedObjectSelector selector) throws Exception
+   public void select(CachedObjectSelector<? super K, ? super V> selector) throws Exception
    {
-      for (Node<Serializable, Object> node : cache.getRoot().getChildren())
+      if (selector == null)
       {
+         throw new IllegalArgumentException("No null selector");
+      }      
+      for (Node<K, V> node : cache.getRoot().getChildren())
+      {
          if (node == null)
          {
             continue;
          }
-         final Serializable key = getKey(node);
-         final Object value = node.get(key);
-         ObjectCacheInfo info = new ObjectCacheInfo()
+         final K key = getKey(node);
+         final V value = node.get(key);
+         ObjectCacheInfo<V> info = new ObjectCacheInfo<V>()
          {
-            public Object get()
+            public V get()
             {
                return value;
             }
@@ -380,7 +406,7 @@
    /**
     * Returns the key related to the given node
     */
-   private Serializable getKey(Node<Serializable, Object> node)
+   private K getKey(Node<K, V> node)
    {
       return getKey(node.getFqn());
    }
@@ -389,22 +415,30 @@
     * Returns the key related to the given Fqn
     */
    @SuppressWarnings("unchecked")
-   private Serializable getKey(Fqn fqn)
+   private K getKey(Fqn fqn)
    {
-      return (Serializable)fqn.get(0);
+      return (K)fqn.get(0);
    }
 
-   void onExpire(Serializable key, Object obj)
+   /**
+    * Returns the Fqn related to the given name
+    */
+   private Fqn<Serializable> getFqn(Serializable name)
    {
+      return Fqn.fromElements(name);
+   }
+
+   void onExpire(K key, V obj)
+   {
       if (listeners.isEmpty())
       {
          return;
       }
-      for (CacheListener listener : listeners)
+      for (ListenerContext<K, V> context : listeners)
       {
          try
          {
-            listener.onExpire(this, key, obj);
+            context.onExpire(key, obj);
          }
          catch (Exception e)
          {
@@ -414,17 +448,17 @@
       }
    }
 
-   void onRemove(Serializable key, Object obj)
+   void onRemove(K key, V obj)
    {
       if (listeners.isEmpty())
       {
          return;
       }
-      for (CacheListener listener : listeners)
+      for (ListenerContext<K, V> context : listeners)
       {
          try
          {
-            listener.onRemove(this, key, obj);
+            context.onRemove(key, obj);
          }
          catch (Exception e)
          {
@@ -434,16 +468,16 @@
       }
    }
 
-   void onPut(Serializable key, Object obj)
+   void onPut(K key, V obj)
    {
       if (listeners.isEmpty())
       {
          return;
       }
-      for (CacheListener listener : listeners)
+      for (ListenerContext<K, V> context : listeners)
          try
          {
-            listener.onPut(this, key, obj);
+            context.onPut(key, obj);
          }
          catch (Exception e)
          {
@@ -452,16 +486,16 @@
          }
    }
 
-   void onGet(Serializable key, Object obj)
+   void onGet(K key, V obj)
    {
       if (listeners.isEmpty())
       {
          return;
       }
-      for (CacheListener listener : listeners)
+      for (ListenerContext<K, V> context : listeners)
          try
          {
-            listener.onGet(this, key, obj);
+            context.onGet(key, obj);
          }
          catch (Exception e)
          {
@@ -476,10 +510,10 @@
       {
          return;
       }
-      for (CacheListener listener : listeners)
+      for (ListenerContext<K, V> context : listeners)
          try
          {
-            listener.onClearCache(this);
+            context.onClearCache();
          }
          catch (Exception e)
          {
@@ -489,7 +523,7 @@
    }
 
    @org.jboss.cache.notifications.annotation.CacheListener
-   public class SizeManager
+   public class CacheEventListener
    {
 
       @NodeEvicted
@@ -507,43 +541,100 @@
       @NodeRemoved
       public void nodeRemoved(NodeEvent ne)
       {
-         if (ne.isPre())
+         if (ne.isPre() && !ne.isOriginLocal())
          {
-            if (!ne.isOriginLocal())
-            {
-               final Node<Serializable, Object> node = cache.getNode(ne.getFqn());
-               final Serializable key = getKey(ne.getFqn());
-               onRemove(key, node.get(key));
-            }
+            final Node<K, V> node = cache.getNode(ne.getFqn());
+            final K key = getKey(ne.getFqn());
+            onRemove(key, node.get(key));
          }
       }
 
-      @NodeCreated
-      public void nodeCreated(NodeEvent ne)
-      {
-         size.incrementAndGet();
-      }
-
       @SuppressWarnings("unchecked")
       @NodeModified
       public void nodeModified(NodeEvent ne)
       {
          if (!ne.isOriginLocal() && !ne.isPre())
          {
-            final Serializable key = getKey(ne.getFqn());
+            final K key = getKey(ne.getFqn());
             if (ne instanceof EventImpl)
             {
                EventImpl evt = (EventImpl)ne;
-               Map<Serializable, Object> data = evt.getData();
+               Map<K, V> data = evt.getData();
                if (data != null)
                {
                   onPut(key, data.get(key));
                   return;
                }
             }
-            final Node<Serializable, Object> node = cache.getNode(ne.getFqn());
+            final Node<K, V> node = cache.getNode(ne.getFqn());
             onPut(key, node.get(key));
          }
       }
    }
+   
+   private static class ListenerContext<K extends Serializable, V> implements CacheListenerContext, CacheInfo
+   {
+
+      /** . */
+      private final ExoCache<K, V> cache;
+
+      /** . */
+      final CacheListener<? super K, ? super V> listener;
+
+      public ListenerContext(CacheListener<? super K, ? super V> listener, ExoCache<K, V> cache)
+      {
+         this.listener = listener;
+         this.cache = cache;
+      }
+
+      public CacheInfo getCacheInfo()
+      {
+         return this;
+      }
+
+      public String getName()
+      {
+         return cache.getName();
+      }
+
+      public int getMaxSize()
+      {
+         return cache.getMaxSize();
+      }
+
+      public long getLiveTime()
+      {
+         return cache.getLiveTime();
+      }
+
+      public int getSize()
+      {
+         return cache.getCacheSize();
+      }
+
+      void onExpire(K key, V obj) throws Exception
+      {
+         listener.onExpire(this, key, obj);
+      }
+
+      void onRemove(K key, V obj) throws Exception
+      {
+         listener.onRemove(this, key, obj);
+      }
+
+      void onPut(K key, V obj) throws Exception
+      {
+         listener.onPut(this, key, obj);
+      }
+
+      void onGet(K key, V obj) throws Exception
+      {
+         listener.onGet(this, key, obj);
+      }
+
+      void onClearCache() throws Exception
+      {
+         listener.onClearCache(this);
+      }
+   }
 }

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheCreator.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,13 +18,13 @@
  */
 package org.exoplatform.services.cache.impl.jboss;
 
-import java.io.Serializable;
-
 import org.exoplatform.services.cache.ExoCache;
 import org.exoplatform.services.cache.ExoCacheConfig;
 import org.exoplatform.services.cache.ExoCacheInitException;
 import org.jboss.cache.Cache;
 
+import java.io.Serializable;
+
 /**
  * This class is used to create the cache according to the given 
  * configuration {@link org.exoplatform.services.cache.ExoCacheConfig}
@@ -43,7 +43,7 @@
     * @param cache the cache to initialize
     * @exception ExoCacheInitException if an exception happens while initializing the cache
     */
-   public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException;
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException;
 
    /**
     * Returns the type of {@link org.exoplatform.services.cache.ExoCacheConfig} expected by the creator  

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheCreator.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
  */
 package org.exoplatform.services.cache.impl.jboss.fifo;
 
-import java.io.Serializable;
-
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
 import org.exoplatform.services.cache.ExoCache;
@@ -34,6 +32,8 @@
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.FIFOAlgorithmConfig;
 
+import java.io.Serializable;
+
 /**
  * The FIFO Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
  * Created by The eXo Platform SAS
@@ -68,7 +68,7 @@
    /**
     * {@inheritDoc}
     */
-   public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
    {
       if (config instanceof FIFOExoCacheConfig)
       {
@@ -85,7 +85,7 @@
    /**
     * Creates a new ExoCache instance with the relevant parameters
     */
-   private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
       throws ExoCacheInitException
    {
       final Configuration configuration = cache.getConfiguration();
@@ -97,7 +97,7 @@
       final EvictionConfig evictionConfig = configuration.getEvictionConfig();
       evictionConfig.setDefaultEvictionRegionConfig(erc);
 
-      return new AbstractExoCache(config, cache)
+      return new AbstractExoCache<Serializable, Object>(config, cache)
       {
 
          public void setMaxSize(int max)

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	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheCreator.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
  */
 package org.exoplatform.services.cache.impl.jboss.lfu;
 
-import java.io.Serializable;
-
 import org.exoplatform.management.annotations.Managed;
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
@@ -35,6 +33,8 @@
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.LFUAlgorithmConfig;
 
+import java.io.Serializable;
+
 /**
  * The LFU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
  * Created by The eXo Platform SAS
@@ -58,7 +58,7 @@
    /**
     * {@inheritDoc}
     */
-   public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
    {
       if (config instanceof LFUExoCacheConfig)
       {
@@ -75,7 +75,7 @@
    /**
     * Creates a new ExoCache instance with the relevant parameters
     */
-   private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, int minNodes,
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, int minNodes,
       long minTimeToLive) throws ExoCacheInitException
    {
       final Configuration configuration = cache.getConfiguration();
@@ -108,7 +108,7 @@
    /**
     * The LRU implementation of an ExoCache
     */
-   public static class LFUExoCache extends AbstractExoCache
+   public static class LFUExoCache extends AbstractExoCache<Serializable, Object>
    {
 
       private final LFUAlgorithmConfig lfu;

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheCreator.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
  */
 package org.exoplatform.services.cache.impl.jboss.lru;
 
-import java.io.Serializable;
-
 import org.exoplatform.management.annotations.Managed;
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
@@ -35,6 +33,8 @@
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.LRUAlgorithmConfig;
 
+import java.io.Serializable;
+
 /**
  * The LRU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
  * Created by The eXo Platform SAS
@@ -63,7 +63,7 @@
    /**
     * {@inheritDoc}
     */
-   public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
    {
       if (config instanceof LRUExoCacheConfig)
       {
@@ -82,7 +82,7 @@
    /**
     * Creates a new ExoCache instance with the relevant parameters
     */
-   private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long timeToLive,
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long timeToLive,
       long maxAge, long minTimeToLive) throws ExoCacheInitException
    {
       final Configuration configuration = cache.getConfiguration();
@@ -115,7 +115,7 @@
    /**
     * The LRU implementation of an ExoCache
     */
-   public static class LRUExoCache extends AbstractExoCache
+   public static class LRUExoCache extends AbstractExoCache<Serializable, Object>
    {
 
       private final LRUAlgorithmConfig lru;

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheCreator.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -18,8 +18,6 @@
  */
 package org.exoplatform.services.cache.impl.jboss.mru;
 
-import java.io.Serializable;
-
 import org.exoplatform.management.annotations.ManagedDescription;
 import org.exoplatform.management.annotations.ManagedName;
 import org.exoplatform.services.cache.ExoCache;
@@ -34,6 +32,8 @@
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.MRUAlgorithmConfig;
 
+import java.io.Serializable;
+
 /**
  * The MRU Implementation of an {@link org.exoplatform.services.cache.impl.jboss.ExoCacheCreator}
  * Created by The eXo Platform SAS
@@ -52,7 +52,7 @@
    /**
     * {@inheritDoc}
     */
-   public ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache) throws ExoCacheInitException
    {
       if (config instanceof MRUExoCacheConfig)
       {
@@ -69,7 +69,7 @@
    /**
     * Creates a new ExoCache instance with the relevant parameters
     */
-   private ExoCache create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Cache<Serializable, Object> cache, int maxNodes, long minTimeToLive)
       throws ExoCacheInitException
    {
       final Configuration configuration = cache.getConfiguration();
@@ -81,7 +81,7 @@
       final EvictionConfig evictionConfig = configuration.getEvictionConfig();
       evictionConfig.setDefaultEvictionRegionConfig(erc);
 
-      return new AbstractExoCache(config, cache)
+      return new AbstractExoCache<Serializable, Object>(config, cache)
       {
 
          public void setMaxSize(int max)

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java	2009-12-09 10:30:42 UTC (rev 959)
@@ -52,7 +52,7 @@
 
    CacheService service;
 
-   AbstractExoCache cache;
+   AbstractExoCache<Serializable, Object> cache;
 
    ExoCacheFactory factory;
 
@@ -64,7 +64,7 @@
    public void setUp() throws Exception
    {
       this.service = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
-      this.cache = (AbstractExoCache)service.getCacheInstance("myCache");
+      this.cache = (AbstractExoCache<Serializable, Object>)service.getCacheInstance("myCache");
       this.factory = (ExoCacheFactory)PortalContainer.getInstance().getComponentInstanceOfType(ExoCacheFactory.class);
    }
 
@@ -130,6 +130,8 @@
       assertEquals(2, cache.getCacheSize());
       values = new HashMap<Serializable, Object>()
       {
+         private static final long serialVersionUID = 1L;
+
          public Set<Entry<Serializable, Object>> entrySet()
          {
             Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
@@ -156,14 +158,7 @@
       };
       values.put(new MyKey("e"), "e");
       values.put(new MyKey("d"), "d");
-      try
-      {
-         cache.putMap(values);
-         assertTrue("An error was expected", false);
-      }
-      catch (Exception e)
-      {
-      }
+      cache.putMap(values);
       assertEquals(2, cache.getCacheSize());
    }
 
@@ -202,17 +197,17 @@
       cache.put(new MyKey("b"), 2);
       cache.put(new MyKey("c"), 3);
       final AtomicInteger count = new AtomicInteger();
-      CachedObjectSelector selector = new CachedObjectSelector()
+      CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>()
       {
 
-         public void onSelect(ExoCache cache, Serializable key, ObjectCacheInfo ocinfo) throws Exception
+         public void onSelect(ExoCache<? extends Serializable, ? extends Object> cache, Serializable key, ObjectCacheInfo<? extends Object> ocinfo) throws Exception
          {
             assertTrue(key.equals(new MyKey("a")) || key.equals(new MyKey("b")) || key.equals(new MyKey("c")));
             assertTrue(ocinfo.get().equals(1) || ocinfo.get().equals(2) || ocinfo.get().equals(3));
             count.incrementAndGet();
          }
 
-         public boolean select(Serializable key, ObjectCacheInfo ocinfo)
+         public boolean select(Serializable key, ObjectCacheInfo<? extends Object> ocinfo)
          {
             return true;
          }
@@ -234,6 +229,7 @@
       assertEquals(2, cache.getCacheMiss() - misses);
    }
 
+   @SuppressWarnings("unchecked")
    public void testDistributedCache() throws Exception
    {
       ExoCacheConfig config = new ExoCacheConfig();
@@ -246,13 +242,13 @@
       config2.setMaxSize(5);
       config2.setLiveTime(1000);
       config2.setDistributed(true);
-      AbstractExoCache cache1 = (AbstractExoCache)factory.createCache(config);
+      AbstractExoCache<Serializable, Object> cache1 = (AbstractExoCache<Serializable, Object>)factory.createCache(config);
       MyCacheListener listener1 = new MyCacheListener();
       cache1.addCacheListener(listener1);
-      AbstractExoCache cache2 = (AbstractExoCache)factory.createCache(config);
+      AbstractExoCache<Serializable, Object> cache2 = (AbstractExoCache<Serializable, Object>)factory.createCache(config);
       MyCacheListener listener2 = new MyCacheListener();
       cache2.addCacheListener(listener2);
-      AbstractExoCache cache3 = (AbstractExoCache)factory.createCache(config2);
+      AbstractExoCache<Serializable, Object> cache3 = (AbstractExoCache<Serializable, Object>)factory.createCache(config2);
       MyCacheListener listener3 = new MyCacheListener();
       cache3.addCacheListener(listener3);
       try
@@ -351,6 +347,8 @@
          assertEquals(0, listener3.clearCache);
          values = new HashMap<Serializable, Object>()
          {
+            private static final long serialVersionUID = 1L;
+
             public Set<Entry<Serializable, Object>> entrySet()
             {
                Set<Entry<Serializable, Object>> set = new LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
@@ -377,14 +375,7 @@
          };
          values.put(new MyKey("e"), "e");
          values.put(new MyKey("d"), "d");
-         try
-         {
-            cache1.putMap(values);
-            assertTrue("An error was expected", false);
-         }
-         catch (Exception e)
-         {
-         }
+         cache1.putMap(values);
          assertEquals(2, cache1.getCacheSize());
          assertEquals(2, cache2.getCacheSize());
          assertEquals(5, listener1.put);
@@ -410,7 +401,8 @@
 
    public void testMultiThreading() throws Exception
    {
-      final ExoCache cache = service.getCacheInstance("test-multi-threading");
+      long time = System.currentTimeMillis();
+      final ExoCache<Serializable, Object> cache = service.getCacheInstance("test-multi-threading");
       final int totalElement = 100;
       final int totalTimes = 100;
       int reader = 20;
@@ -444,12 +436,15 @@
                      }
                      sleep(50);
                   }
-                  doneSignal.countDown();
                }
                catch (Exception e)
                {
                   errors.add(e);
                }
+               finally
+               {
+                  doneSignal.countDown();
+               }
             }
          };
          thread.start();
@@ -472,12 +467,15 @@
                      }
                      sleep(50);
                   }
-                  doneSignal.countDown();
                }
                catch (Exception e)
                {
                   errors.add(e);
                }
+               finally
+               {
+                  doneSignal.countDown();
+               }
             }
          };
          thread.start();
@@ -499,12 +497,15 @@
                      }
                      sleep(50);
                   }
-                  doneSignal.countDown();
                }
                catch (Exception e)
                {
                   errors.add(e);
                }
+               finally
+               {
+                  doneSignal.countDown();
+               }
             }
          };
          thread.start();
@@ -534,12 +535,15 @@
                      }
                      sleep(50);
                   }
-                  doneSignal2.countDown();
                }
                catch (Exception e)
                {
                   errors.add(e);
                }
+               finally
+               {
+                  doneSignal2.countDown();
+               }
             }
          };
          thread.start();
@@ -558,12 +562,15 @@
                      sleep(150);
                      cache.clearCache();
                   }
-                  doneSignal2.countDown();
                }
                catch (Exception e)
                {
                   errors.add(e);
                }
+               finally
+               {
+                  doneSignal2.countDown();
+               }
             }
          };
          thread.start();
@@ -578,10 +585,10 @@
          }
          throw errors.get(0);
       }
-
+      System.out.println("Total Time = " + (System.currentTimeMillis() - time));
    }
 
-   public static class MyCacheListener implements CacheListener
+   public static class MyCacheListener implements CacheListener<Serializable, Object>
    {
 
       public int clearCache;
@@ -594,27 +601,27 @@
 
       public int remove;
 
-      public void onClearCache(ExoCache cache) throws Exception
+      public void onClearCache(ExoCache<Serializable, Object> cache) throws Exception
       {
          clearCache++;
       }
 
-      public void onExpire(ExoCache cache, Serializable key, Object obj) throws Exception
+      public void onExpire(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
       {
          expire++;
       }
 
-      public void onGet(ExoCache cache, Serializable key, Object obj) throws Exception
+      public void onGet(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
       {
          get++;
       }
 
-      public void onPut(ExoCache cache, Serializable key, Object obj) throws Exception
+      public void onPut(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
       {
          put++;
       }
 
-      public void onRemove(ExoCache cache, Serializable key, Object obj) throws Exception
+      public void onRemove(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
       {
          remove++;
       }
@@ -647,6 +654,7 @@
 
    public static class MyKey implements Serializable
    {
+      private static final long serialVersionUID = 1L;
       public String value;
 
       public MyKey(String value)

Modified: kernel/trunk/pom.xml
===================================================================
--- kernel/trunk/pom.xml	2009-12-09 09:10:18 UTC (rev 958)
+++ kernel/trunk/pom.xml	2009-12-09 10:30:42 UTC (rev 959)
@@ -53,7 +53,7 @@
       <module>exo.kernel.component.common</module>
       <module>exo.kernel.component.remote</module>
       <module>exo.kernel.component.cache</module>
-      <!--module>exo.kernel.component.ext.cache</module-->
+      <module>exo.kernel.component.ext.cache.impl.jboss.v3</module>
       <module>exo.kernel.component.command</module>
       <module>packaging/module</module>
    </modules>



More information about the exo-jcr-commits mailing list