[exo-jcr-commits] exo-jcr SVN: r5430 - in kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src: main/java/org/exoplatform/services/cache/impl/infinispan/distributed and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jan 6 11:47:45 EST 2012


Author: nfilotto
Date: 2012-01-06 11:47:45 -0500 (Fri, 06 Jan 2012)
New Revision: 5430

Modified:
   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/ExoCacheFactoryImpl.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.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/java/org/exoplatform/services/ispn/DistributedCacheManager.java
   kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java
   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/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/conf/portal/cache-configuration-template.xml
Log:
EXOJCR-1682: Improve ISPN integration to support properly the distribution mode (kernel)
* Got rid of all deprecated code but due to some bugs in ISPN we have some workarounds to remove later

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -22,7 +22,7 @@
 import org.exoplatform.services.cache.ExoCacheConfig;
 import org.exoplatform.services.cache.ExoCacheInitException;
 import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
 
 import java.io.Serializable;
 import java.util.Set;
@@ -41,11 +41,11 @@
    /**
     * 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 confBuilder the configuration builder 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, 
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder, 
             Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException;
 
    /**

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -34,12 +34,19 @@
 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.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
+import org.infinispan.configuration.parsing.Parser;
+import org.infinispan.distribution.ch.ConsistentHash;
+import org.infinispan.distribution.ch.DefaultConsistentHash;
 import org.infinispan.eviction.EvictionStrategy;
 import org.infinispan.jmx.MBeanServerLookup;
 import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.util.Util;
 
 import java.io.InputStream;
 import java.io.Serializable;
@@ -113,10 +120,10 @@
    private final Map<String, String> mappingCacheNameConfig = new HashMap<String, String>();
 
    /**
-    * The mapping between the global configuration and the cache managers
+    * The mapping between the cluster name and the cache managers
     */
-   private final Map<GlobalConfiguration, DefaultCacheManager> mappingGlobalConfigCacheManager =
-      new HashMap<GlobalConfiguration, DefaultCacheManager>();
+   private final Map<String, DefaultCacheManager> mappingGlobalConfigCacheManager =
+      new HashMap<String, DefaultCacheManager>();
 
    /**
     * The default creator
@@ -162,7 +169,8 @@
       // Initialize the main cache manager
       this.cacheManager = initCacheManager(cacheConfigTemplate);
       // Register the main cache manager
-      mappingGlobalConfigCacheManager.put(cacheManager.getGlobalConfiguration(), cacheManager);
+      mappingGlobalConfigCacheManager.put(cacheManager.getCacheManagerConfiguration().transport().clusterName(),
+         cacheManager);
    }
 
    /**
@@ -193,24 +201,32 @@
                   throw new ExoCacheInitException("The configuration of the CacheManager cannot be found at '"
                      + cacheConfigTemplate + "'");
                }
-               DefaultCacheManager cacheManager = null;
+               GlobalConfigurationBuilder configBuilder;
+               Configuration config;
                try
                {
-                  // Create the CacheManager from the input stream
-                  cacheManager = new DefaultCacheManager(is, false);
+                  Parser parser = new Parser(Thread.currentThread().getContextClassLoader());
+                  // Loads the configuration from the input stream
+                  ConfigurationBuilderHolder holder = parser.parse(is);
+                  configBuilder = holder.getGlobalConfigurationBuilder();
+                  config = holder.getDefaultConfigurationBuilder().build();
                }
                catch (Exception e)
                {
+                  throw new ExoCacheInitException("Cannot parse the configuration '" + cacheConfigTemplate + "'", e);
+               }
+               configureCacheManager(configBuilder);
+               try
+               {
+                  // Create the CacheManager from the new configuration
+                  return new DefaultCacheManager(configBuilder.build(), config);
+               }
+               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;
             }
          });
       }
@@ -231,16 +247,18 @@
    /**
     * Configure the cache manager
     * 
-    * @param config
+    * @param configBuilder the configuration builder on which we applied all the required changes
     * @throws ExoCacheInitException
     */
-   private void configureCacheManager(GlobalConfiguration config) throws ExoCacheInitException
+   private void configureCacheManager(GlobalConfigurationBuilder configBuilder) throws ExoCacheInitException
    {
+      GlobalConfiguration config = configBuilder.build();
       // Configure JGroups
-      configureJGroups(config);
+      configureJGroups(config, configBuilder);
       // Configure the name of the cache manager
-      config.fluent().globalJmxStatistics().cacheManagerName(config.getCacheManagerName() + "_" + ctx.getName()).
-      // Configure the MBeanServerLookup
+      configBuilder.globalJmxStatistics().enable()
+         .cacheManagerName(config.globalJmxStatistics().cacheManagerName() + "_" + ctx.getName()).
+         // Configure the MBeanServerLookup
          mBeanServerLookup(MBEAN_SERVER_LOOKUP);
    }
 
@@ -249,27 +267,31 @@
     * 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
+    * @param configBuilder the related configuration builder
     * @throws ExoCacheInitException if any exception occurs while configuring JGroups
     */
-   private void configureJGroups(GlobalConfiguration config) throws ExoCacheInitException
+   private void configureJGroups(GlobalConfiguration config, GlobalConfigurationBuilder configBuilder)
+      throws ExoCacheInitException
    {
-      if (loadJGroupsConfig(config))
+      if (loadJGroupsConfig(config, configBuilder))
       {
          // The JGroups Config could be loaded which means that the configuration is for a cluster
-         config.fluent().transport().clusterName(config.getClusterName() + "-" + ctx.getName());
+         configBuilder.transport().clusterName(config.transport().clusterName() + "-" + 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
+    * @param configBuilder the related configuration builder
     * @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
+   private boolean loadJGroupsConfig(GlobalConfiguration config, GlobalConfigurationBuilder configBuilder)
+      throws ExoCacheInitException
    {
-      return Utils.loadJGroupsConfig(configManager, config);
+      return Utils.loadJGroupsConfig(configManager, config, configBuilder);
    }
 
    /**
@@ -289,7 +311,7 @@
       final DefaultCacheManager cacheManager;
       try
       {
-         final Configuration conf;
+         final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
          if (customConfig != null)
          {
             try
@@ -302,24 +324,34 @@
                         // 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();
+                        Parser parser = new Parser(Thread.currentThread().getContextClassLoader());
+                        // Load the configuration
+                        ConfigurationBuilderHolder holder = parser.parse(configManager.getInputStream(customConfig));
+                        GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder();
                         // Configure JGroups and JMX since it could affect the state of the Global Config
-                        configureCacheManager(gc);
+                        configureCacheManager(configBuilder);
+                        GlobalConfiguration gc = configBuilder.build();
+
                         // Check if a CacheManager with the same GlobalConfiguration exists
-                        DefaultCacheManager currentCacheManager = mappingGlobalConfigCacheManager.get(gc);
+                        DefaultCacheManager currentCacheManager =
+                           mappingGlobalConfigCacheManager.get(gc.transport().clusterName());
                         if (currentCacheManager == null)
                         {
+                           // Use a different cache manager name to prevent naming conflict
+                           configBuilder.globalJmxStatistics().cacheManagerName(
+                              gc.globalJmxStatistics().cacheManagerName() + "_" + region + "_" + ctx.getName());
                            // 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 =
+                              new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder()
+                                 .build(), false);
+                           for (ConfigurationBuilder b : holder.getConfigurationBuilders())
+                           {
+                              Configuration c = b.build();
+                              currentCacheManager.defineConfiguration(c.name(), c);
+                           }
                            currentCacheManager.start();
                            // We register this new cache manager
-                           mappingGlobalConfigCacheManager.put(gc, customCacheManager);
+                           mappingGlobalConfigCacheManager.put(gc.transport().clusterName(), currentCacheManager);
                         }
                         return currentCacheManager;
                      }
@@ -337,7 +369,17 @@
                   throw new Exception(e);
                }
             }
-            conf = cacheManager.getDefaultConfiguration().clone();
+            confBuilder.read(cacheManager.getDefaultCacheConfiguration());
+            //TODO remove it once ISPN-1687 will be fixed
+            confBuilder.storeAsBinary().enabled(false);
+            confBuilder.jmxStatistics().enable();
+            //TODO remove it once ISPN-1689 will be fixed
+            confBuilder
+               .clustering()
+               .hash()
+               .consistentHash(
+                  Util.<ConsistentHash> getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+                     .getContextClassLoader()));
          }
          else if (config.isDistributed())
          {
@@ -356,20 +398,29 @@
             // 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();
+            confBuilder.read(cacheManager.getDefaultCacheConfiguration());
+            //TODO remove it once ISPN-1687 will be fixed
+            confBuilder.storeAsBinary().enabled(false);
+            confBuilder.jmxStatistics().enable();
+            //TODO remove it once ISPN-1689 will be fixed
+            confBuilder
+               .clustering()
+               .hash()
+               .consistentHash(
+                  Util.<ConsistentHash> getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+                     .getContextClassLoader()));
             if (!config.isRepicated())
             {
                // The cache is local
-               conf.fluent().clustering().mode(CacheMode.LOCAL);
+               confBuilder.clustering().cacheMode(CacheMode.LOCAL);
             }
          }
          // Reset the configuration to avoid conflicts
-         resetConfiguration(conf);
+         resetConfiguration(confBuilder);
          final ExoCacheCreator creator = getExoCacheCreator(config);
          // Create the cache
-         eXoCache = creator.create(config, conf, new Callable<Cache<Serializable, Object>>()
+         eXoCache = creator.create(config, confBuilder, new Callable<Cache<Serializable, Object>>()
          {
-            @Override
             public Cache<Serializable, Object> call() throws Exception
             {
                try
@@ -380,7 +431,7 @@
                         public Cache<Serializable, Object> run() throws Exception
                         {
                            // Define the configuration
-                           cacheManager.defineConfiguration(region, conf);
+                           cacheManager.defineConfiguration(region, confBuilder.build());
                            // create and start the cache                 
                            return cacheManager.getCache(region);
                         }
@@ -485,9 +536,9 @@
    /**
     * Clean the configuration template to prevent conflicts
     */
-   protected void resetConfiguration(Configuration config)
+   protected void resetConfiguration(ConfigurationBuilder confBuilder)
    {
-      config.fluent().invocationBatching().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration()
+      confBuilder.invocationBatching().enable().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration()
          .lifespan(-1L).maxIdle(-1L).wakeUpInterval(60000L);
    }
 }

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -794,7 +794,7 @@
    @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.")
    public int getMaxSize()
    {
-      return cache.getConfiguration().getEvictionMaxEntries();
+      return cache.getCacheConfiguration().eviction().maxEntries();
    }
 
    @ManagedName("Lifespan")
@@ -802,7 +802,7 @@
       + " -1 means the entries never expire.")
    public long getLiveTime()
    {
-      return cache.getConfiguration().getExpirationLifespan();
+      return cache.getCacheConfiguration().expiration().lifespan();
    }
 
    @Managed
@@ -811,7 +811,7 @@
       + "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.")
    public long getMaxIdle()
    {
-      return cache.getConfiguration().getExpirationMaxIdle();
+      return cache.getCacheConfiguration().expiration().maxIdle();
    }
 
    @Managed
@@ -820,7 +820,7 @@
       + "process altogether, set wakeupInterval to -1.")
    public long getWakeUpInterval()
    {
-      return cache.getConfiguration().getExpirationWakeUpInterval();
+      return cache.getCacheConfiguration().expiration().wakeUpInterval();
    }
 
    public static class CacheKey<K> implements Externalizable

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -27,7 +27,7 @@
 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.configuration.cache.ConfigurationBuilder;
 import org.infinispan.eviction.EvictionStrategy;
 
 import java.io.Serializable;
@@ -84,20 +84,20 @@
    /**
     * {@inheritDoc}
     */
-   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder,
       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(),
+         return create(config, confBuilder, 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,
+         return create(config, confBuilder, cacheGetter,
             config.getImplementation() == null ? defaultStrategy : config.getImplementation(), config.getMaxSize(),
             period > 0 ? period * 1000 : -1, defaultMaxIdle, defaultWakeUpInterval);
       }
@@ -107,7 +107,7 @@
     * 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,
+   private ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder,
       Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle,
       long wakeUpInterval) throws ExoCacheInitException
    {
@@ -118,11 +118,11 @@
       {
          es = EvictionStrategy.LRU;
       }
-      cacheConfig.fluent().eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration()
+      confBuilder.eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration()
          .lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval);
       try
       {
-         return new GenericExoCache(cacheConfig, config, cacheGetter.call());
+         return new GenericExoCache(config, cacheGetter.call());
       }
       catch (Exception e)
       {
@@ -136,41 +136,26 @@
    public static class GenericExoCache extends AbstractExoCache<Serializable, Object>
    {
 
-      private final Configuration cacheConfig;
-
-      public GenericExoCache(Configuration cacheConfig, ExoCacheConfig config, Cache<Serializable, Object> cache)
+      public GenericExoCache(ExoCacheConfig config, Cache<Serializable, Object> cache)
       {
          super(config, cache);
-         this.cacheConfig = cacheConfig;
       }
 
       public void setMaxSize(int max)
       {
-         cacheConfig.fluent().eviction().maxEntries(max);
+         throw new UnsupportedOperationException("The configuration of the cache cannot not be modified");
       }
 
       public void setLiveTime(long period)
       {
-         cacheConfig.fluent().expiration().lifespan(period);
+         throw new UnsupportedOperationException("The configuration of the cache cannot not be modified");
       }
 
-      @Managed
-      public void setMaxIdle(long maxIdle)
-      {
-         cacheConfig.fluent().expiration().maxIdle(maxIdle);
-      }
-
-      @Managed
-      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();
+         return cache.getCacheConfiguration().eviction().maxEntries();
       }
 
       @ManagedName("Lifespan")
@@ -178,7 +163,7 @@
          + " -1 means the entries never expire.")
       public long getLiveTime()
       {
-         return cacheConfig.getExpirationLifespan();
+         return cache.getCacheConfiguration().expiration().lifespan();
       }
 
       @Managed
@@ -187,7 +172,7 @@
          + "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();
+         return cache.getCacheConfiguration().expiration().maxIdle();
       }
 
       @Managed
@@ -196,7 +181,7 @@
          + "process altogether, set wakeupInterval to -1.")
       public long getWakeUpInterval()
       {
-         return cacheConfig.getExpirationWakeUpInterval();
+         return cache.getCacheConfiguration().expiration().wakeUpInterval();
       }
    }
 }
\ No newline at end of file

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -29,9 +29,17 @@
 import org.exoplatform.services.log.Log;
 import org.exoplatform.services.transaction.TransactionService;
 import org.infinispan.Cache;
-import org.infinispan.factories.ComponentRegistry;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
+import org.infinispan.configuration.parsing.Parser;
+import org.infinispan.distribution.ch.ConsistentHash;
+import org.infinispan.distribution.ch.DefaultConsistentHash;
 import org.infinispan.manager.DefaultCacheManager;
 import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.transaction.lookup.TransactionManagerLookup;
+import org.infinispan.util.Util;
 import org.picocontainer.Startable;
 
 import java.security.PrivilegedExceptionAction;
@@ -143,24 +151,35 @@
          }
          return SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<EmbeddedCacheManager>()
          {
-
-            @Override
             public EmbeddedCacheManager run() throws Exception
             {
+               Parser parser = new Parser(Thread.currentThread().getContextClassLoader());
+               // Load the configuration
+               ConfigurationBuilderHolder holder = parser.parse(helper.fillTemplate(configurationFile, parameters));
+               GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder();
+               Utils.loadJGroupsConfig(configManager, configBuilder.build(), configBuilder);
+               // Create the CacheManager from the new configuration
                EmbeddedCacheManager manager =
-                  new DefaultCacheManager(helper.fillTemplate(configurationFile, parameters), false);
-               Utils.loadJGroupsConfig(configManager, manager.getGlobalConfiguration());
-               manager.start();
-               for (String cacheName : manager.getCacheNames())
+                  new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder().build());
+               TransactionManagerLookup tml = new TransactionManagerLookup()
                {
-                  Cache cache = manager.getCache(cacheName);
-                  if (tm != null)
+                  public TransactionManager getTransactionManager() throws Exception
                   {
-                     // We inject the transaction manager
-                     ComponentRegistry cr = cache.getAdvancedCache().getComponentRegistry();
-                     cr.registerComponent(tm, TransactionManager.class);
-                     cr.rewire();
-                  }                  
+                     return tm;
+                  }
+               };
+               for (ConfigurationBuilder b : holder.getConfigurationBuilders())
+               {
+                  b.transaction().transactionManagerLookup(tml);
+                  //TODO remove it once ISPN-1689 will be fixed
+                  b.clustering()
+                     .hash()
+                     .consistentHash(
+                        Util.<ConsistentHash> getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+                           .getContextClassLoader()));
+                  Configuration c = b.build();
+                  manager.defineConfiguration(c.name(), c);
+                  manager.getCache(c.name());
                }
                return manager;
             }

Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -23,7 +23,8 @@
 import org.exoplatform.services.cache.ExoCacheInitException;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
-import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
 import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
 
 import java.io.IOException;
@@ -41,22 +42,24 @@
    /**
     * The logger
     */
-   private static final Log LOG = ExoLogger
-      .getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.Utils");
-   
-   private Utils() {}
-   
+   private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.Utils");
 
+   private Utils()
+   {
+   }
+
    /**
     * Load the JGroups configuration file thanks to the {@link ConfigurationManager}
     * @param config the global configuration from which the JGroups config will be extracted
+    * @param configBuilder the related configuration builder
     * @return <code>true</code> if the JGoups config could be loaded successfully, 
     * <code>false</code> if there were no JGroups config to load
     * @throws IllegalStateException if the JGroups config could not be loaded
     */
-   public static boolean loadJGroupsConfig(ConfigurationManager cfm, GlobalConfiguration config) throws ExoCacheInitException
+   public static boolean loadJGroupsConfig(ConfigurationManager cfm, GlobalConfiguration config,
+      GlobalConfigurationBuilder configBuilder) throws ExoCacheInitException
    {
-      Properties properties = config.getTransportProperties();
+      Properties properties = config.transport().properties();
       if (properties == null || !properties.containsKey(JGroupsTransport.CONFIGURATION_FILE))
       {
          return false;
@@ -67,9 +70,8 @@
       // inputStream still remains null, so file was not opened
       if (inputStream == null)
       {
-         throw new IllegalStateException("The jgroups configuration cannot be loaded from '" + filename
-            + "'");
-      }      
+         throw new IllegalStateException("The jgroups configuration cannot be loaded from '" + filename + "'");
+      }
       try
       {
          // Set the jgroups configuration as XML
@@ -77,15 +79,14 @@
       }
       catch (IOException e)
       {
-         throw new IllegalStateException("The jgroups configuration cannot be read from '" + filename
-            + "'");
+         throw new IllegalStateException("The jgroups configuration cannot be read from '" + filename + "'");
       }
       // Remove the property corresponding to the configuration file
       properties.remove(JGroupsTransport.CONFIGURATION_FILE);
+      configBuilder.transport().withProperties(properties);
       return true;
    }
 
-
    /**
     * Reads bytes from input stream and builds a string from them
     * 

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml	2012-01-06 16:47:45 UTC (rev 5430)
@@ -53,7 +53,7 @@
       <shutdown hookBehavior="DEFAULT"/>
    </global>
    <default>
-      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="true"/>
       <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" transactionMode="TRANSACTIONAL"/>
       <jmxStatistics enabled="true"/>
       <invocationBatching enabled="true"/>

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -24,7 +24,7 @@
 import org.exoplatform.services.cache.ExoCacheConfig;
 import org.exoplatform.services.cache.ExoCacheInitException;
 import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
 
 import java.io.Serializable;
 import java.util.Collections;
@@ -42,10 +42,10 @@
 {
 
    /**
-    * @see org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig, org.infinispan.config.Configuration, java.util.concurrent.Callable)
+    * {@inheritDoc}
     */
    @Override
-   public ExoCache<Serializable, Object> create(ExoCacheConfig config, Configuration cacheConfig,
+   public ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder,
       Callable<Cache<Serializable, Object>> cacheGetter) throws ExoCacheInitException
    {
       return new TestExoCache();
@@ -61,55 +61,46 @@
       return Collections.singleton("TEST");
    }
 
+   @SuppressWarnings({"rawtypes", "unchecked"})
    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;
       }
 
@@ -120,104 +111,86 @@
 
       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;
       }
 

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java	2012-01-06 16:47:45 UTC (rev 5430)
@@ -23,7 +23,7 @@
 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.configuration.cache.CacheMode;
 import org.infinispan.manager.CacheContainer;
 
 /**
@@ -31,6 +31,7 @@
  * @version $Id$
  *
  */
+ at SuppressWarnings("rawtypes")
 public class TestExoCacheFactoryImpl extends BasicTestCase
 {
 
@@ -51,17 +52,20 @@
       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);
+      assertTrue("expect a local cache",
+         aCache.cache.getCacheConfiguration().clustering().cacheMode() == 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);
+      assertTrue("expect a distributed cache",
+         aCache.cache.getCacheConfiguration().clustering().cacheMode() == 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);
+      assertTrue("expect a distributed cache",
+         aCache.cache.getCacheConfiguration().clustering().cacheMode() == CacheMode.REPL_SYNC);
       aCache.cache.stop();
    }
 
@@ -76,27 +80,27 @@
       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();      
+      aCache2.cache.stop();
    }
 }

Modified: 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	2012-01-06 10:43:05 UTC (rev 5429)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml	2012-01-06 16:47:45 UTC (rev 5430)
@@ -53,7 +53,7 @@
       <shutdown hookBehavior="DEFAULT"/>
    </global>
    <default>
-      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500"/>
+      <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="10000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="true"/>
       <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" transactionMode="TRANSACTIONAL"/>
       <jmxStatistics enabled="true"/>
       <clustering mode="replication">



More information about the exo-jcr-commits mailing list