[exo-jcr-commits] exo-jcr SVN: r4720 - in kernel/trunk: exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl and 25 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 9 10:05:17 EDT 2011


Author: nfilotto
Date: 2011-08-09 10:05:16 -0400 (Tue, 09 Aug 2011)
New Revision: 4720

Added:
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/configuration.xml
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml
Removed:
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v4/
Modified:
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
   kernel/trunk/pom.xml
Log:
EXOJCR-1475: Upgrade ISPN to 5.0.0 FINAL (kernel part)
* Removed exo.kernel.component.ext.cache.impl.infinispan.v4 since ISPN 4 and 5 are not compatible and only the version 5 will be supported by RH
* Used reflection to call the method org.jgroups.Message.setObject since the signature of the method has changed since JGroups 2.12
* Adapted the code to IPSN 5 : Fluent config has been used, eviction events have been modified and wakeUpInterval has been moved from eviction to expiration
* Adapted the config files to ISPN 5 : Correct version has been set to the config files header and replication timeout has been set explicitly to prevent warnings
* JGroups and ISPN have been upgraded in the pom files

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2011-08-09 12:59:58 UTC (rev 4719)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -53,6 +53,7 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.Serializable;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
@@ -83,6 +84,41 @@
    private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.common.RPCServiceImpl");
 
    /**
+    * We use reflection for the Message.setObject method in order to remain backward compatible 
+    * because since JGroups 2.12 the signature has changed the expected parameter is no more a Serializable, 
+    * it is an Object
+    */
+   private static Method MESSAGE_SET_OBJECT_METHOD;
+   
+   static
+   {
+      try
+      {
+         MESSAGE_SET_OBJECT_METHOD = Message.class.getMethod("setObject", Serializable.class);
+      }
+      catch (SecurityException e)
+      {
+         throw e;
+      }
+      catch (NoSuchMethodException e)
+      {
+         // We assume that we use JGroups 2.12 or higher
+         try
+         {
+            MESSAGE_SET_OBJECT_METHOD = Message.class.getMethod("setObject", Object.class);
+         }
+         catch (SecurityException e1)
+         {
+            throw e1;
+         }
+         catch (Exception e1)
+         {
+            throw new RuntimeException("Could not find the right Message.setObject method", e);
+         }
+      }
+   }
+   
+   /**
     * The name of the parameter for the location of the JGroups configuration.
     */
    protected static final String PARAM_JGROUPS_CONFIG = "jgroups-configuration";
@@ -426,7 +462,14 @@
          throw new RPCException("Command " + commandId + " unknown, please register your command first");
       }
       final Message msg = new Message();
-      msg.setObject(new MessageBody(dests.size() == 1 && dests != members ? dests.get(0) : null, commandId, args));
+      try
+      {
+         MESSAGE_SET_OBJECT_METHOD.invoke(msg, new MessageBody(dests.size() == 1 && dests != members ? dests.get(0) : null, commandId, args));
+      }
+      catch (Exception e)
+      {
+         throw new RPCException("Could not call the method Message.setObject");
+      }
       RspList rsps = SecurityHelper.doPrivilegedAction(new PrivilegedAction<RspList>()
       {
          public RspList run()

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -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.
+	-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.exoplatform.kernel</groupId>
+		<artifactId>kernel-parent</artifactId>
+		<version>2.3.0-GA-SNAPSHOT</version>
+	</parent>
+	<artifactId>exo.kernel.component.ext.cache.impl.infinispan.v5</artifactId>
+	<name>eXo Kernel :: Cache Extension :: Infinispan Implementation</name>
+	<description>Infinispan Implementation for the Cache Service</description>
+	<dependencies>
+		<dependency>
+			<groupId>org.exoplatform.kernel</groupId>
+			<artifactId>exo.kernel.component.cache</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.infinispan</groupId>
+			<artifactId>infinispan-core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.jgroups</groupId>
+			<artifactId>jgroups</artifactId>
+			<version>2.12.1.3.Final</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<configuration>
+					<systemProperties>
+						<!--
+							We add this system property due to some incompatibility between
+							IPv6 and some JVM of Linux distributions such as Ubuntu and
+							Fedora
+						-->
+						<property>
+							<name>java.net.preferIPv4Stack</name>
+							<value>true</value>
+						</property>
+						<!-- Avoid the firewall -->
+						<property>
+							<name>bind.address</name>
+							<value>127.0.0.1</value>
+						</property>
+						<property>
+							<name>jgroups.stack</name>
+							<value>udp</value>
+						</property>
+					</systemProperties>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,581 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+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;
+import org.exoplatform.services.cache.ObjectCacheInfo;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.infinispan.AdvancedCache;
+import org.infinispan.Cache;
+import org.infinispan.context.Flag;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
+import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent;
+import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
+import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+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 Cache}.
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public abstract class AbstractExoCache<K extends Serializable, V> implements ExoCache<K, V>
+{
+
+   /**
+    * Logger.
+    */
+   private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v4.AbstractExoCache");
+
+   private final AtomicInteger hits = new AtomicInteger(0);
+
+   private final AtomicInteger misses = new AtomicInteger(0);
+
+   private String label;
+
+   private String name;
+
+   private boolean distributed;
+
+   private boolean replicated;
+
+   private boolean logEnabled;
+
+   private final CopyOnWriteArrayList<ListenerContext<K, V>> listeners;
+
+   protected final AdvancedCache<K, V> cache;
+
+   public AbstractExoCache(ExoCacheConfig config, Cache<K, V> cache)
+   {
+      this.cache = cache.getAdvancedCache();
+      this.listeners = new CopyOnWriteArrayList<ListenerContext<K, V>>();
+      setDistributed(config.isDistributed());
+      setLabel(config.getLabel());
+      setName(config.getName());
+      setLogEnabled(config.isLogEnabled());
+      setReplicated(config.isRepicated());
+      cache.addListener(new CacheEventListener());
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void addCacheListener(CacheListener<? super K, ? super V> listener)
+   {
+      if (listener == null)
+      {
+         throw new NullPointerException();
+      }
+      listeners.add(new ListenerContext<K, V>(listener, this));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void clearCache()
+   {
+      cache.withFlags(Flag.CACHE_MODE_LOCAL).clear();
+      onClearCache();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @SuppressWarnings("unchecked")
+   public V get(Serializable name)
+   {
+      if (name == null)
+      {
+         return null;
+      }      
+      final V result = cache.get(name);
+      if (result == null)
+      {
+         misses.incrementAndGet();
+      }
+      else
+      {
+         hits.incrementAndGet();
+      }
+      onGet((K)name, result);
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getCacheHit()
+   {
+      return hits.get();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getCacheMiss()
+   {
+      return misses.get();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getCacheSize()
+   {
+      return cache.size();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public List<V> getCachedObjects()
+   {
+      Collection<V> values = cache.values();
+      if (values == null || values.isEmpty())
+      {
+         return Collections.emptyList();
+      }
+      else
+      {
+         return new ArrayList<V>(values);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getLabel()
+   {
+      return label;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isDistributed()
+   {
+      return distributed;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isLogEnabled()
+   {
+      return logEnabled;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isReplicated()
+   {
+      return replicated;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void put(K key, V value) throws NullPointerException
+   {
+      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
+    */
+   protected void putOnly(K key, V value)
+   {
+      cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).put(key, value);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   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();
+      try
+      {
+         // Start transaction
+         for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
+         {
+            putOnly(entry.getKey(), entry.getValue());
+         }
+         cache.endBatch(true);
+         // End transaction
+         for (Map.Entry<? extends K, ? extends V> entry : objs.entrySet())
+         {
+            onPut(entry.getKey(), entry.getValue());
+         }
+      }
+      catch (Exception e)
+      {
+         cache.endBatch(false);
+         LOG.warn("An error occurs while executing the putMap method", e);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @SuppressWarnings("unchecked")
+   public V remove(Serializable name) throws NullPointerException
+   {
+      if (name == null)
+      {
+         throw new NullPointerException("No null cache key accepted");
+      }      
+      V result = cache.remove(name);
+      onRemove((K)name, result);
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public List<V> removeCachedObjects()
+   {
+      final List<V> list = getCachedObjects();
+      clearCache();
+      return list;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void select(CachedObjectSelector<? super K, ? super V> selector) throws Exception
+   {
+      if (selector == null)
+      {
+         throw new IllegalArgumentException("No null selector");
+      }      
+      for (K key : cache.keySet())
+      {
+         if (key == null)
+         {
+            continue;
+         }
+         final V value = cache.withFlags(Flag.SKIP_LOCKING).get(key);
+         ObjectCacheInfo<V> info = new ObjectCacheInfo<V>()
+         {
+            public V get()
+            {
+               return value;
+            }
+
+            public long getExpireTime()
+            {
+               // Cannot know: The expire time is managed by Infinispan itself
+               return -1;
+            }
+         };
+         if (selector.select(key, info))
+         {
+            selector.onSelect(this, key, info);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setDistributed(boolean distributed)
+   {
+      this.distributed = distributed;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setLabel(String label)
+   {
+      this.label = label;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setLogEnabled(boolean logEnabled)
+   {
+      this.logEnabled = logEnabled;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setReplicated(boolean replicated)
+   {
+      this.replicated = replicated;
+   }
+
+   void onExpire(K key, V obj)
+   {
+      if (listeners.isEmpty())
+      {
+         return;
+      }
+      for (ListenerContext<K, V> context : listeners)
+      {
+         try
+         {
+            context.onExpire(key, obj);
+         }
+         catch (Exception e)
+         {
+            if (LOG.isWarnEnabled())
+               LOG.warn("Cannot execute the CacheListener properly", e);
+         }
+      }
+   }
+
+   void onRemove(K key, V obj)
+   {
+      if (listeners.isEmpty())
+      {
+         return;
+      }
+      for (ListenerContext<K, V> context : listeners)
+      {
+         try
+         {
+            context.onRemove(key, obj);
+         }
+         catch (Exception e)
+         {
+            if (LOG.isWarnEnabled())
+               LOG.warn("Cannot execute the CacheListener properly", e);
+         }
+      }
+   }
+
+   void onPut(K key, V obj)
+   {
+      if (listeners.isEmpty())
+      {
+         return;
+      }
+      for (ListenerContext<K, V> context : listeners)
+         try
+         {
+            context.onPut(key, obj);
+         }
+         catch (Exception e)
+         {
+            if (LOG.isWarnEnabled())
+               LOG.warn("Cannot execute the CacheListener properly", e);
+         }
+   }
+
+   void onGet(K key, V obj)
+   {
+      if (listeners.isEmpty())
+      {
+         return;
+      }
+      for (ListenerContext<K, V> context : listeners)
+         try
+         {
+            context.onGet(key, obj);
+         }
+         catch (Exception e)
+         {
+            if (LOG.isWarnEnabled())
+               LOG.warn("Cannot execute the CacheListener properly", e);
+         }
+   }
+
+   void onClearCache()
+   {
+      if (listeners.isEmpty())
+      {
+         return;
+      }
+      for (ListenerContext<K, V> context : listeners)
+         try
+         {
+            context.onClearCache();
+         }
+         catch (Exception e)
+         {
+            if (LOG.isWarnEnabled())
+               LOG.warn("Cannot execute the CacheListener properly", e);
+         }
+   }
+
+   @Listener
+   public class CacheEventListener
+   {
+      /**
+       * Warning Infinispan triggers a <code>CacheEntryEvictedEvent</code> only at explicit eviction
+       * that is done lazily which is not exactly what we expect, we still use it to be 
+       * able to use it with <code>avoidValueReplication</code> set to <code>true</code>.
+       */
+      @CacheEntriesEvicted
+      public void cacheEntryEvicted(CacheEntriesEvictedEvent<K, V> evt)
+      {
+         if (evt.isPre())
+         {
+            for (Map.Entry<K, V> entry : evt.getEntries().entrySet())
+            {
+               onExpire(entry.getKey(), entry.getValue());               
+            }
+         }
+      }
+
+      @CacheEntryRemoved
+      public void cacheEntryRemoved(CacheEntryRemovedEvent<K, V> evt)
+      {
+         if (evt.isPre() && !evt.isOriginLocal())
+         {
+            final K key = evt.getKey();
+            final V value = evt.getValue();
+            onRemove(key, value);
+         }
+      }
+
+      @CacheEntryModified
+      public void cacheEntryModified(CacheEntryModifiedEvent<K, V> evt)
+      {
+         if (!evt.isOriginLocal() && !evt.isPre())
+         {
+            final K key = evt.getKey();
+            final V value = evt.getValue();
+            onPut(key, value);
+         }
+      }
+   }
+   
+   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);
+      }
+   }
+}
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * This class is used to create the cache according to the given 
+ * configuration {@link org.exoplatform.services.cache.ExoCacheConfig}
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public interface ExoCacheCreator
+{
+
+   /**
+    * Creates an eXo cache according to the given configuration {@link org.exoplatform.services.cache.ExoCacheConfig}
+    * @param config the configuration of the cache to apply
+    * @param cacheConfig the configuration of the infinispan cache
+    * @param cacheGetter a {@link Callable} instance from which we can get the cache
+    * @exception ExoCacheInitException if an exception happens while initializing the cache
+    */
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig, 
+            Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException;
+
+   /**
+    * Returns the type of {@link org.exoplatform.services.cache.ExoCacheConfig} expected by the creator  
+    * @return the expected type
+    */
+   public Class<? extends ExoCacheConfig> getExpectedConfigType();
+
+   /**
+    * Returns a set of all the implementations expected by the creator. This is mainly used to be backward compatible
+    * @return the expected by the creator
+    */
+   public Set<String> getExpectedImplementations();
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreatorPlugin.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class allows us to define new creators
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class ExoCacheCreatorPlugin extends BaseComponentPlugin
+{
+
+   /**
+    * The list of all the creators defined for this ComponentPlugin
+    */
+   private final List<ExoCacheCreator> creators;
+
+   public ExoCacheCreatorPlugin(InitParams params)
+   {
+      creators = new ArrayList<ExoCacheCreator>();
+      List<?> configs = params.getObjectParamValues(ExoCacheCreator.class);
+      for (int i = 0; i < configs.size(); i++)
+      {
+         ExoCacheCreator config = (ExoCacheCreator)configs.get(i);
+         creators.add(config);
+      }
+   }
+
+   /**
+    * Returns all the creators defined for this ComponentPlugin
+    */
+   public List<ExoCacheCreator> getCreators()
+   {
+      return creators;
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryConfigPlugin.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This class is used to define custom configurations
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class ExoCacheFactoryConfigPlugin extends BaseComponentPlugin
+{
+
+   /**
+    * The map of all the creators defined for this ComponentPlugin
+    */
+   private final Map<String, String> configs;
+
+   public ExoCacheFactoryConfigPlugin(InitParams params)
+   {
+      configs = new HashMap<String, String>();
+      for (Iterator<ValueParam> iterator = params.getValueParamIterator(); iterator.hasNext();)
+      {
+         ValueParam vParam = iterator.next();
+         configs.put(vParam.getName(), vParam.getValue());
+      }
+   }
+
+   /**
+    * Returns all the configurations defined for this ComponentPlugin
+    */
+   public Map<String, String> getConfigs()
+   {
+      return configs;
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,458 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheFactory;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.jmx.MBeanServerLookup;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import javax.management.MBeanServer;
+
+/**
+ * This class is the Infinispan implementation of the {@link org.exoplatform.services.cache.ExoCacheFactory}
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class ExoCacheFactoryImpl implements ExoCacheFactory
+{
+
+   /**
+    * The logger
+    */
+   private static final Log LOG =
+      ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v4.ExoCacheFactoryImpl");
+
+   /**
+    * The initial parameter key that defines the full path of the configuration template
+    */
+   private static final String CACHE_CONFIG_TEMPLATE_KEY = "cache.config.template";
+
+   /**
+    * The current {@link ExoContainerContext}
+    */
+   private final ExoContainerContext ctx;
+   
+   /**
+    * The configuration manager that allows us to retrieve a configuration file in several different
+    * manners
+    */
+   private final ConfigurationManager configManager;
+
+   /**
+    * The {@link DefaultCacheManager} used for all the cache regions
+    */
+   private final DefaultCacheManager cacheManager;
+
+   /**
+    * The mapping between the configuration types and the creators
+    */
+   private final Map<Class<? extends ExoCacheConfig>, ExoCacheCreator> mappingConfigTypeCreators =
+      new HashMap<Class<? extends ExoCacheConfig>, ExoCacheCreator>();
+
+   /**
+    * The mapping between the implementations and the creators. This is mainly used for backward compatibility
+    */
+   private final Map<String, ExoCacheCreator> mappingImplCreators = new HashMap<String, ExoCacheCreator>();
+
+   /**
+    * The mapping between the cache names and the configuration paths
+    */
+   private final Map<String, String> mappingCacheNameConfig = new HashMap<String, String>();
+   
+   /**
+    * The mapping between the global configuration and the cache managers
+    */   
+   private final Map<GlobalConfiguration, DefaultCacheManager> mappingGlobalConfigCacheManager = 
+      new HashMap<GlobalConfiguration, DefaultCacheManager>(); 
+
+   /**
+    * The default creator
+    */
+   private final ExoCacheCreator defaultCreator = new GenericExoCacheCreator();
+   
+   private static final MBeanServerLookup MBEAN_SERVER_LOOKUP = new MBeanServerLookup()
+   {
+      public MBeanServer getMBeanServer(Properties properties)
+      {
+         return ExoContainerContext.getTopContainer().getMBeanServer();
+      }      
+   };
+
+   public ExoCacheFactoryImpl(ExoContainerContext ctx, InitParams params, ConfigurationManager configManager)
+      throws ExoCacheInitException
+   {
+      this(ctx, getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), configManager);
+   }
+
+   ExoCacheFactoryImpl(ExoContainerContext ctx, String cacheConfigTemplate, ConfigurationManager configManager)
+      throws ExoCacheInitException
+   {
+      this.ctx = ctx;
+      this.configManager = configManager;
+      if (cacheConfigTemplate == null)
+      {
+         throw new RuntimeException("The parameter '" + CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
+      }
+      // Initialize the main cache manager
+      this.cacheManager = initCacheManager(cacheConfigTemplate);
+      // Register the main cache manager
+      mappingGlobalConfigCacheManager.put(cacheManager.getGlobalConfiguration(), cacheManager);
+   }
+
+   /**
+    * Initializes the {@link DefaultCacheManager}
+    * @throws ExoCacheInitException if the cache manager cannot be initialized
+    */
+   private DefaultCacheManager initCacheManager(String cacheConfigTemplate)
+      throws ExoCacheInitException
+   {
+      InputStream is = null;
+      try
+      {
+         // Read the configuration file of the cache
+         is = configManager.getInputStream(cacheConfigTemplate);
+      }
+      catch (Exception e)
+      {
+         throw new ExoCacheInitException("The configuration of the CacheManager cannot be loaded from '"
+            + cacheConfigTemplate + "'", e);
+      }
+      if (is == null)
+      {
+         throw new ExoCacheInitException("The configuration of the CacheManager cannot be found at '"
+            + cacheConfigTemplate + "'");
+      }
+      DefaultCacheManager cacheManager = null;
+      try
+      {
+         // Create the CacheManager from the input stream
+         cacheManager = new DefaultCacheManager(is, false);
+      }
+      catch (Exception e)
+      {
+         throw new ExoCacheInitException("Cannot initialize the CacheManager corresponding to the configuration '"
+            + cacheConfigTemplate + "'", e);
+      }
+
+      GlobalConfiguration config = cacheManager.getGlobalConfiguration();
+      
+      configureCacheManager(config);
+      cacheManager.start();
+      return cacheManager;
+   }
+
+   /**
+    * Configure the cache manager
+    * 
+    * @param config
+    * @throws ExoCacheInitException
+    */
+   private void configureCacheManager(GlobalConfiguration config) throws ExoCacheInitException
+   {
+      // Configure JGroups
+      configureJGroups(config);
+      // Configure the name of the cache manager
+      config.fluent().globalJmxStatistics().cacheManagerName(config.getCacheManagerName() + "_" + ctx.getName()).
+      // Configure the MBeanServerLookup
+      mBeanServerLookup(MBEAN_SERVER_LOOKUP);
+   }
+
+   /**
+    * If some JGoups properties has been set, it will load the configuration and set
+    * the cluster name by adding as suffix the name of the {@link ExoContainerContext}
+    * 
+    * @param config the global configuration from which the JGroups config will be extracted
+    * @throws ExoCacheInitException if any exception occurs while configuring JGroups
+    */
+   private void configureJGroups(GlobalConfiguration config) throws ExoCacheInitException
+   {
+      if (loadJGroupsConfig(config))
+      {
+         // The JGroups Config could be loaded which means that the configuration is for a cluster
+         config.fluent().transport().clusterName(config.getClusterName() + "-" + ctx.getName());
+      }
+   }
+
+   /**
+    * Load the JGroups configuration file thanks to the {@link ConfigurationManager}
+    * @param config the global configuration from which the JGroups config will be extracted
+    * @return <code>true</code> if the JGoups config could be loaded successfully, 
+    * <code>false</code> if there were no JGroups config to load
+    * @throws ExoCacheInitException if the JGroups config could not be loaded
+    */
+   private boolean loadJGroupsConfig(GlobalConfiguration config) throws ExoCacheInitException
+   {
+      Properties properties = config.getTransportProperties();
+      if (properties == null || !properties.containsKey(JGroupsTransport.CONFIGURATION_FILE))
+      {
+         return false;
+      }
+      InputStream is;
+      String jgroupsFileLocation = properties.getProperty(JGroupsTransport.CONFIGURATION_FILE);
+      try
+      {
+         // Read the jgroups configuration file
+         URL url = configManager.getURL(jgroupsFileLocation);
+         is = url == null ? null : url.openStream();
+      }
+      catch (Exception e)
+      {
+         throw new ExoCacheInitException("The jgroups configuration cannot be loaded from '" + jgroupsFileLocation
+            + "'", e);
+      }
+      if (is != null)
+      {
+         try
+         {
+            // Set the jgroups configuration as XML
+            properties.setProperty(JGroupsTransport.CONFIGURATION_XML, readStream(is));
+         }
+         catch (IOException e)
+         {
+            throw new ExoCacheInitException("The jgroups configuration cannot be read from '" + jgroupsFileLocation
+               + "'");
+         }
+         // Remove the property corresponding to the configuration file
+         properties.remove(JGroupsTransport.CONFIGURATION_FILE);
+      }
+      return true;
+   }
+
+   /**
+    * Reads bytes from input stream and builds a string from them
+    * 
+    * @param inputStream
+    * @return
+    * @throws IOException
+    */
+   protected String readStream(InputStream inputStream) throws IOException
+   {
+      StringBuilder out = new StringBuilder(4096);
+      byte[] b = new byte[4096];
+      try
+      {
+         for (int length; (length = inputStream.read(b)) != -1;)
+         {
+            out.append(new String(b, 0, length));
+         }
+      }
+      finally
+      {
+         try
+         {
+            inputStream.close();
+         }
+         catch (Exception e)
+         {
+            LOG.debug("Cannot close stream", e);
+         }
+      }
+      return out.toString();
+   }
+
+   /**
+    * To create a new cache instance according to the given configuration, we follow the steps below:
+    * 
+    * We first try to find if a specific location of the cache configuration has been defined thanks
+    * to an external component plugin of type ExoCacheFactoryConfigPlugin. If so we use the default cache
+    * configuration defined in this file otherwise we use the default cache configuration defined in
+    * "${CACHE_CONFIG_TEMPLATE_KEY}"
+    */
+   public ExoCache<Serializable, Object> createCache(ExoCacheConfig config) throws ExoCacheInitException
+   {
+      final String region = config.getName();
+      final String customConfig = mappingCacheNameConfig.get(region);
+      final ExoCache<Serializable, Object> eXoCache;
+      final DefaultCacheManager cacheManager;
+      try
+      {
+         final Configuration conf;
+         if (customConfig != null)
+         {
+            // A custom configuration has been set
+            if (LOG.isInfoEnabled())
+               LOG.info("A custom configuration has been set for the cache '" + region + "'.");
+            // Create the CacheManager by loading the configuration
+            DefaultCacheManager customCacheManager = new DefaultCacheManager(configManager.getInputStream(customConfig), false);
+            GlobalConfiguration gc = customCacheManager.getGlobalConfiguration();
+            // Configure JGroups and JMX since it could affect the state of the Global Config
+            configureCacheManager(gc);
+            // Check if a CacheManager with the same GlobalConfiguration exists
+            DefaultCacheManager currentCacheManager = mappingGlobalConfigCacheManager.get(gc);
+            if (currentCacheManager == null)
+            {
+               // No cache manager has been defined so far for this Cache Configuration
+               currentCacheManager = customCacheManager;
+               // Use a different cache manager name to prevent naming conflict
+               gc.fluent().globalJmxStatistics().cacheManagerName(gc.getCacheManagerName() + "_" + region + "_" + ctx.getName());
+               currentCacheManager.start();
+               // We register this new cache manager
+               mappingGlobalConfigCacheManager.put(gc, customCacheManager);
+            }
+            conf = currentCacheManager.getDefaultConfiguration().clone();
+            cacheManager = currentCacheManager;
+         }
+         else
+         {
+            cacheManager = this.cacheManager;
+            // No custom configuration has been found, a configuration template will be used 
+            if (LOG.isInfoEnabled())
+               LOG.info("The configuration template will be used for the the cache '" + region + "'.");
+            conf = cacheManager.getDefaultConfiguration().clone();
+            if (!config.isDistributed() && !config.isRepicated())
+            {
+               // The cache is local
+               conf.fluent().clustering().mode(CacheMode.LOCAL);
+            }
+         }
+         // Reset the configuration to avoid conflicts
+         resetConfiguration(conf);
+         final ExoCacheCreator creator = getExoCacheCreator(config);
+         // Create the cache
+         eXoCache = creator.create(config, conf, new Callable<Cache<Serializable, Object>>()
+         {
+            @Override
+            public Cache<Serializable, Object> call() throws Exception
+            {
+               // Define the configuration
+               cacheManager.defineConfiguration(region, conf);
+               // create and start the cache                 
+               return cacheManager.getCache(region);
+            }
+         });
+      }
+      catch (Exception e)
+      {
+         throw new ExoCacheInitException("The cache '" + region + "' could not be initialized", e);
+      }
+      return eXoCache;
+   }
+
+   /**
+    * Add a list of creators to register
+    * @param plugin the plugin that contains the creators
+    */
+   public void addCreator(ExoCacheCreatorPlugin plugin)
+   {
+      final List<ExoCacheCreator> creators = plugin.getCreators();
+      for (ExoCacheCreator creator : creators)
+      {
+         mappingConfigTypeCreators.put(creator.getExpectedConfigType(), creator);
+         Set<String> implementations = creator.getExpectedImplementations();
+         if (implementations == null)
+         {
+            throw new NullPointerException("The set of implementations cannot be null");
+         }
+         for (String imp : implementations)
+         {
+            mappingImplCreators.put(imp, creator);
+         }
+      }
+   }
+
+   /**
+    * Add a list of custom configuration to register
+    * @param plugin the plugin that contains the configs
+    */
+   public void addConfig(ExoCacheFactoryConfigPlugin plugin)
+   {
+      final Map<String, String> configs = plugin.getConfigs();
+      mappingCacheNameConfig.putAll(configs);
+   }
+
+   /**
+    * Returns the value of the ValueParam if and only if the value is not empty
+    */
+   private static String getValueParam(InitParams params, String key)
+   {
+      if (params == null)
+      {
+         return null;
+      }
+      final ValueParam vp = params.getValueParam(key);
+      String result;
+      if (vp == null || (result = vp.getValue()) == null || (result = result.trim()).length() == 0)
+      {
+         return null;
+      }
+      return result;
+   }
+
+   /**
+    * Returns the most relevant ExoCacheCreator according to the give configuration
+    */
+   protected ExoCacheCreator getExoCacheCreator(ExoCacheConfig config)
+   {
+      ExoCacheCreator creator = mappingConfigTypeCreators.get(config.getClass());
+      if (creator == null)
+      {
+         // No creator for this type has been found, let's try the implementation field
+         creator = mappingImplCreators.get(config.getImplementation());
+         if (creator == null)
+         {
+            // No creator can be found, we will use the default creator
+            if (LOG.isInfoEnabled())
+               LOG.info("No cache creator has been found for the the cache '" + config.getName()
+                  + "', the default one will be used.");
+            return defaultCreator;
+         }
+      }
+      if (LOG.isInfoEnabled())
+         LOG.info("The cache '" + config.getName() + "' will be created with '" + creator.getClass() + "'.");
+      return creator;
+   }
+
+   /**
+    * Clean the configuration template to prevent conflicts
+    */
+   protected void resetConfiguration(Configuration config)
+   {
+      config.fluent().invocationBatching().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration()
+         .lifespan(-1L).maxIdle(-1L).wakeUpInterval(60000L);
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheConfig.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2010 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.infinispan.generic;
+
+import org.exoplatform.services.cache.ExoCacheConfig;
+
+/**
+ * The {@link org.exoplatform.services.cache.ExoCacheConfig} for all the eviction algorithms 
+ * available in infinispan
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class GenericExoCacheConfig extends ExoCacheConfig
+{
+
+   private String strategy;
+   
+   private int maxEntries;
+   
+   private long lifespan;
+   
+   private long maxIdle;
+
+   private long wakeUpInterval;
+   
+   /**
+    * @return the strategy
+    */
+   public String getStrategy()
+   {
+      return strategy;
+   }
+
+   /**
+    * @param strategy the strategy to set
+    */
+   public void setStrategy(String strategy)
+   {
+      this.strategy = strategy;
+   }
+
+   /**
+    * @return the wakeUpInterval
+    */
+   public long getWakeUpInterval()
+   {
+      return wakeUpInterval;
+   }
+
+   /**
+    * @param wakeUpInterval the wakeUpInterval to set
+    */
+   public void setWakeUpInterval(long wakeUpInterval)
+   {
+      this.wakeUpInterval = wakeUpInterval;
+   }
+
+   /**
+    * @return the maxEntries
+    */
+   public int getMaxEntries()
+   {
+      return maxEntries;
+   }
+
+   /**
+    * @param maxEntries the maxEntries to set
+    */
+   public void setMaxEntries(int maxEntries)
+   {
+      this.maxEntries = maxEntries;
+   }
+
+   /**
+    * @return the lifespan
+    */
+   public long getLifespan()
+   {
+      return lifespan;
+   }
+
+   /**
+    * @param lifespan the lifespan to set
+    */
+   public void setLifespan(long lifespan)
+   {
+      this.lifespan = lifespan;
+   }
+
+   /**
+    * @return the maxIdle
+    */
+   public long getMaxIdle()
+   {
+      return maxIdle;
+   }
+
+   /**
+    * @param maxIdle the maxIdle to set
+    */
+   public void setMaxIdle(long maxIdle)
+   {
+      this.maxIdle = maxIdle;
+   }
+}
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2010 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.infinispan.generic;
+
+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.infinispan.AbstractExoCache;
+import org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.eviction.EvictionStrategy;
+
+import java.io.Serializable;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * The generic {@link ExoCacheCreator} for all the expiration available in infinispan.
+ * 
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class GenericExoCacheCreator implements ExoCacheCreator
+{
+
+   /**
+    * The default value for the eviction strategy
+    */
+   protected String defaultStrategy = "LRU";
+
+   /**
+    * The default value for maxIdle
+    */
+   protected long defaultMaxIdle = -1;
+
+   /**
+    * The default value for wakeUpInterval
+    */
+   protected long defaultWakeUpInterval = 5000;
+
+   /**
+    * A set of all the implementations supported by this creator
+    */
+   protected Set<String> implementations;
+
+   /**
+    * {@inheritDoc}
+    */
+   public Set<String> getExpectedImplementations()
+   {
+      return implementations;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Class<? extends ExoCacheConfig> getExpectedConfigType()
+   {
+      return GenericExoCacheConfig.class;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+      Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException
+   {
+      if (config instanceof GenericExoCacheConfig)
+      {
+         final GenericExoCacheConfig gConfig = (GenericExoCacheConfig)config;
+         return create(config, cacheConfig, cacheGetter, gConfig.getStrategy(), gConfig.getMaxEntries(), gConfig
+            .getLifespan(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle : gConfig.getMaxIdle(), gConfig
+            .getWakeUpInterval() == 0 ? defaultWakeUpInterval : gConfig.getWakeUpInterval());
+      }
+      else
+      {
+         final long period = config.getLiveTime();
+         return create(config, cacheConfig, cacheGetter, config.getImplementation() == null ? defaultStrategy : config
+            .getImplementation(), config.getMaxSize(), period > 0 ? period * 1000 : -1, defaultMaxIdle,
+            defaultWakeUpInterval);
+      }
+   }
+
+   /**
+    * Creates a new ExoCache instance with the relevant parameters
+    * @throws ExoCacheInitException If any exception occurs while creating the cache
+    */
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+      Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle,
+      long wakeUpInterval) throws ExoCacheInitException
+   {
+      EvictionStrategy es = strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy.toUpperCase(Locale.ENGLISH));
+      if (es == null)
+      {
+         es = EvictionStrategy.LRU;
+      }
+      cacheConfig.fluent().eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration()
+         .lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval);
+      try
+      {
+         return new GenericExoCache(cacheConfig, config, cacheGetter.call());
+      }
+      catch (Exception e)
+      {
+         throw new ExoCacheInitException("Cannot create the cache '" + config.getName() + "'", e);
+      }
+   }
+
+   /**
+    * The Generic implementation of an ExoCache
+    */
+   public static class GenericExoCache extends AbstractExoCache<Serializable, Object>
+   {
+
+      private final Configuration cacheConfig;
+
+      public GenericExoCache(Configuration cacheConfig, ExoCacheConfig config, Cache<Serializable, Object> cache)
+      {
+         super(config, cache);
+         this.cacheConfig = cacheConfig;
+      }
+
+      public void setMaxSize(int max)
+      {
+         cacheConfig.fluent().eviction().maxEntries(max);
+      }
+
+      public void setLiveTime(long period)
+      {
+         cacheConfig.fluent().expiration().lifespan(period);
+      }
+
+      public void setMaxIdle(long maxIdle)
+      {
+         cacheConfig.fluent().expiration().maxIdle(maxIdle);
+      }
+
+      public void setWakeUpInterval(long wakeUpInterval)
+      {
+         cacheConfig.fluent().expiration().wakeUpInterval(wakeUpInterval);
+      }
+
+      @ManagedName("MaxEntries")
+      @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.")
+      public int getMaxSize()
+      {
+         return cacheConfig.getEvictionMaxEntries();
+      }
+
+      @ManagedName("Lifespan")
+      @ManagedDescription("Maximum lifespan of a cache entry, after which the entry is expired cluster-wide." +
+            " -1 means the entries never expire.")
+      public long getLiveTime()
+      {
+         return cacheConfig.getExpirationLifespan();
+      }
+
+      @Managed
+      @ManagedName("MaxIdle")
+      @ManagedDescription("Maximum idle time a cache entry will be maintained in the cache. " +
+            "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.")
+      public long getMaxIdle()
+      {
+         return cacheConfig.getExpirationMaxIdle();
+      }
+
+      @Managed
+      @ManagedName("WakeUpInterval")
+      @ManagedDescription("Interval between subsequent eviction runs. If you wish to disable the periodic eviction " +
+            "process altogether, set wakeupInterval to -1.")
+      public long getWakeUpInterval()
+      {
+         return cacheConfig.getExpirationWakeUpInterval();
+      }
+   }
+}
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (C) 2010 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:5.0 http://www.infinispan.org/schemas/infinispan-config-5.0.xsd"
+	xmlns="urn:infinispan:config:5.0">
+   <global>
+      <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="maxThreads" value="1"/>
+            <property name="queueSize" value="100000"/>
+            <property name="threadNamePrefix" value="AsyncListenerThread"/>
+         </properties>
+      </asyncListenerExecutor>
+      <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+         </properties>
+      </asyncTransportExecutor>
+      <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="EvictionThread"/>
+         </properties>
+      </evictionScheduledExecutor>
+      <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+         </properties>
+      </replicationQueueScheduledExecutor>
+      <globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/>
+      <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="eXoCache-cluster" distributedSyncTimeout="20000">
+      	<properties>
+         <property name="configurationFile" value="flush-udp.xml"/>
+      	</properties>
+      </transport>
+      <shutdown hookBehavior="DEFAULT"/>
+   </global>
+   <default>
+      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+      <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+      <jmxStatistics enabled="true"/>
+      <invocationBatching enabled="true"/>
+      <clustering mode="replication">
+         <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+         <sync replTimeout="20000"/>
+      </clustering>
+   </default>
+</infinispan>
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/configuration.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/configuration.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    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.
+
+-->
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_0.xsd http://www.exoplatform.org/xml/ns/kernel_1_0.xsd"
+   xmlns="http://www.exoplatform.org/xml/ns/kernel_1_0.xsd">
+   <component>
+      <key>org.exoplatform.services.cache.ExoCacheFactory</key>
+      <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl</type>
+      <init-params>
+         <value-param>
+            <name>cache.config.template</name>
+            <value>jar:/conf/portal/cache-configuration-template.xml</value>
+         </value-param>
+      </init-params>
+   </component>
+</configuration>

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,752 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CacheListenerContext;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.CachedObjectSelector;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheFactory;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.exoplatform.services.cache.ObjectCacheInfo;
+import org.exoplatform.test.BasicTestCase;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestAbstractExoCache extends BasicTestCase
+{
+
+   CacheService service;
+
+   AbstractExoCache<Serializable, Object> cache;
+
+   public TestAbstractExoCache(String name)
+   {
+      super(name);
+   }
+
+   public void setUp() throws Exception
+   {
+      this.service = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
+      this.cache = (AbstractExoCache<Serializable, Object>)service.getCacheInstance("myCache");
+   }
+
+   public void testPut() throws Exception
+   {
+      cache.put(new MyKey("a"), "a");
+      cache.put(new MyKey("b"), "b");
+      cache.put(new MyKey("c"), "c");
+      assertEquals(3, cache.getCacheSize());
+      cache.put(new MyKey("a"), "c");
+      assertEquals(3, cache.getCacheSize());
+      cache.put(new MyKey("d"), "c");
+      assertEquals(4, cache.getCacheSize());
+
+      cache.clearCache();
+   }
+
+   public void testClearCache() throws Exception
+   {
+      cache.put(new MyKey("a"), "a");
+      cache.put(new MyKey("b"), "b");
+      cache.put(new MyKey("c"), "c");
+      assertTrue(cache.getCacheSize() > 0);
+      cache.clearCache();
+      assertTrue(cache.getCacheSize() == 0);
+
+      cache.clearCache();
+   }
+
+   public void testGet() throws Exception
+   {
+      cache.put(new MyKey("a"), "a");
+      assertEquals("a", cache.get(new MyKey("a")));
+      cache.put(new MyKey("a"), "c");
+      assertEquals("c", cache.get(new MyKey("a")));
+      cache.remove(new MyKey("a"));
+      assertEquals(null, cache.get(new MyKey("a")));
+      assertEquals(null, cache.get(new MyKey("x")));
+
+      cache.clearCache();
+   }
+
+   public void testRemove() throws Exception
+   {
+      cache.put(new MyKey("a"), 1);
+      cache.put(new MyKey("b"), 2);
+      cache.put(new MyKey("c"), 3);
+      assertEquals(3, cache.getCacheSize());
+      assertEquals(1, cache.remove(new MyKey("a")));
+      assertEquals(2, cache.getCacheSize());
+      assertEquals(2, cache.remove(new MyKey("b")));
+      assertEquals(1, cache.getCacheSize());
+      assertEquals(null, cache.remove(new MyKey("x")));
+      assertEquals(1, cache.getCacheSize());
+
+      cache.clearCache();
+   }
+
+   public void testPutMap() throws Exception
+   {
+      Map<Serializable, Object> values = new HashMap<Serializable, Object>();
+      values.put(new MyKey("a"), "a");
+      values.put(new MyKey("b"), "b");
+      assertEquals(0, cache.getCacheSize());
+      cache.putMap(values);
+      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());
+            set.add(new Entry<Serializable, Object>()
+            {
+
+               public Object setValue(Object paramV)
+               {
+                  return null;
+               }
+
+               public Object getValue()
+               {
+                  throw new RuntimeException("An exception");
+               }
+
+               public Serializable getKey()
+               {
+                  return "c";
+               }
+            });
+            return set;
+         }
+      };
+      values.put(new MyKey("e"), "e");
+      values.put(new MyKey("d"), "d");
+      cache.putMap(values);
+      assertEquals(2, cache.getCacheSize());
+
+      cache.clearCache();
+   }
+
+   public void testGetCachedObjects() throws Exception
+   {
+      cache.put(new MyKey("a"), "a");
+      cache.put(new MyKey("b"), "b");
+      cache.put(new MyKey("c"), "c");
+      cache.put(new MyKey("d"), null);
+      assertEquals(3, cache.getCacheSize());
+      List<Object> values = cache.getCachedObjects();
+      assertEquals(3, values.size());
+      assertTrue(values.contains("a"));
+      assertTrue(values.contains("b"));
+      assertTrue(values.contains("c"));
+
+      cache.clearCache();
+   }
+
+   public void testRemoveCachedObjects() throws Exception
+   {
+      cache.put(new MyKey("a"), "a");
+      cache.put(new MyKey("b"), "b");
+      cache.put(new MyKey("c"), "c");
+      cache.put(new MyKey("d"), null);
+      assertEquals(3, cache.getCacheSize());
+      List<Object> values = cache.removeCachedObjects();
+      assertEquals(3, values.size());
+      assertTrue(values.contains("a"));
+      assertTrue(values.contains("b"));
+      assertTrue(values.contains("c"));
+      assertEquals(0, cache.getCacheSize());
+
+      cache.clearCache();
+   }
+
+   public void testSelect() throws Exception
+   {
+      cache.put(new MyKey("a"), 1);
+      cache.put(new MyKey("b"), 2);
+      cache.put(new MyKey("c"), 3);
+      final AtomicInteger count = new AtomicInteger();
+      CachedObjectSelector<Serializable, Object> selector = new CachedObjectSelector<Serializable, Object>()
+      {
+
+         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<? extends Object> ocinfo)
+         {
+            return true;
+         }
+      };
+      cache.select(selector);
+      assertEquals(3, count.intValue());
+
+      cache.clearCache();
+   }
+
+   public void testGetHitsNMisses() throws Exception
+   {
+      int hits = cache.getCacheHit();
+      int misses = cache.getCacheMiss();
+      cache.put(new MyKey("a"), "a");
+      cache.get(new MyKey("a"));
+      cache.remove(new MyKey("a"));
+      cache.get(new MyKey("a"));
+      cache.get(new MyKey("z"));
+      assertEquals(1, cache.getCacheHit() - hits);
+      assertEquals(2, cache.getCacheMiss() - misses);
+
+      cache.clearCache();
+   }
+
+   private ExoCacheFactory getExoCacheFactoryInstance() throws ExoCacheInitException
+   {
+      PortalContainer pc = PortalContainer.getInstance();
+      return new ExoCacheFactoryImpl((ExoContainerContext)pc.getComponentInstanceOfType(ExoContainerContext.class),
+         "jar:/conf/portal/cache-configuration-template.xml", (ConfigurationManager)pc
+            .getComponentInstanceOfType(ConfigurationManager.class));
+   }
+
+   public void testMultiThreading() throws Exception
+   {
+      long time = System.currentTimeMillis();
+      final ExoCache<Serializable, Object> cache = service.getCacheInstance("test-multi-threading");
+      final int totalElement = 100;
+      final int totalTimes = 20;
+      int reader = 20;
+      int writer = 10;
+      int remover = 5;
+      int cleaner = 1;
+      final CountDownLatch startSignalWriter = new CountDownLatch(1);
+      final CountDownLatch startSignalOthers = new CountDownLatch(1);
+      final CountDownLatch doneSignal = new CountDownLatch(reader + writer + remover);
+      final List<Exception> errors = Collections.synchronizedList(new ArrayList<Exception>());
+      for (int i = 0; i < writer; i++)
+      {
+         final int index = i;
+         Thread thread = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  startSignalWriter.await();
+                  for (int j = 0; j < totalTimes; j++)
+                  {
+                     for (int i = 0; i < totalElement; i++)
+                     {
+                        cache.put(new MyKey("key" + i), "value" + i);
+                     }
+                     if (index == 0 && j == 0)
+                     {
+                        // The cache is full, we can launch the others
+                        startSignalOthers.countDown();
+                     }
+                     sleep(50);
+                  }
+               }
+               catch (Exception e)
+               {
+                  errors.add(e);
+               }
+               finally
+               {
+                  doneSignal.countDown();
+               }
+            }
+         };
+         thread.start();
+      }
+      startSignalWriter.countDown();
+      for (int i = 0; i < reader; i++)
+      {
+         Thread thread = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  startSignalOthers.await();
+                  for (int j = 0; j < totalTimes; j++)
+                  {
+                     for (int i = 0; i < totalElement; i++)
+                     {
+                        cache.get(new MyKey("key" + i));
+                     }
+                     sleep(50);
+                  }
+               }
+               catch (Exception e)
+               {
+                  errors.add(e);
+               }
+               finally
+               {
+                  doneSignal.countDown();
+               }
+            }
+         };
+         thread.start();
+      }
+      for (int i = 0; i < remover; i++)
+      {
+         Thread thread = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  startSignalOthers.await();
+                  for (int j = 0; j < totalTimes; j++)
+                  {
+                     for (int i = 0; i < totalElement; i++)
+                     {
+                        cache.remove(new MyKey("key" + i));
+                     }
+                     sleep(50);
+                  }
+               }
+               catch (Exception e)
+               {
+                  errors.add(e);
+               }
+               finally
+               {
+                  doneSignal.countDown();
+               }
+            }
+         };
+         thread.start();
+      }
+      doneSignal.await();
+      for (int i = 0; i < totalElement; i++)
+      {
+         cache.put(new MyKey("key" + i), "value" + i);
+      }
+      assertEquals(totalElement, cache.getCacheSize());
+      final CountDownLatch startSignal = new CountDownLatch(1);
+      final CountDownLatch doneSignal2 = new CountDownLatch(writer + cleaner);
+      for (int i = 0; i < writer; i++)
+      {
+         Thread thread = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  startSignal.await();
+                  for (int j = 0; j < totalTimes; j++)
+                  {
+                     for (int i = 0; i < totalElement; i++)
+                     {
+                        cache.put(new MyKey("key" + i), "value" + i);
+                     }
+                     sleep(50);
+                  }
+               }
+               catch (Exception e)
+               {
+                  errors.add(e);
+               }
+               finally
+               {
+                  doneSignal2.countDown();
+               }
+            }
+         };
+         thread.start();
+      }
+      for (int i = 0; i < cleaner; i++)
+      {
+         Thread thread = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  startSignal.await();
+                  for (int j = 0; j < totalTimes; j++)
+                  {
+                     sleep(150);
+                     cache.clearCache();
+                  }
+               }
+               catch (Exception e)
+               {
+                  errors.add(e);
+               }
+               finally
+               {
+                  doneSignal2.countDown();
+               }
+            }
+         };
+         thread.start();
+      }
+      cache.clearCache();
+      assertEquals(0, cache.getCacheSize());
+      if (!errors.isEmpty())
+      {
+         for (Exception e : errors)
+         {
+            e.printStackTrace();
+         }
+         throw errors.get(0);
+      }
+      System.out.println("Total Time = " + (System.currentTimeMillis() - time));
+
+      cache.clearCache();
+   }
+
+   public static class MyCacheListener implements CacheListener<Serializable, Object>
+   {
+
+      public int clearCache;
+
+      public int expire;
+
+      public int get;
+
+      public int put;
+
+      public int remove;
+
+      public void onClearCache(ExoCache<Serializable, Object> cache) throws Exception
+      {
+         clearCache++;
+      }
+
+      public void onExpire(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+      {
+         expire++;
+      }
+
+      public void onGet(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+      {
+         get++;
+      }
+
+      public void onPut(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+      {
+         put++;
+      }
+
+      public void onRemove(ExoCache<Serializable, Object> cache, Serializable key, Object obj) throws Exception
+      {
+         remove++;
+      }
+
+      public void onClearCache(CacheListenerContext context) throws Exception
+      {
+         clearCache++;
+      }
+
+      public void onExpire(CacheListenerContext context, Serializable key, Object obj) throws Exception
+      {
+         expire++;
+      }
+
+      public void onGet(CacheListenerContext context, Serializable key, Object obj) throws Exception
+      {
+         get++;
+      }
+
+      public void onPut(CacheListenerContext context, Serializable key, Object obj) throws Exception
+      {
+         put++;
+      }
+
+      public void onRemove(CacheListenerContext context, Serializable key, Object obj) throws Exception
+      {
+         remove++;
+      }
+   }
+
+   public static class MyKey implements Serializable
+   {
+      private static final long serialVersionUID = 1L;
+
+      public String value;
+
+      public MyKey(String value)
+      {
+         this.value = value;
+      }
+
+      @Override
+      public boolean equals(Object paramObject)
+      {
+         return paramObject instanceof MyKey && ((MyKey)paramObject).value.endsWith(value);
+      }
+
+      @Override
+      public int hashCode()
+      {
+         return value.hashCode();
+      }
+
+      @Override
+      public String toString()
+      {
+         return value;
+      }
+   }   
+
+   @SuppressWarnings("unchecked")
+   public void testDistributedCache() throws Exception
+   {
+      // If the cache is still alive this test fails due to a TimeoutException.
+      cache.cache.getCacheManager().stop();
+      
+      System.out
+         .println("WARNING: For Linux distributions the following JVM parameter must be set to true, java.net.preferIPv4Stack = "
+            + System.getProperty("java.net.preferIPv4Stack"));
+      ExoCacheConfig config = new ExoCacheConfig();
+      config.setName("MyCacheDistributed");
+      config.setMaxSize(5);
+      config.setLiveTime(1);
+      config.setImplementation("LRU");
+      config.setDistributed(true);
+      ExoCacheConfig config2 = new ExoCacheConfig();
+      config2.setName("MyCacheDistributed2");
+      config2.setMaxSize(5);
+      config2.setLiveTime(1);
+      config2.setImplementation("LRU");
+      config2.setDistributed(true);
+      AbstractExoCache<Serializable, Object> cache1 =
+         (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config);
+      MyCacheListener listener1 = new MyCacheListener();
+      cache1.addCacheListener(listener1);
+      AbstractExoCache<Serializable, Object> cache2 =
+         (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config);
+      MyCacheListener listener2 = new MyCacheListener();
+      cache2.addCacheListener(listener2);
+// Cache 3 creates a conflict with cache 1 and 2      
+//      AbstractExoCache<Serializable, Object> cache3 =
+//         (AbstractExoCache<Serializable, Object>)getExoCacheFactoryInstance().createCache(config2);
+//      MyCacheListener listener3 = new MyCacheListener();
+//      cache3.addCacheListener(listener3);
+      try
+      {
+         cache1.put(new MyKey("a"), "b");
+         assertEquals(1, cache1.getCacheSize());
+         assertEquals("b", cache2.get(new MyKey("a")));
+         assertEquals(1, cache2.getCacheSize());
+//         assertEquals(0, cache3.getCacheSize());
+         assertEquals(1, listener1.put);
+         assertEquals(1, listener2.put);
+//         assertEquals(0, listener3.put);
+         assertEquals(0, listener1.get);
+         assertEquals(1, listener2.get);
+//         assertEquals(0, listener3.get);
+         cache2.put(new MyKey("b"), "c");
+         assertEquals(2, cache1.getCacheSize());
+         assertEquals(2, cache2.getCacheSize());
+         assertEquals("c", cache1.get(new MyKey("b")));
+//         assertEquals(0, cache3.getCacheSize());
+         assertEquals(2, listener1.put);
+         assertEquals(2, listener2.put);
+//         assertEquals(0, listener3.put);
+         assertEquals(1, listener1.get);
+         assertEquals(1, listener2.get);
+//         assertEquals(0, listener3.get);
+//         cache3.put(new MyKey("c"), "d");
+         assertEquals(2, cache1.getCacheSize());
+         assertEquals(2, cache2.getCacheSize());
+//         assertEquals(1, cache3.getCacheSize());
+//         assertEquals("d", cache3.get(new MyKey("c")));
+         assertEquals(2, listener1.put);
+         assertEquals(2, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(1, listener1.get);
+         assertEquals(1, listener2.get);
+//         assertEquals(1, listener3.get);
+         cache2.put(new MyKey("a"), "a");
+         assertEquals(2, cache1.getCacheSize());
+         assertEquals(2, cache2.getCacheSize());
+         assertEquals("a", cache1.get(new MyKey("a")));
+         assertEquals(3, listener1.put);
+         assertEquals(3, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(2, listener1.get);
+         assertEquals(1, listener2.get);
+//         assertEquals(1, listener3.get);
+         cache2.remove(new MyKey("a"));
+         assertEquals(1, cache1.getCacheSize());
+         assertEquals(1, cache2.getCacheSize());
+         assertEquals(3, listener1.put);
+         assertEquals(3, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(2, listener1.get);
+         assertEquals(1, listener2.get);
+//         assertEquals(1, listener3.get);
+         assertEquals(1, listener1.remove);
+         assertEquals(1, listener2.remove);
+//         assertEquals(0, listener3.remove);
+         cache1.put(new MyKey("c"), "c");
+         cache1.clearCache();
+         assertEquals(0, cache1.getCacheSize());
+         assertEquals(null, cache1.get(new MyKey("b")));
+         assertEquals("c", cache2.get(new MyKey("b")));
+         assertEquals("c", cache2.get(new MyKey("c")));
+         assertEquals(2, cache2.getCacheSize());
+         assertEquals(4, listener1.put);
+         assertEquals(4, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(3, listener1.get);
+         assertEquals(3, listener2.get);
+//         assertEquals(1, listener3.get);
+         assertEquals(1, listener1.remove);
+         assertEquals(1, listener2.remove);
+//         assertEquals(0, listener3.remove);
+         assertEquals(1, listener1.clearCache);
+         assertEquals(0, listener2.clearCache);
+//         assertEquals(0, listener3.clearCache);
+         Map<Serializable, Object> values = new HashMap<Serializable, Object>();
+         values.put(new MyKey("a"), "a");
+         values.put(new MyKey("b"), "b");
+         cache1.putMap(values);
+         assertEquals(2, cache1.getCacheSize());
+         Thread.sleep(40);
+         assertEquals("a", cache2.get(new MyKey("a")));
+         assertEquals("b", cache2.get(new MyKey("b")));
+         assertEquals(3, cache2.getCacheSize());
+         assertEquals(6, listener1.put);
+         assertEquals(6, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(3, listener1.get);
+         assertEquals(5, listener2.get);
+//         assertEquals(1, listener3.get);
+         assertEquals(1, listener1.remove);
+         assertEquals(1, listener2.remove);
+//         assertEquals(0, listener3.remove);
+         assertEquals(1, listener1.clearCache);
+         assertEquals(0, listener2.clearCache);
+//         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());
+               set.add(new Entry<Serializable, Object>()
+               {
+
+                  public Object setValue(Object paramV)
+                  {
+                     return null;
+                  }
+
+                  public Object getValue()
+                  {
+                     throw new RuntimeException("An exception");
+                  }
+
+                  public Serializable getKey()
+                  {
+                     return "c";
+                  }
+               });
+               return set;
+            }
+         };
+         values.put(new MyKey("e"), "e");
+         values.put(new MyKey("d"), "d");
+         cache1.putMap(values);
+         assertEquals(2, cache1.getCacheSize());
+         assertEquals(3, cache2.getCacheSize());
+//         assertEquals(1, cache3.getCacheSize());
+         assertEquals(6, listener1.put);
+         assertEquals(6, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(3, listener1.get);
+         assertEquals(5, listener2.get);
+//         assertEquals(1, listener3.get);
+         assertEquals(1, listener1.remove);
+         assertEquals(1, listener2.remove);
+//         assertEquals(0, listener3.remove);
+         assertEquals(1, listener1.clearCache);
+         assertEquals(0, listener2.clearCache);
+//         assertEquals(0, listener3.clearCache);
+         assertEquals(0, listener1.expire);
+         assertEquals(0, listener2.expire);
+//         assertEquals(0, listener3.expire);
+         Thread.sleep(5600);
+         // The values are evicted lazily when we call it
+         cache1.get(new MyKey("a"));
+         cache1.get(new MyKey("b"));
+         cache2.get(new MyKey("a"));
+         cache2.get(new MyKey("b"));
+         cache2.get(new MyKey("c"));
+         assertEquals(0, cache1.getCacheSize());
+         assertEquals(0, cache2.getCacheSize());
+//         assertEquals(0, cache3.getCacheSize());
+         assertEquals(6, listener1.put);
+         assertEquals(6, listener2.put);
+//         assertEquals(1, listener3.put);
+         assertEquals(5, listener1.get);
+         assertEquals(8, listener2.get);
+//         assertEquals(1, listener3.get);
+         assertEquals(1, listener1.remove);
+         assertEquals(1, listener2.remove);
+//         assertEquals(0, listener3.remove);
+         assertEquals(1, listener1.clearCache);
+         assertEquals(0, listener2.clearCache);
+//         assertEquals(0, listener3.clearCache);
+// Expiration events are not triggered in infinispan         
+//         assertEquals(2, listener1.expire);
+//         assertEquals(3, listener2.expire);
+//         assertEquals(1, listener3.expire);
+      }
+      finally
+      {
+         cache1.cache.getCacheManager().stop();
+         cache2.cache.getCacheManager().stop();
+//         cache3.cache.getCacheManager().stop();
+      }
+   }   
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheConfig.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.services.cache.ExoCacheConfig;
+
+/**
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheConfig extends ExoCacheConfig
+{
+
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.services.cache.CacheListener;
+import org.exoplatform.services.cache.CachedObjectSelector;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.ExoCacheInitException;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheCreator implements ExoCacheCreator
+{
+
+   /**
+    * @see org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig, org.infinispan.config.Configuration, java.util.concurrent.Callable)
+    */
+   @Override
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+      Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException
+   {
+      return new TestExoCache();
+   }
+
+   public Class<? extends ExoCacheConfig> getExpectedConfigType()
+   {
+      return TestExoCacheConfig.class;
+   }
+
+   public Set<String> getExpectedImplementations()
+   {
+      return Collections.singleton("TEST");
+   }
+
+   public static class TestExoCache implements ExoCache<Serializable, Object>
+   {
+
+      public void addCacheListener(CacheListener listener)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+
+      public int getCacheHit()
+      {
+         // TODO Auto-generated method stub
+         return 0;
+      }
+
+      public int getCacheMiss()
+      {
+         // TODO Auto-generated method stub
+         return 0;
+      }
+
+      public int getCacheSize()
+      {
+         // TODO Auto-generated method stub
+         return 0;
+      }
+
+      public List getCachedObjects()
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+      public String getLabel()
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+      public long getLiveTime()
+      {
+         // TODO Auto-generated method stub
+         return 0;
+      }
+
+      public int getMaxSize()
+      {
+         // TODO Auto-generated method stub
+         return 0;
+      }
+
+      public String getName()
+      {
+         return "name";
+      }
+
+      public boolean isDistributed()
+      {
+         // TODO Auto-generated method stub
+         return false;
+      }
+
+      public boolean isLogEnabled()
+      {
+         // TODO Auto-generated method stub
+         return false;
+      }
+
+      public boolean isReplicated()
+      {
+         // TODO Auto-generated method stub
+         return false;
+      }
+
+
+      public void select(CachedObjectSelector selector) throws Exception
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setDistributed(boolean b)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setLabel(String s)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setLiveTime(long period)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setLogEnabled(boolean b)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setMaxSize(int max)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setName(String name)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void setReplicated(boolean b)
+      {
+         // TODO Auto-generated method stub
+
+      }
+
+      public void clearCache()
+      {
+         // TODO Auto-generated method stub
+         
+      }
+
+      public Object get(Serializable key)
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+      public void put(Serializable key, Object value) throws NullPointerException
+      {
+         // TODO Auto-generated method stub
+         
+      }
+
+      public void putMap(Map objs) throws NullPointerException, IllegalArgumentException
+      {
+         // TODO Auto-generated method stub
+         
+      }
+
+      public Object remove(Serializable key) throws NullPointerException
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+      public List removeCachedObjects()
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2010 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.infinispan;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator.TestExoCache;
+import org.exoplatform.test.BasicTestCase;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.manager.CacheContainer;
+
+/**
+ * @author <a href="mailto:nicolas.filotto at exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestExoCacheFactoryImpl extends BasicTestCase
+{
+
+   CacheService service_;
+
+   public TestExoCacheFactoryImpl(String name)
+   {
+      super(name);
+   }
+
+   public void setUp() throws Exception
+   {
+      service_ = (CacheService)PortalContainer.getInstance().getComponentInstanceOfType(CacheService.class);
+   }
+
+   public void testCacheFactory()
+   {
+      ExoCache cache = service_.getCacheInstance("myCache");
+      assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+      AbstractExoCache aCache = (AbstractExoCache)cache;
+      assertTrue("expect a local cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.LOCAL);
+      aCache.cache.stop();
+      cache = service_.getCacheInstance("cacheDistributed");
+      assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+      aCache = (AbstractExoCache)cache;
+      assertTrue("expect a distributed cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+      aCache.cache.stop();
+      cache = service_.getCacheInstance("myCustomCache");
+      assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+      aCache = (AbstractExoCache)cache;
+      assertTrue("expect a distributed cache", aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+      aCache.cache.stop();
+   }
+
+   public void testExoCacheCreator()
+   {
+      ExoCache cache = service_.getCacheInstance("test-default-impl");
+      assertTrue("expect an instance of AbstractExoCache", cache instanceof AbstractExoCache);
+      AbstractExoCache aCache = (AbstractExoCache)cache;
+      aCache.cache.stop();
+      cache = service_.getCacheInstance("test-custom-impl-with-old-config");
+      assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache);
+      cache = service_.getCacheInstance("test-custom-impl-with-new-config");
+      assertTrue("expect an instance of TestExoCache", cache instanceof TestExoCache);
+   }
+   
+   public void testSameCacheManager()
+   {
+      ExoCache cache1 = service_.getCacheInstance("myCustomCache");
+      assertTrue("expect an instance of AbstractExoCache", cache1 instanceof AbstractExoCache);
+      AbstractExoCache aCache1 = (AbstractExoCache)cache1;
+      CacheContainer cacheContainer1 = aCache1.cache.getCacheManager();
+      
+      ExoCache cache2 = service_.getCacheInstance("myCustomCache-Bis");
+      assertTrue("expect an instance of AbstractExoCache", cache2 instanceof AbstractExoCache);
+      AbstractExoCache aCache2 = (AbstractExoCache)cache2;
+      CacheContainer cacheContainer2 = aCache2.cache.getCacheManager();
+      assertTrue("The CacheContainer should be the same", cacheContainer1 == cacheContainer2);
+      
+      ExoCache cache3 = service_.getCacheInstance("myCustomCache-Bis2");
+      assertTrue("expect an instance of AbstractExoCache", cache3 instanceof AbstractExoCache);
+      AbstractExoCache aCache3 = (AbstractExoCache)cache3;
+      CacheContainer cacheContainer3 = aCache3.cache.getCacheManager();
+      assertTrue("The CacheContainer should be the same", cacheContainer1 == cacheContainer3);
+      
+      aCache1.cache.stop();
+      aCache2.cache.stop();      
+   }
+}

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (C) 2010 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:5.0 http://www.infinispan.org/schemas/infinispan-config-5.0.xsd"
+	xmlns="urn:infinispan:config:5.0">
+   <global>
+      <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="maxThreads" value="1"/>
+            <property name="queueSize" value="100000"/>
+            <property name="threadNamePrefix" value="AsyncListenerThread"/>
+         </properties>
+      </asyncListenerExecutor>
+      <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+         </properties>
+      </asyncTransportExecutor>
+      <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="EvictionThread"/>
+         </properties>
+      </evictionScheduledExecutor>
+      <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+         </properties>
+      </replicationQueueScheduledExecutor>
+      <globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true" />
+      <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
+      	<properties>
+         <property name="configurationFile" value="flush-udp.xml"/>
+      	</properties>
+      </transport>
+      <shutdown hookBehavior="DEFAULT"/>
+   </global>
+   <default>
+      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+      <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+      <jmxStatistics enabled="true"/>
+      <clustering mode="replication">
+         <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+         <sync replTimeout="20000"/>
+      </clustering>
+   </default>
+</infinispan>
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (C) 2010 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.
+
+-->
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:5.0 http://www.infinispan.org/schemas/infinispan-config-5.0.xsd"
+	xmlns="urn:infinispan:config:5.0">
+   <global>
+      <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="maxThreads" value="1"/>
+            <property name="queueSize" value="100000"/>
+            <property name="threadNamePrefix" value="AsyncListenerThread"/>
+         </properties>
+      </asyncListenerExecutor>
+      <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="AsyncSerializationThread"/>
+         </properties>
+      </asyncTransportExecutor>
+      <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="EvictionThread"/>
+         </properties>
+      </evictionScheduledExecutor>
+      <replicationQueueScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+         <properties>
+            <property name="threadNamePrefix" value="ReplicationQueueThread"/>
+         </properties>
+      </replicationQueueScheduledExecutor>
+      <globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/>
+      <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
+      	<properties>
+         <property name="configurationFile" value="flush-udp.xml"/>
+      	</properties>
+      </transport>
+      <shutdown hookBehavior="DEFAULT"/>
+   </global>
+   <default>
+      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500"/>
+      <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+      <jmxStatistics enabled="true"/>
+      <clustering mode="replication">
+         <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+         <sync replTimeout="20000"/>
+      </clustering>
+   </default>
+</infinispan>
\ No newline at end of file

Added: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml	                        (rev 0)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -0,0 +1,223 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    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.
+
+-->
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+   xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+  
+  <component>
+    <key>org.exoplatform.services.cache.CacheService</key>
+    <type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>
+
+  	<init-params>
+      <object-param>
+        <name>cache.config.default</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.ExoCacheConfig">
+          <field  name="name"><string>default</string></field>
+          <field  name="maxSize"><int>5</int></field>
+          <field  name="liveTime"><long>2</long></field>
+        </object>
+      </object-param>
+      <object-param>
+        <name>test-multi-threading</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
+          <field name="name"><string>test-multi-threading</string></field>
+          <field name="strategy"><string>NONE</string></field>
+          <field name="maxEntries"><int>-1</int></field>
+          <field name="lifespan"><long>-1</long></field>
+        </object>        
+      </object-param>      
+      <object-param>
+        <name>cacheDistributed</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.ExoCacheConfig">
+          <field  name="name"><string>cacheDistributed</string></field>
+          <field  name="maxSize"><int>5</int></field>
+          <field  name="liveTime"><long>2</long></field>
+          <field  name="distributed"><boolean>true</boolean></field>
+        </object>
+      </object-param>                
+      <object-param>
+        <name>test-default-impl</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.ExoCacheConfig">
+          <field  name="name"><string>test-default-impl</string></field>
+          <field  name="maxSize"><int>5</int></field>
+          <field  name="liveTime"><long>2</long></field>
+        </object>
+      </object-param>                
+      <object-param>
+        <name>test-custom-impl-with-old-config</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.ExoCacheConfig">
+          <field  name="name"><string>test-custom-impl-with-old-config</string></field>
+          <field  name="maxSize"><int>5</int></field>
+          <field  name="liveTime"><long>2</long></field>
+          <field  name="implementation"><string>TEST</string></field>
+        </object>
+      </object-param>                
+      <object-param>
+        <name>test-custom-impl-with-new-config</name>
+        <description>The default cache configuration</description>
+        <object type="org.exoplatform.services.cache.impl.infinispan.TestExoCacheConfig">
+          <field  name="name"><string>test-custom-impl-with-new-config</string></field>
+          <field  name="maxSize"><int>5</int></field>
+          <field  name="liveTime"><long>2</long></field>
+        </object>
+      </object-param>
+<!--       <object-param>-->
+<!--        <name>test-fifo-with-old-config</name>-->
+<!--        <description>The default cache configuration</description>-->
+<!--        <object type="org.exoplatform.services.cache.ExoCacheConfig">-->
+<!--          <field name="name"><string>test-fifo-with-old-config</string></field>-->
+<!--          <field name="maxSize"><int>5</int></field>-->
+<!--          <field name="liveTime"><long>1</long></field>-->
+<!--          <field name="implementation"><string>FIFO</string></field>-->
+<!--        </object>-->
+<!--      </object-param>      -->
+<!--       <object-param>-->
+<!--        <name>test-fifo</name>-->
+<!--        <description>The default cache configuration</description>-->
+<!--        <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!--          <field name="name"><string>test-fifo</string></field>-->
+<!--          <field name="strategy"><string>FIFO</string></field>-->
+<!--          <field name="maxEntries"><int>5</int></field>-->
+<!--          <field name="lifespan"><long>1000</long></field>-->
+<!--        </object>-->
+<!--      </object-param>    -->
+<!--      <object-param>-->
+<!--        <name>test-lru-with-old-config</name>-->
+<!--        <description>The default cache configuration</description>-->
+<!--        <object type="org.exoplatform.services.cache.ExoCacheConfig">-->
+<!--          <field name="name"><string>test-lru-with-old-config</string></field>-->
+<!--          <field name="maxSize"><int>4</int></field>-->
+<!--          <field name="liveTime"><long>1</long></field>-->
+<!--          <field name="implementation"><string>LRU</string></field>-->
+<!--        </object>-->
+<!--      </object-param> -->
+<!--       <object-param>-->
+<!--        <name>test-lru</name>-->
+<!--        <description>The default cache configuration</description>-->
+<!--        <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!--          <field name="name"><string>test-lru</string></field>-->
+<!--          <field name="strategy"><string>LRU</string></field>-->
+<!--          <field name="maxEntries"><int>4</int></field>-->
+<!--          <field name="lifespan"><long>1000</long></field>-->
+<!--          <field name="maxIdle"><long>-1</long></field>-->
+<!--        </object>-->
+<!--      </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>NONE</string></field>-->
+<!--        </object>-->
+<!--      </object-param> -->
+<!--       <object-param>-->
+<!--        <name>test-ea</name>-->
+<!--        <description>The default cache configuration</description>-->
+<!--        <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">-->
+<!--          <field name="name"><string>test-ea</string></field>-->
+<!--          <field name="strategy"><string>NONE</string></field>-->
+<!--          <field name="maxEntries"><int>5</int></field>-->
+<!--          <field name="maxIdle"><long>1000</long></field>-->
+<!--          <field name="lifespan"><long>2000</long></field>-->
+<!--        </object>-->
+<!--      </object-param>                                   -->
+    </init-params>	
+  </component>  
+  
+  <component>
+    <key>org.exoplatform.services.cache.ExoCacheFactory</key>
+    <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl</type>
+    <init-params>
+      <value-param>
+        <name>cache.config.template</name>
+        <value>jar:/conf/portal/cache-configuration-template.xml</value>
+      </value-param>
+    </init-params>
+  </component>  
+    
+  <external-component-plugins>
+    <target-component>org.exoplatform.services.cache.ExoCacheFactory</target-component>
+    <component-plugin>
+      <name>addConfig</name>
+      <set-method>addConfig</set-method>
+      <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryConfigPlugin</type>
+      <description>add Custom Configurations</description>
+      <init-params>	
+	      <value-param>
+	        <name>myCustomCache</name>
+	        <value>jar:/conf/portal/distributed-cache-configuration-template.xml</value>
+	      </value-param>    		          
+	      <value-param>
+	        <name>myCustomCache-Bis</name>
+	        <value>classpath:/conf/portal/distributed-cache-configuration-template.xml</value>
+	      </value-param>    		          
+      </init-params>	
+    </component-plugin>    
+    <component-plugin>
+      <name>addCreator</name>
+      <set-method>addCreator</set-method>
+      <type>org.exoplatform.services.cache.impl.infinispan.ExoCacheCreatorPlugin</type>
+      <description>add Exo Cache Creator</description>
+      <init-params>	
+	      <object-param>
+		        <name>Test</name>
+		        <description>The cache creator for testing purpose</description>
+		        <object type="org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator"></object>
+		    </object-param>      
+	      <object-param>
+		        <name>GENERIC</name>
+		        <description>The generic cache creator</description>
+		        <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheCreator">
+		        	<field name="implementations">
+	                  <collection type="java.util.HashSet">
+	                     <value>
+	                        <string>NONE</string>
+	                     </value>
+	                     <value>
+	                        <string>FIFO</string>
+	                     </value>
+	                     <value>
+	                        <string>LRU</string>
+	                     </value>
+	                     <value>
+	                        <string>UNORDERED</string>
+	                     </value>
+	                     <value>
+	                        <string>LIRS</string>
+	                     </value>
+	                  </collection>		        	
+		        	</field>
+		        	<field name="defaultStrategy"><string>LRU</string></field>
+		        	<field name="defaultMaxIdle"><long>-1</long></field>
+		        	<field name="defaultWakeUpInterval"><long>500</long></field>	
+		        </object>
+		    </object-param>  		    		          
+      </init-params>	
+    </component-plugin>
+  </external-component-plugins>  
+</configuration>

Modified: kernel/trunk/pom.xml
===================================================================
--- kernel/trunk/pom.xml	2011-08-09 12:59:58 UTC (rev 4719)
+++ kernel/trunk/pom.xml	2011-08-09 14:05:16 UTC (rev 4720)
@@ -55,7 +55,7 @@
       <module>exo.kernel.component.common</module>
       <module>exo.kernel.component.cache</module>
       <module>exo.kernel.component.ext.cache.impl.jboss.v3</module>
-      <module>exo.kernel.component.ext.cache.impl.infinispan.v4</module>
+      <module>exo.kernel.component.ext.cache.impl.infinispan.v5</module>
       <module>exo.kernel.component.command</module>
       <module>exo.kernel.mc-integration</module>
       <module>packaging/module</module>
@@ -212,7 +212,7 @@
          <dependency>
             <groupId>org.infinispan</groupId>
             <artifactId>infinispan-core</artifactId>
-            <version>4.2.1.FINAL</version>
+            <version>5.0.0.FINAL</version>
          </dependency>
          <dependency>
             <groupId>org.jibx</groupId>



More information about the exo-jcr-commits mailing list