[jboss-cvs] JBossAS SVN: r106401 - in projects/cluster/ha-server-cache-ispn/trunk: src/main/java and 16 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 2 11:04:37 EDT 2010


Author: pferraro
Date: 2010-07-02 11:04:36 -0400 (Fri, 02 Jul 2010)
New Revision: 106401

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfiguration.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfigurationAdapter.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactory.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistry.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfiguration.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationEntry.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationSource.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSource.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSource.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/package-info.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolver.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSource.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/resources/META-INF/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerFactoryTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerRegistryTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSourceTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSourceTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolverTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml
   projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs.xml
Modified:
   projects/cluster/ha-server-cache-ispn/trunk/pom.xml
Log:
Initial check-in of CacheManagerRegistry

Modified: projects/cluster/ha-server-cache-ispn/trunk/pom.xml
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/pom.xml	2010-07-02 14:24:02 UTC (rev 106400)
+++ projects/cluster/ha-server-cache-ispn/trunk/pom.xml	2010-07-02 15:04:36 UTC (rev 106401)
@@ -1,8 +1,8 @@
 <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">
   <parent>
-    <groupId>org.jboss.cluster</groupId>
-    <artifactId>jboss-cluster</artifactId>
-    <version>2.0.0.GA</version>
+    <groupId>org.jboss</groupId>
+    <artifactId>jboss-parent</artifactId>
+    <version>5</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.jboss.cluster</groupId>
@@ -24,32 +24,32 @@
   </organization>
   
   <scm>
-    <connection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-ispn/trunk</connection>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-ispn/trunk</connection>
     <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-ispn/trunk</developerConnection>
   </scm>
   
   <properties>
-    <version.jboss.ha.server.cache.spi>2.1.0.Final</version.jboss.ha.server.cache.spi>
-    <version.jboss.ha.server.api>2.0.0-SNAPSHOT</version.jboss.ha.server.api>
+    <version.jboss.ha.server.cache.spi>2.2.0.Final</version.jboss.ha.server.cache.spi>
+    <version.jboss.ha.server.api>2.0.0.Alpha3</version.jboss.ha.server.api>
     <version.jboss.common.core>2.2.17.GA</version.jboss.common.core>
     <version.jboss.logging>3.0.0.Beta2</version.jboss.logging>
-    <version.infinispan>4.0.0.GA</version.infinispan>
-    <version.jgroups>2.10.0.Alpha3</version.jgroups>
-    <version.org.jboss.naming>5.0.5.GA</version.org.jboss.naming>
+    <version.infinispan>4.1.0.BETA2</version.infinispan>
+    <version.org.jboss.naming>5.0.5.Final</version.org.jboss.naming>
     <version.suffix.org.jboss.javaee>.GA</version.suffix.org.jboss.javaee>
     <version.org.jboss.metadata.war>2.0.0.Alpha14</version.org.jboss.metadata.war>
-    <version.junit>3.8.1</version.junit>
+    <version.junit>4.8.1</version.junit>
+    <version.easymock>3.0</version.easymock>
   </properties>
   
   <build>
     <plugins>
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-release-plugin</artifactId>
-        <version>2.0-beta-9</version>
         <configuration>
           <!-- The tagBase property is needed during the release process so that the maven release plugin
             will create the release tag in the appropriate location. -->
-          <tagBase>https://svn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-jbc/tags</tagBase>
+          <tagBase>https://svn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-ispn/tags</tagBase>
         </configuration>
       </plugin>     
     </plugins>
@@ -78,6 +78,12 @@
       <groupId>org.jboss.cluster</groupId>
       <artifactId>jboss-ha-server-cache-spi</artifactId>
       <version>${version.jboss.ha.server.cache.spi}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>jgroups</groupId>
+          <artifactId>jgroups</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     
     <dependency>
@@ -90,26 +96,23 @@
       <groupId>org.jboss.logging</groupId>
       <artifactId>jboss-logging</artifactId>
       <version>${version.jboss.logging}</version>
+      <scope>provided</scope>
     </dependency> 
       
     <dependency>
       <groupId>org.infinispan</groupId>
       <artifactId>infinispan-core</artifactId>
-      <version>${version.infinispan}</version>      
-      <optional>true</optional>
+      <version>${version.infinispan}</version>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
-          <groupId>jgroups</groupId>
-          <artifactId>jgroups</artifactId>
-        </exclusion>
-        <exclusion>
           <groupId>org.jboss</groupId>
           <artifactId>jboss-common-core</artifactId>
         </exclusion>
-        <exclusion>
+        <!--exclusion>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging</artifactId>
-        </exclusion>
+        </exclusion-->
         <exclusion>
           <groupId>javax.transaction</groupId>
           <artifactId>jta</artifactId>
@@ -117,19 +120,6 @@
       </exclusions>
     </dependency>
     
-    <dependency>
-      <groupId>jgroups</groupId>
-      <artifactId>jgroups</artifactId>
-      <version>${version.jgroups}</version>      
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-
     <!-- For the JTA 1.1 API; consuming projects can safely
          exclude this and replace with any valid source of this API -->
     <dependency>
@@ -158,6 +148,12 @@
       <version>${version.junit}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>${version.easymock}</version>
+      <scope>test</scope>
+    </dependency>
     
   </dependencies>   
   
@@ -172,4 +168,3 @@
   </reporting>
 
 </project>
-

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfiguration.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfiguration.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfiguration.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan;
+
+import java.util.Collection;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+
+/**
+ * Represents an Infinispan cache manager configuration.
+ * @author Paul Ferraro
+ */
+public interface CacheManagerConfiguration
+{
+   /**
+    * The general configuration shared by all caches.
+    * @return a global configuration
+    */
+   GlobalConfiguration getGlobalConfiguration();
+
+   /**
+    * The default configuration inherited by any named caches.
+    * @return the default cache configuration
+    */
+   Configuration getDefaultConfiguration();
+
+   /**
+    * The name cache configurations.
+    * @return a collection of named cache configuration
+    */
+   Collection<Configuration> getConfigurations();
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfigurationAdapter.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfigurationAdapter.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerConfigurationAdapter.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,39 @@
+package org.jboss.ha.infinispan;
+
+import java.util.Collection;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.config.InfinispanConfiguration;
+
+/**
+ * Adapts an {@link InfinispanConfiguration} to the {@link CacheManagerConfiguration} interface.
+ * @author Paul Ferraro
+ */
+public class CacheManagerConfigurationAdapter implements CacheManagerConfiguration
+{
+   private final InfinispanConfiguration configuration;
+   
+   public CacheManagerConfigurationAdapter(InfinispanConfiguration configuration)
+   {
+      this.configuration = configuration;
+   }
+
+   @Override
+   public GlobalConfiguration getGlobalConfiguration()
+   {
+      return this.configuration.parseGlobalConfiguration();
+   }
+
+   @Override
+   public Configuration getDefaultConfiguration()
+   {
+      return this.configuration.parseDefaultConfiguration();
+   }
+
+   @Override
+   public Collection<Configuration> getConfigurations()
+   {
+      return this.configuration.parseNamedConfigurations().values();
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactory.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactory.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactory.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan;
+
+import org.infinispan.manager.CacheManager;
+
+/**
+ * Creates an Infinispan {@link CacheManager} instance from configuration.
+ * 
+ * @author Paul Ferraro
+ */
+public interface CacheManagerFactory
+{
+   /**
+    * Creates a {@link CacheManager} from the specified configuration.
+    * @param configuration a cache manager configuration
+    * @return an Infinispan cache manager
+    */
+   CacheManager createCacheManager(CacheManagerConfiguration configuration);
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactoryImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerFactoryImpl.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan;
+
+import java.util.Properties;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.remoting.transport.jgroups.JGroupsChannelLookup;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+import org.jgroups.Channel;
+import org.jgroups.ChannelFactory;
+
+/**
+ * An Infinispan cache manager factory that injects its channel from a channel factory.
+ * 
+ * @author Paul Ferraro
+ */
+ at SuppressWarnings("deprecation")
+public class CacheManagerFactoryImpl implements CacheManagerFactory
+{
+   private static final String CHANNEL_ID = "channelId";
+   private static final String CHANNEL_FACTORY = "channelFactory";
+   
+   private final ChannelFactory channelFactory;
+   
+   /**
+    * Creates a new CacheManagerFactoryImpl using the specified channel factory.
+    * @param channelFactory a channel factory
+    */
+   public CacheManagerFactoryImpl(ChannelFactory channelFactory)
+   {
+      this.channelFactory = channelFactory;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.CacheManagerFactory#createCacheManager(org.jboss.ha.infinispan.CacheManagerConfiguration)
+    */
+   @Override
+   public CacheManager createCacheManager(CacheManagerConfiguration configuration)
+   {
+      GlobalConfiguration globalConfiguration = configuration.getGlobalConfiguration();
+      Properties properties = globalConfiguration.getTransportProperties();
+      properties.put(CHANNEL_FACTORY, this.channelFactory);
+      properties.setProperty(CHANNEL_ID, globalConfiguration.getClusterName());
+      properties.setProperty(JGroupsTransport.CHANNEL_LOOKUP, ChannelFactoryChannelLookup.class.getName());
+
+      EmbeddedCacheManager manager = new DefaultCacheManager(globalConfiguration, configuration.getDefaultConfiguration(), false);
+
+      // Add named configurations
+      for (Configuration config: configuration.getConfigurations())
+      {
+         manager.defineConfiguration(config.getName(), config);
+      }
+      
+      manager.start();
+      
+      return manager;
+   }
+   
+   /**
+    * JGroupsChannelLookup implementation that uses a channel factory.
+    */
+   public static class ChannelFactoryChannelLookup implements JGroupsChannelLookup
+   {
+      public static final String STACK = "stack";
+      public static final String DEFAULT_STACK = "udp";
+      
+      @Override
+      public Channel getJGroupsChannel(Properties properties)
+      {
+         String stack = properties.getProperty(STACK, DEFAULT_STACK);
+         String id = properties.getProperty(CHANNEL_ID);
+         ChannelFactory factory = (ChannelFactory) properties.get(CHANNEL_FACTORY);
+         
+         try
+         {
+            return factory.createMultiplexerChannel(stack, id);
+         }
+         catch (Exception e)
+         {
+            throw new IllegalArgumentException(e);
+         }
+      }
+
+      @Override
+      public boolean shouldStartAndConnect()
+      {
+         return true;
+      }
+
+      @Override
+      public boolean shouldStopAndDisconnect()
+      {
+         return true;
+      }
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistry.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistry.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistry.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan;
+
+import java.util.Set;
+
+import org.infinispan.manager.CacheManager;
+
+/**
+ * A registry of Infinispan cache managers.
+ * @author Paul Ferraro
+ */
+public interface CacheManagerRegistry
+{
+   /**
+    * Returns the cache manager associated with the specified identifier,
+    * or the default cache manager if there is no associated cache manager
+    * or the specified id is null.
+    * @param id a cache manager identifier
+    * @return an Infinispan cache manager.
+    */
+   CacheManager getCacheManager(String id);
+   
+   /**
+    * Returns the identifiers of all cache managers in this registry.
+    * @return a set of cache manager identifiers.
+    */
+   Set<String> getCacheManagers();
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistryImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/CacheManagerRegistryImpl.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan;
+
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.infinispan.manager.CacheManager;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfiguration;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationEntry;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource;
+import org.jboss.logging.Logger;
+
+/**
+ * Cache manager registry that populates itself using a specified factory from configuration from a specified source.
+ * All cache managers in the registry are bound to jndi.
+ * @author Paul Ferraro
+ */
+public class CacheManagerRegistryImpl implements CacheManagerRegistry
+{
+   private static Logger logger = Logger.getLogger(CacheManagerRegistryImpl.class);
+   
+   private final CacheManagerFactory factory;
+   private final CacheManagerRegistryConfigurationSource source;
+   private final Context context;
+   private final Map<String, Map.Entry<String, CacheManager>> cacheManagers = new ConcurrentHashMap<String, Map.Entry<String, CacheManager>>();
+   
+   private CacheManager defaultCacheManager;
+   
+   /**
+    * Creates a new CacheManagerRegistryImpl using the specified factory and source.
+    * @param factory used to create cache manager instances from configuration
+    * @param source source of cache manager configurations.
+    * @throws NamingException if inital context could not be created
+    */
+   public CacheManagerRegistryImpl(CacheManagerFactory factory, CacheManagerRegistryConfigurationSource source) throws NamingException
+   {
+      this(factory, source, new InitialContext());
+   }
+   
+   /**
+    * Creates a new CacheManagerRegistryImpl using the specified factory and source.
+    * @param factory used to create cache manager instances from configuration
+    * @param source source of cache manager configurations.
+    * @param context jndi context to which to bind cache managers.
+    */
+   public CacheManagerRegistryImpl(CacheManagerFactory factory, CacheManagerRegistryConfigurationSource source, Context context)
+   {
+      this.factory = factory;
+      this.source = source;
+      this.context = context;
+   }
+   
+   public void start() throws Exception
+   {
+      CacheManagerRegistryConfiguration registry = this.source.getRegistryConfiguration();
+      
+      for (CacheManagerRegistryConfigurationEntry entry: registry.getEntries())
+      {
+         String id = entry.getId();
+         String jndiName = entry.getJndiName();
+         
+         // If no jndi name was specified, construct one using the id
+         if (jndiName == null)
+         {
+            jndiName = this.context.composeName(id, registry.getBaseJndiName());
+         }
+         
+         CacheManager manager = this.factory.createCacheManager(new CacheManagerConfigurationAdapter(entry.getConfiguration()));
+         
+         // Store cache managers with jndi name, so they can be unbound during stop()
+         this.cacheManagers.put(id, new AbstractMap.SimpleImmutableEntry<String, CacheManager>(jndiName, manager));
+         
+         // Bind cache manager to jndi
+         this.context.bind(jndiName, manager);
+      }
+
+      CacheManagerRegistryConfigurationEntry defaultEntry = registry.getDefaultEntry();
+      
+      if (defaultEntry == null)
+      {
+         defaultEntry = registry.getEntries().get(0);
+      }
+      
+      this.defaultCacheManager = this.cacheManagers.get(defaultEntry.getId()).getValue();
+   }
+   
+   public void stop() throws Exception
+   {
+      for (Map.Entry<String, CacheManager> entry: this.cacheManagers.values())
+      {
+         try
+         {
+            this.context.unbind(entry.getKey());
+         }
+         catch (NamingException e)
+         {
+            logger.warn(e.getMessage(), e);
+         }
+         
+         entry.getValue().stop();
+      }
+      
+      this.cacheManagers.clear();
+      this.defaultCacheManager = null;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.CacheManagerRegistry#getCacheManagers()
+    */
+   @Override
+   public Set<String> getCacheManagers()
+   {
+      return Collections.unmodifiableSet(this.cacheManagers.keySet());
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.CacheManagerRegistry#getCacheManager(java.lang.String)
+    */
+   @Override
+   public CacheManager getCacheManager(String name)
+   {
+      Map.Entry<String, CacheManager> entry = (name != null) ? this.cacheManagers.get(name) : null;
+      
+      // Return default cache manager, if name was not found or if it was null
+      return (entry != null) ? entry.getValue() : this.defaultCacheManager;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfiguration.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfiguration.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfiguration.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlIDREF;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Root element for cache manager registry configuration.
+ * @author Paul Ferraro
+ */
+ at XmlRootElement(name = "infinispan-configs")
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType
+public class CacheManagerRegistryConfiguration
+{
+   @XmlIDREF
+   @XmlAttribute(name = "default", required = false)
+   private CacheManagerRegistryConfigurationEntry defaultEntry;
+
+   @XmlAttribute(name = "base-jndi-name", required = false)
+   private String baseJndiName = "java:CacheManager";
+   
+   @XmlElement(name = "infinispan-config")
+   private List<CacheManagerRegistryConfigurationEntry> entries;
+   
+   public CacheManagerRegistryConfigurationEntry getDefaultEntry()
+   {
+      return this.defaultEntry;
+   }
+   
+   public void setDefaultEntry(CacheManagerRegistryConfigurationEntry defaultEntry)
+   {
+      this.defaultEntry = defaultEntry;
+   }
+   
+   public List<CacheManagerRegistryConfigurationEntry> getEntries()
+   {
+      return this.entries;
+   }
+
+   public void setEntries(List<CacheManagerRegistryConfigurationEntry> entries)
+   {
+      this.entries = entries;
+   }
+
+   public String getBaseJndiName()
+   {
+      return this.baseJndiName;
+   }
+
+   public void setBaseJndiName(String baseJndiName)
+   {
+      this.baseJndiName = baseJndiName;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationEntry.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationEntry.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationEntry.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.XmlType;
+
+import org.infinispan.config.InfinispanConfiguration;
+
+/**
+ * A cache manager registry configuration entry.
+ * @author Paul Ferraro
+ */
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType
+public class CacheManagerRegistryConfigurationEntry
+{
+   @XmlID
+   @XmlAttribute(name = "name", required = true)
+   private String id;
+   @XmlAttribute(name = "jndi-name", required = false)
+   private String jndiName;
+   
+   @XmlElementRef
+   private InfinispanConfiguration configuration;
+
+   public String getId()
+   {
+      return this.id;
+   }
+   
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+   
+   public String getJndiName()
+   {
+      return this.jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+   
+   public InfinispanConfiguration getConfiguration()
+   {
+      return this.configuration;
+   }
+   
+   public void setConfiguration(InfinispanConfiguration configuration)
+   {
+      this.configuration = configuration;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationSource.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/CacheManagerRegistryConfigurationSource.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config;
+
+/**
+ * A source of cache manager registry configuration.
+ * @author Paul Ferraro
+ */
+public interface CacheManagerRegistryConfigurationSource
+{
+   /**
+    * Retrieves a cache manager registry configuration.
+    * @return a cache manager registry configuration
+    * @throws Exception if the configuration could not be retrieved.
+    */
+   CacheManagerRegistryConfiguration getRegistryConfiguration() throws Exception;
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSource.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSource.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config;
+
+/**
+ * A trivial cache manager registry source implementation.
+ * @author Paul Ferraro
+ */
+public class SimpleCacheManagerRegistryConfigurationSource implements CacheManagerRegistryConfigurationSource
+{
+   private final CacheManagerRegistryConfiguration configuration;
+   
+   /**
+    * Creates a new SimpleCacheManagerRegistryConfigurationSource using the specified configuration.
+    * @param configuration the cache manager registry configuration.
+    */
+   public SimpleCacheManagerRegistryConfigurationSource(CacheManagerRegistryConfiguration configuration)
+   {
+      this.configuration = configuration;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource#getRegistryConfiguration()
+    */
+   @Override
+   public CacheManagerRegistryConfiguration getRegistryConfiguration()
+   {
+      return this.configuration;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSource.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSource.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.infinispan.config.InfinispanConfiguration;
+
+/**
+ * A source for a cache manager registry that parses an single Infinispan cache manager configuration file.
+ * @author Paul Ferraro
+ */
+public class SingleCacheManagerRegistryConfigurationSource implements CacheManagerRegistryConfigurationSource
+{
+   private final String id;
+   private final String jndiName;
+   private final String resource;
+   
+   /**
+    * Creates a new SingleCacheManagerRegistryConfigurationSource
+    * @param id the identifier of the singleton cache manager
+    * @param jndiName the jndi name for the cache manager
+    * @param resource the classpath resource containing the infinispan cache manager configuration.
+    */
+   public SingleCacheManagerRegistryConfigurationSource(String id, String jndiName, String resource)
+   {
+      this.id = id;
+      this.jndiName = jndiName;
+      this.resource = resource;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource#getRegistryConfiguration()
+    */
+   @Override
+   public CacheManagerRegistryConfiguration getRegistryConfiguration() throws IOException
+   {
+      CacheManagerRegistryConfigurationEntry entry = new CacheManagerRegistryConfigurationEntry();
+      entry.setId(this.id);
+      entry.setJndiName(this.jndiName);
+      entry.setConfiguration(InfinispanConfiguration.newInfinispanConfiguration(this.resource));
+      
+      CacheManagerRegistryConfiguration registry = new CacheManagerRegistryConfiguration();
+      registry.setDefaultEntry(entry);
+      registry.setEntries(Collections.singletonList(entry));
+      
+      return registry;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/package-info.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/package-info.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/package-info.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ */
+ at XmlSchema(namespace = "urn:jboss:infinispan-configs:1.0", elementFormDefault = XmlNsForm.QUALIFIED)
+package org.jboss.ha.infinispan.config;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
\ No newline at end of file

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolver.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolver.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolver.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config.xml;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+/**
+ * A custom resource resolver that can override the locations for resources by namespace.
+ * 
+ * @author Paul Ferraro
+ */
+public class NamespaceResourceResolver implements LSResourceResolver
+{
+   private final Map<String, Map<String, URL>> types;
+   private final DOMImplementationLS implementation;
+   
+   /**
+    * Creates a new NamespaceResourceResolver using the specified set of target resource URLs, identified by namespace, per resource type.
+    * Uses the default DOM load-store implementation.
+    * @param types a map of resource type to map of namespace to resource location
+    */
+   public NamespaceResourceResolver(Map<String, Map<String, URL>> types)
+   {
+      this(types, defaultImplementation());
+   }
+   
+   /**
+    * Creates a new NamespaceResourceResolver using the specified set of target resource URLs, identified by namespace, per resource type.
+    * @param types a map of resource type to map of namespace to resource location
+    * @param implementation a DOM load-store implementation
+    */
+   public NamespaceResourceResolver(Map<String, Map<String, URL>> types, DOMImplementationLS implementation)
+   {
+      this.types = types;
+      this.implementation = implementation;
+   }
+   
+   private static DOMImplementationLS defaultImplementation()
+   {
+      try
+      {
+         return (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new IllegalStateException(e);
+      }
+      catch (InstantiationException e)
+      {
+         throw new IllegalStateException(e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new IllegalStateException(e);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+    */
+   @Override
+   public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI)
+   {
+      LSInput input = this.implementation.createLSInput();
+      
+      input.setPublicId(publicId);
+      input.setSystemId(systemId);
+      input.setBaseURI(baseURI);
+      
+      Map<String, URL> namespaces = this.types.get(type);
+      
+      if (namespaces != null)
+      {
+         URL url = namespaces.get(namespaceURI);
+         
+         if (url != null)
+         {
+            // Substitute our system id, since we have a matching type and namespace
+            input.setSystemId(url.toString());
+         }
+      }
+      
+      return input;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSource.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSource.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.ha.infinispan.config.xml;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.SchemaFactory;
+
+import org.infinispan.config.InfinispanConfiguration;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfiguration;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource;
+import org.xml.sax.SAXException;
+
+/**
+ * A source for a cache manager registry that parses an XML file containing a series of infinispan cache manager configurations.
+ * @author Paul Ferraro
+ */
+public class XMLCacheManagerRegistryConfigurationSource implements CacheManagerRegistryConfigurationSource
+{
+   private static final String SCHEMA = "META-INF/infinispan-configs.xsd";
+   private static final String DEFAULT_XML = "infinispan-configs.xml";
+   
+   private static final String INFINISPAN_NAMESPACE = "urn:infinispan:config:4.0";   
+   private static final String INFINISPAN_SCHEMA = InfinispanConfiguration.resolveSchemaPath();
+
+   private final URL infinispanSchemaURL;
+   private final URL schemaURL;
+   private final URL xmlURL;
+   
+   /**
+    * Creates a new XMLCacheManagerRegistryConfigurationSource using the {@link #DEFAULT_XML} classpath resource
+    * containing the cache manager registry configuration.
+    */
+   public XMLCacheManagerRegistryConfigurationSource()
+   {
+      this(DEFAULT_XML);
+   }
+   
+   /**
+    * Creates a new XMLCacheManagerRegistryConfigurationSource using the specified location containing
+    * the cache manager registry configuration.
+    * @param url the location of the cache manager registry configuration
+    */
+   public XMLCacheManagerRegistryConfigurationSource(URL url)
+   {
+      this(url, defaultClassLoader());
+   }
+   
+   /**
+    * Creates a new XMLCacheManagerRegistryConfigurationSource using the specified classpath resource containing
+    * the cache manager registry configuration.
+    * @param resource the classpath resource containing the cache manager registry configuration
+    */
+   public XMLCacheManagerRegistryConfigurationSource(String resource)
+   {
+      this(resource, defaultClassLoader());
+   }
+   
+   /**
+    * Creates a new XMLCacheManagerRegistryConfigurationSource using the specified classpath resource containing
+    * the cache manager registry configuration and specified class loader to locate the specified resource and relevant schemas.
+    * @param resource the classpath resource containing the cache manager registry configuration
+    * @param loader the class loader used to locate the specified resource and relevant schemas
+    */
+   public XMLCacheManagerRegistryConfigurationSource(String resource, ClassLoader loader)
+   {
+      this(findResource(resource, loader), loader);
+   }
+   
+   /**
+    * Creates a new XMLCacheManagerRegistryConfigurationSource using the specified location containing
+    * the cache manager registry configuration and specified class loader to locate relevant schemas.
+    * @param url the location of the cache manager registry configuration
+    * @param loader the class loader used to locate relevant schemas
+    */
+   public XMLCacheManagerRegistryConfigurationSource(URL url, ClassLoader loader)
+   {
+      this.xmlURL = url;
+      this.schemaURL = findResource(SCHEMA, loader);
+      this.infinispanSchemaURL = findResource(INFINISPAN_SCHEMA, loader);
+   }
+   
+   private static ClassLoader defaultClassLoader()
+   {
+      return Thread.currentThread().getContextClassLoader();
+   }
+   
+   private static URL findResource(String resource, ClassLoader loader)
+   {
+      URL url = loader.getResource(resource);
+      
+      if (url == null)
+      {
+         throw new IllegalArgumentException("Failed to locate resource: " + resource);
+      }
+      
+      return url;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource#getRegistryConfiguration()
+    */
+   @Override
+   public CacheManagerRegistryConfiguration getRegistryConfiguration() throws JAXBException, SAXException
+   {
+      SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+      // Resolve Infinispan schema against schema found in classpath
+      Map<String, URL> schemaURLs = Collections.singletonMap(INFINISPAN_NAMESPACE, this.infinispanSchemaURL);
+      schemaFactory.setResourceResolver(new NamespaceResourceResolver(Collections.singletonMap(XMLConstants.W3C_XML_SCHEMA_NS_URI, schemaURLs)));
+      
+      Unmarshaller unmarshaller = JAXBContext.newInstance(CacheManagerRegistryConfiguration.class).createUnmarshaller();
+      unmarshaller.setSchema(schemaFactory.newSchema(this.schemaURL));
+      
+      return (CacheManagerRegistryConfiguration) unmarshaller.unmarshal(this.xmlURL);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<xs:schema targetNamespace="urn:jboss:infinispan-configs:1.0" xmlns:tns="urn:jboss:infinispan-configs:1.0" xmlns:ispn="urn:infinispan:config:4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0">
+
+  <xs:import namespace="urn:infinispan:config:4.0" schemaLocation="http://docs.jboss.org/infinispan/schemas/infinispan-config-4.1.xsd"/>
+  
+  <xs:element name="infinispan-configs" type="tns:cacheManagerRegistryConfiguration"/>
+  
+  <xs:complexType name="cacheManagerRegistryConfiguration">
+  	<xs:sequence>
+  	  <xs:element name="infinispan-config" type="tns:cacheManagerRegistryConfigurationEntry" maxOccurs="unbounded"/>
+  	</xs:sequence>
+    <xs:attribute name="default" type="xs:IDREF"/>
+    <xs:attribute name="base-jndi-name" type="xs:string" default="java:CacheManager"/>
+  </xs:complexType>
+  
+  <xs:complexType name="cacheManagerRegistryConfigurationEntry">
+  	<xs:sequence>
+      <xs:element ref="ispn:infinispan"/>
+  	</xs:sequence>
+  	<xs:attribute name="name" type="xs:ID" use="required"/>
+    <xs:attribute name="jndi-name" type="xs:string"/>
+  </xs:complexType>
+</xs:schema>
\ No newline at end of file

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerFactoryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerFactoryTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerFactoryTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,100 @@
+package org.jboss.ha.infinispan;
+
+import java.net.URL;
+import java.util.Collections;
+
+import junit.framework.Assert;
+
+import org.easymock.EasyMock;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+import org.jgroups.ChannelFactory;
+import org.jgroups.JChannel;
+import org.junit.Test;
+
+ at SuppressWarnings("deprecation")
+public class CacheManagerFactoryTest
+{
+   @Test
+   public void test() throws Exception
+   {
+      CacheManagerConfiguration configuration = EasyMock.createStrictMock(CacheManagerConfiguration.class);
+      ChannelFactory channelFactory = EasyMock.createStrictMock(ChannelFactory.class);
+      GlobalConfiguration globalConfiguration = new GlobalConfiguration();
+      globalConfiguration.setTransportClass(JGroupsTransport.class.getName());
+      globalConfiguration.setClusterName("mychannel");
+      
+      Configuration defaultConfiguration = new Configuration();
+      Configuration namedConfiguration = new NamedConfiguration("custom");
+
+      CacheManagerFactory factory = new CacheManagerFactoryImpl(channelFactory);
+      
+      EasyMock.expect(configuration.getGlobalConfiguration()).andReturn(globalConfiguration);
+      EasyMock.expect(configuration.getDefaultConfiguration()).andReturn(defaultConfiguration);
+      EasyMock.expect(configuration.getConfigurations()).andReturn(Collections.singletonList(namedConfiguration));
+      
+      EasyMock.replay(configuration, channelFactory);
+      
+      CacheManager result = factory.createCacheManager(configuration);
+      
+      try
+      {
+         EasyMock.verify(configuration, channelFactory);
+         
+         Assert.assertTrue(result instanceof EmbeddedCacheManager);
+         EmbeddedCacheManager manager = (EmbeddedCacheManager) result;
+         
+         Assert.assertEquals(globalConfiguration, manager.getGlobalConfiguration());
+         Assert.assertEquals(defaultConfiguration, manager.getDefaultConfiguration());
+         Assert.assertEquals(Collections.singleton("custom"), manager.getCacheNames());
+         Assert.assertSame(ComponentStatus.INSTANTIATED, manager.getStatus());
+         Assert.assertEquals("mychannel", manager.getClusterName());
+         Assert.assertFalse(manager.isCoordinator());
+         Assert.assertNull(manager.getAddress());
+         Assert.assertNull(manager.getMembers());
+         
+         EasyMock.reset(configuration, channelFactory);
+   
+         URL url = Thread.currentThread().getContextClassLoader().getResource("config-samples/jgroups-udp.xml");
+         EasyMock.expect(channelFactory.createMultiplexerChannel(CacheManagerFactoryImpl.ChannelFactoryChannelLookup.DEFAULT_STACK, "mychannel")).andReturn(new JChannel(url));
+         
+         EasyMock.replay(channelFactory);
+         
+         Cache<?, ?> cache = manager.getCache();
+   
+         try
+         {
+            EasyMock.verify(channelFactory);
+      
+            Assert.assertSame(ComponentStatus.RUNNING, cache.getStatus());
+            Assert.assertSame(manager, cache.getCacheManager());
+            Assert.assertSame(ComponentStatus.RUNNING, manager.getStatus());
+            Assert.assertTrue(manager.isCoordinator());
+            Assert.assertEquals(Collections.singletonList(manager.getAddress()), manager.getMembers());
+         }
+         finally
+         {
+            cache.stop();
+         }
+      }
+      finally
+      {
+         result.stop();
+      }
+   }
+   
+   public static class NamedConfiguration extends Configuration
+   {
+      private static final long serialVersionUID = -6362167959914418561L;
+
+      public NamedConfiguration(String name)
+      {
+         this.name = name;
+      }
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerRegistryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerRegistryTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/CacheManagerRegistryTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,183 @@
+package org.jboss.ha.infinispan;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.Context;
+
+import junit.framework.Assert;
+
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.InfinispanConfiguration;
+import org.infinispan.manager.CacheManager;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfiguration;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationEntry;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource;
+import org.junit.Test;
+
+public class CacheManagerRegistryTest
+{
+   /**
+    * Test with unspecified default config and default base jndi name
+    * @throws Exception
+    */
+   @Test
+   public void defaults() throws Exception
+   {
+      CacheManagerFactory factory = EasyMock.createStrictMock(CacheManagerFactory.class);
+      CacheManagerRegistryConfigurationSource source = EasyMock.createStrictMock(CacheManagerRegistryConfigurationSource.class);
+      CacheManager defaultCacheManager = EasyMock.createStrictMock(CacheManager.class);
+      CacheManager otherCacheManager = EasyMock.createStrictMock(CacheManager.class);
+      Context context = EasyMock.createStrictMock(Context.class);
+      Capture<CacheManagerConfiguration> capturedConfiguration = new Capture<CacheManagerConfiguration>(CaptureType.ALL);
+      
+      InfinispanConfiguration config = InfinispanConfiguration.newInfinispanConfiguration("config-samples/minimal.xml");
+
+      CacheManagerRegistryConfigurationEntry entry1 = new CacheManagerRegistryConfigurationEntry();
+      
+      entry1.setId("default");
+      entry1.setConfiguration(config);
+
+      CacheManagerRegistryConfigurationEntry entry2 = new CacheManagerRegistryConfigurationEntry();
+      
+      entry2.setId("other");
+      entry2.setConfiguration(config);
+      
+      CacheManagerRegistryConfiguration configRegistry = new CacheManagerRegistryConfiguration();
+      configRegistry.setEntries(Arrays.asList(entry1, entry2));
+      
+      CacheManagerRegistryImpl registry = new CacheManagerRegistryImpl(factory, source, context);
+      
+      EasyMock.expect(source.getRegistryConfiguration()).andReturn(configRegistry);
+      
+      EasyMock.expect(factory.createCacheManager(EasyMock.capture(capturedConfiguration))).andReturn(defaultCacheManager);
+      EasyMock.expect(context.composeName("default", "java:CacheManager")).andReturn("java:CacheManager/default");
+      
+      context.bind("java:CacheManager/default", defaultCacheManager);
+
+      EasyMock.expect(factory.createCacheManager(EasyMock.capture(capturedConfiguration))).andReturn(otherCacheManager);
+      EasyMock.expect(context.composeName("other", "java:CacheManager")).andReturn("java:CacheManager/other");
+      
+      context.bind("java:CacheManager/other", otherCacheManager);
+
+      EasyMock.replay(factory, source, context, defaultCacheManager, otherCacheManager);
+      
+      registry.start();
+      
+      EasyMock.verify(factory, source, context, defaultCacheManager, otherCacheManager);
+      
+      Set<String> names = registry.getCacheManagers();
+      Assert.assertEquals(2, names.size());
+      Assert.assertTrue(names.contains("default"));
+      Assert.assertTrue(names.contains("other"));
+      
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager(null));
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager("default"));
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager("unknown"));
+      Assert.assertSame(otherCacheManager, registry.getCacheManager("other"));
+
+      List<CacheManagerConfiguration> configurations = capturedConfiguration.getValues();
+      Assert.assertEquals(2, configurations.size());
+      
+      for (CacheManagerConfiguration configuration: configurations)
+      {
+         Assert.assertSame(config.parseGlobalConfiguration(), configuration.getGlobalConfiguration());
+         Assert.assertSame(config.parseDefaultConfiguration(), configuration.getDefaultConfiguration());
+         Map<String, Configuration> namedConfigurations = config.parseNamedConfigurations();
+         Collection<Configuration> configs = configuration.getConfigurations();
+         Assert.assertEquals(namedConfigurations.size(), configs.size());
+         for (Configuration c: configs)
+         {
+            Assert.assertSame(namedConfigurations.get(c.getName()), c);
+         }
+      }
+      
+      EasyMock.reset(factory, source, context, defaultCacheManager, otherCacheManager);
+   }
+   
+   /**
+    * Test with custom default config and custom base jndi name
+    * @throws Exception
+    */
+   @Test
+   public void custom() throws Exception
+   {
+      CacheManagerFactory factory = EasyMock.createStrictMock(CacheManagerFactory.class);
+      CacheManagerRegistryConfigurationSource provider = EasyMock.createStrictMock(CacheManagerRegistryConfigurationSource.class);
+      CacheManager defaultCacheManager = EasyMock.createStrictMock(CacheManager.class);
+      CacheManager otherCacheManager = EasyMock.createStrictMock(CacheManager.class);
+      Context context = EasyMock.createStrictMock(Context.class);
+      Capture<CacheManagerConfiguration> capturedConfiguration = new Capture<CacheManagerConfiguration>(CaptureType.ALL);
+      
+      InfinispanConfiguration config = InfinispanConfiguration.newInfinispanConfiguration("config-samples/minimal.xml");
+
+      CacheManagerRegistryConfigurationEntry entry1 = new CacheManagerRegistryConfigurationEntry();
+      
+      entry1.setId("other");
+      entry1.setConfiguration(config);
+      entry1.setJndiName("java:other");
+      
+      CacheManagerRegistryConfigurationEntry entry2 = new CacheManagerRegistryConfigurationEntry();
+      
+      entry2.setId("default");
+      entry2.setConfiguration(config);
+      
+      CacheManagerRegistryConfiguration configRegistry = new CacheManagerRegistryConfiguration();
+      configRegistry.setEntries(Arrays.asList(entry1, entry2));
+      configRegistry.setDefaultEntry(entry2);
+      configRegistry.setBaseJndiName("java:Infinispan");
+      
+      CacheManagerRegistryImpl registry = new CacheManagerRegistryImpl(factory, provider, context);
+      
+      EasyMock.expect(provider.getRegistryConfiguration()).andReturn(configRegistry);
+      
+      EasyMock.expect(factory.createCacheManager(EasyMock.capture(capturedConfiguration))).andReturn(otherCacheManager);
+      
+      context.bind("java:other", otherCacheManager);
+
+      EasyMock.expect(factory.createCacheManager(EasyMock.capture(capturedConfiguration))).andReturn(defaultCacheManager);
+      EasyMock.expect(context.composeName("default", "java:Infinispan")).andReturn("java:Infinispan/default");
+      
+      context.bind("java:Infinispan/default", defaultCacheManager);
+
+      EasyMock.replay(factory, provider, context, defaultCacheManager, otherCacheManager);
+      
+      registry.start();
+      
+      EasyMock.verify(factory, provider, context, defaultCacheManager, otherCacheManager);
+      
+      Set<String> names = registry.getCacheManagers();
+      Assert.assertEquals(2, names.size());
+      Assert.assertTrue(names.contains("default"));
+      Assert.assertTrue(names.contains("other"));
+      
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager(null));
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager("default"));
+      Assert.assertSame(defaultCacheManager, registry.getCacheManager("unknown"));
+      Assert.assertSame(otherCacheManager, registry.getCacheManager("other"));
+
+      List<CacheManagerConfiguration> configurations = capturedConfiguration.getValues();
+      Assert.assertEquals(2, configurations.size());
+      
+      for (CacheManagerConfiguration configuration: configurations)
+      {
+         Assert.assertSame(config.parseGlobalConfiguration(), configuration.getGlobalConfiguration());
+         Assert.assertSame(config.parseDefaultConfiguration(), configuration.getDefaultConfiguration());
+         Map<String, Configuration> namedConfigurations = config.parseNamedConfigurations();
+         Collection<Configuration> configs = configuration.getConfigurations();
+         Assert.assertEquals(namedConfigurations.size(), configs.size());
+         for (Configuration c: configs)
+         {
+            Assert.assertSame(namedConfigurations.get(c.getName()), c);
+         }
+      }
+      
+      EasyMock.reset(factory, provider, context, defaultCacheManager, otherCacheManager);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSourceTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSourceTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SimpleCacheManagerRegistryConfigurationSourceTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,17 @@
+package org.jboss.ha.infinispan.config;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SimpleCacheManagerRegistryConfigurationSourceTest
+{
+   @Test
+   public void test() throws Exception
+   {
+      CacheManagerRegistryConfiguration configuration = new CacheManagerRegistryConfiguration();
+      
+      CacheManagerRegistryConfigurationSource source = new SimpleCacheManagerRegistryConfigurationSource(configuration);
+      
+      Assert.assertSame(configuration, source.getRegistryConfiguration());
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSourceTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSourceTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/SingleCacheManagerRegistryConfigurationSourceTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,31 @@
+package org.jboss.ha.infinispan.config;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SingleCacheManagerRegistryConfigurationSourceTest
+{
+   @Test
+   public void testDefault() throws Exception
+   {
+      CacheManagerRegistryConfigurationSource source = new SingleCacheManagerRegistryConfigurationSource("default", "java:SingleCacheManager", "config-samples/minimal.xml");
+      
+      CacheManagerRegistryConfiguration configuration = source.getRegistryConfiguration();
+      
+      Assert.assertEquals("java:CacheManager", configuration.getBaseJndiName());
+      
+      List<CacheManagerRegistryConfigurationEntry> entries = configuration.getEntries();
+      
+      Assert.assertEquals(1, entries.size());
+      
+      CacheManagerRegistryConfigurationEntry entry = entries.get(0);
+      
+      Assert.assertSame(entry, configuration.getDefaultEntry());
+      
+      Assert.assertEquals("default", entry.getId());
+      Assert.assertEquals("java:SingleCacheManager", entry.getJndiName());
+      Assert.assertEquals(0, entry.getConfiguration().parseNamedConfigurations().size());
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolverTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolverTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/NamespaceResourceResolverTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,71 @@
+package org.jboss.ha.infinispan.config.xml;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collections;
+
+import org.jboss.ha.infinispan.config.xml.NamespaceResourceResolver;
+import org.junit.Assert;
+import org.junit.Test;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+public class NamespaceResourceResolverTest
+{
+   @Test
+   public void test() throws IOException
+   {
+      File file = File.createTempFile("test", "test");
+      file.deleteOnExit();
+      
+      URL url = file.toURI().toURL();
+      String type = "my-type";
+      String namespace = "urn:my:namespace:1.0";
+      String publicId = "my-public-id";
+      String systemId = "my-system-id";
+      String baseURI = "my-base-uri";
+      
+      LSResourceResolver resolver = new NamespaceResourceResolver(Collections.singletonMap(type, Collections.singletonMap(namespace, url)));
+      
+      LSInput result = resolver.resolveResource("some-type", "namespace-uri", publicId, systemId, baseURI);
+      
+      Assert.assertNull(result.getByteStream());
+      Assert.assertNull(result.getCharacterStream());
+      Assert.assertNull(result.getStringData());
+      Assert.assertFalse(result.getCertifiedText());
+      Assert.assertSame(publicId, result.getPublicId());
+      Assert.assertSame(systemId, result.getSystemId());
+      Assert.assertSame(baseURI, result.getBaseURI());
+      
+      result = resolver.resolveResource(type, "namespace-uri", publicId, systemId, baseURI);
+      
+      Assert.assertNull(result.getByteStream());
+      Assert.assertNull(result.getCharacterStream());
+      Assert.assertNull(result.getStringData());
+      Assert.assertFalse(result.getCertifiedText());
+      Assert.assertSame(publicId, result.getPublicId());
+      Assert.assertSame(systemId, result.getSystemId());
+      Assert.assertSame(baseURI, result.getBaseURI());
+      
+      result = resolver.resolveResource("some-type", namespace, publicId, systemId, baseURI);
+      
+      Assert.assertNull(result.getByteStream());
+      Assert.assertNull(result.getCharacterStream());
+      Assert.assertNull(result.getStringData());
+      Assert.assertFalse(result.getCertifiedText());
+      Assert.assertSame(publicId, result.getPublicId());
+      Assert.assertSame(systemId, result.getSystemId());
+      Assert.assertSame(baseURI, result.getBaseURI());
+      
+      result = resolver.resolveResource(type, namespace, publicId, systemId, baseURI);
+      
+      Assert.assertNull(result.getByteStream());
+      Assert.assertNull(result.getCharacterStream());
+      Assert.assertNull(result.getStringData());
+      Assert.assertFalse(result.getCertifiedText());
+      Assert.assertSame(publicId, result.getPublicId());
+      Assert.assertEquals(url.toString(), result.getSystemId());
+      Assert.assertSame(baseURI, result.getBaseURI());
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/infinispan/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,68 @@
+package org.jboss.ha.infinispan.config.xml;
+
+import java.util.List;
+
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfiguration;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationEntry;
+import org.jboss.ha.infinispan.config.CacheManagerRegistryConfigurationSource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class XMLCacheManagerRegistryConfigurationSourceTest
+{
+   @Test
+   public void testDefault() throws Exception
+   {
+      CacheManagerRegistryConfigurationSource provider = new XMLCacheManagerRegistryConfigurationSource();
+      
+      CacheManagerRegistryConfiguration configuration = provider.getRegistryConfiguration();
+      
+      Assert.assertEquals("java:CacheManager", configuration.getBaseJndiName());
+      Assert.assertNull(configuration.getDefaultEntry());
+      
+      List<CacheManagerRegistryConfigurationEntry> entries = configuration.getEntries();
+      
+      Assert.assertEquals(1, entries.size());
+      
+      CacheManagerRegistryConfigurationEntry entry = entries.get(0);
+      
+      Assert.assertEquals("default", entry.getId());
+      Assert.assertNull(entry.getJndiName());
+      Assert.assertEquals(7, entry.getConfiguration().parseNamedConfigurations().size());
+   }
+   
+   @Test
+   public void testMultiple() throws Exception
+   {
+      CacheManagerRegistryConfigurationSource provider = new XMLCacheManagerRegistryConfigurationSource("infinispan-configs-multiple.xml");
+      
+      CacheManagerRegistryConfiguration registry = provider.getRegistryConfiguration();
+      
+      Assert.assertEquals("java:CacheManagers", registry.getBaseJndiName());
+      
+      List<CacheManagerRegistryConfigurationEntry> entries = registry.getEntries();
+      
+      Assert.assertEquals(3, entries.size());
+      
+      CacheManagerRegistryConfigurationEntry entry = entries.get(0);
+      
+      Assert.assertEquals("manager0", entry.getId());
+      Assert.assertNull(entry.getJndiName());
+      Assert.assertNotSame(entry, registry.getDefaultEntry());
+      Assert.assertEquals(0, entry.getConfiguration().parseNamedConfigurations().size());
+      
+      entry = entries.get(1);
+      
+      Assert.assertEquals("manager1", entry.getId());
+      Assert.assertNull(entry.getJndiName());
+      Assert.assertSame(entry, registry.getDefaultEntry());
+      Assert.assertEquals(0, entry.getConfiguration().parseNamedConfigurations().size());
+      
+      entry = entries.get(2);
+      
+      Assert.assertEquals("manager2", entry.getId());
+      Assert.assertEquals("java:CacheManager2", entry.getJndiName());
+      Assert.assertNotSame(entry, registry.getDefaultEntry());
+      Assert.assertEquals(0, entry.getConfiguration().parseNamedConfigurations().size());
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan-configs default="manager1" base-jndi-name="java:CacheManagers" xmlns="urn:jboss:infinispan-configs:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:infinispan-configs:1.0 ../../src/main/resources/infinispan-configs.xsd">
+  <infinispan-config name="manager0">
+    <infinispan xmlns="urn:infinispan:config:4.0"/>
+  </infinispan-config>
+  <infinispan-config name="manager1">
+    <infinispan xmlns="urn:infinispan:config:4.0"/>
+  </infinispan-config>
+  <infinispan-config name="manager2" jndi-name="java:CacheManager2">
+    <infinispan xmlns="urn:infinispan:config:4.0"/>
+  </infinispan-config>
+</infinispan-configs>
\ No newline at end of file

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs.xml
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs.xml	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/resources/infinispan-configs.xml	2010-07-02 15:04:36 UTC (rev 106401)
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan-configs xmlns="urn:jboss:infinispan-configs:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:infinispan-configs:1.0 ../../src/main/resources/infinispan-configs.xsd">
+  <infinispan-config name="default">
+     <!-- *************************** -->
+     <!-- System-wide global settings -->
+     <!-- *************************** -->
+     <infinispan xmlns="urn:infinispan:config:4.0">
+
+       <global>
+
+          <!-- Note that if these are left blank, defaults are used.  See the user guide for what these defaults are -->
+          <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+             <properties>
+              <property name="maxThreads" value="5"/>
+              <property name="threadNamePrefix" value="AsyncListenerThread"/>
+             </properties>
+          </asyncListenerExecutor>
+    
+          <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+             <properties>
+              <property name="maxThreads" value="25"/>
+              <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 enabled="true" jmxDomain="infinispan"/>
+    
+          <!--
+             If the transport is omitted, there is no way to create distributed or clustered caches.
+             There is no added cost to defining a transport but not creating a cache that uses one, since the transport
+             is created and initialized lazily.
+          -->
+          <transport clusterName="infinispan-cluster" distributedSyncTimeout="50000" nodeName="Jalapeno"/>
+             <!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
+             <!-- See the JGroupsTransport javadocs for more flags -->
+    
+          <!-- Again, sensible defaults are used here if this is omitted.  -->
+          <serialization marshallerClass="org.infinispan.marshall.VersionAwareMarshaller" version="1.0"/>
+    
+          <!--
+             Used to register JVM shutdown hooks.
+             hookBehavior: DEFAULT, REGISTER, DONT_REGISTER
+          -->
+          <shutdown hookBehavior="DEFAULT"/>
+       </global>
+    
+       <!-- *************************** -->
+       <!-- Default "template" settings -->
+       <!-- *************************** -->
+       <!-- this is used as a "template" configuration for all caches in the system. -->
+       <default xmlns="urn:infinispan:config:4.0">
+          <!--
+             isolation levels supported: READ_COMMITTED and REPEATABLE_READ
+          -->
+          <locking
+                isolationLevel="REPEATABLE_READ"
+                lockAcquisitionTimeout="20000"
+                writeSkewCheck="false"
+                concurrencyLevel="500"
+                useLockStriping="true"
+                />
+    
+          <!--
+          Used to register a transaction manager and participate in ongoing transactions.
+          -->
+          <transaction
+                transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
+                syncRollbackPhase="false"
+                syncCommitPhase="false"
+                useEagerLocking="false"/>
+    
+          <!--
+          Used to register JMX statistics in any available MBean server
+          -->
+          <jmxStatistics enabled="false"/>
+    
+          <lazyDeserialization enabled="false"/>
+    
+          <!--
+             Used to enable invocation batching and allow the use of Cache.startBatch()/endBatch() methods.
+          -->
+          <invocationBatching enabled="false"/>
+    
+          <!--
+             This element specifies that the cache is clustered.
+             modes supported: distribution (d), replication (r) or invalidation (i).
+          -->
+          <clustering mode="replication">
+    
+             <!--
+                Defines whether to retrieve state on startup
+             -->
+             <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
+    
+             <!--
+                Network calls are synchronous.
+             -->
+             <sync replTimeout="20000"/>
+             <!--
+                Uncomment this for async replication.
+             -->
+             <!--<async useReplQueue="true" replQueueInterval="10000" replQueueMaxElements="500"/>-->
+          </clustering>
+    
+       </default>
+    
+       <!-- ************************************** -->
+       <!-- Individually configured "named" caches -->
+       <!-- ************************************** -->
+    
+       <namedCache name="asyncCache">
+          <clustering mode="replication">
+             <async asyncMarshalling="true"/>
+          </clustering>
+       </namedCache>
+    
+       <!-- Note that any of the elements appearing in a namedCache section can also appear in the default section as a template. -->
+       <namedCache name="evictionCache">
+    
+          <!--
+             Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
+             the eviction thread will never run.  A separate executor is used for eviction in each cache.
+          -->
+          <eviction wakeUpInterval="500" maxEntries="5000" strategy="FIFO"  threadPolicy="PIGGYBACK"/>
+          <expiration lifespan="60000" maxIdle="1000"/>
+       </namedCache>
+    
+    
+       <namedCache name="persistentCache">
+          <!--
+                Cache loaders.
+    
+                If passivation is enabled, state is offloaded to the cache loaders ONLY when evicted.  Similarly, when the state
+                is accessed again, it is removed from the cache loaderold and loaded into memory.
+    
+                Otherwise, state is always maintained in the cache loaderold as well as in memory.
+    
+                Set 'shared' to true if all instances in the cluster use the same cache loaderold instance, e.g., are talking to the
+                same database.
+    
+                If "preload" is true, all keys are loaded from the cache loaderold into memory upon starting the cache.
+             -->
+          <loaders passivation="false" shared="false" preload="true">
+    
+             <!--
+                We can have multiple cache loaders, which get chained
+             -->
+             <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="true"
+                     ignoreModifications="true" purgeOnStartup="true">
+    
+                <!-- See the documentation for more configuration examples and flags. -->
+                <properties>
+                   <property name="location" value="${java.io.tmpdir}"/>
+                </properties>
+                <singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000"/>
+                <async enabled="true" flushLockTimeout="15000" threadPoolSize="5"/>
+             </loader>
+          </loaders>
+    
+          <deadlockDetection enabled="true" spinDuration="1000"/>
+    
+       </namedCache>
+    
+       <namedCache name="distributedCache">
+          <clustering mode="distribution">
+             <sync/>
+             <!--
+                num owners: number of owners for each key.  The larger this number is, the safer your data will be, but the
+                            slower the cluster will be.
+    
+                rehashRpcTimeout: timeout used for RPC calls relating to rehashing.  This defaults to 600000 (10 minutes).
+             -->
+             <hash numOwners="3" rehashWait="120000" rehashRpcTimeout="600000"/>
+             <l1 enabled="true" lifespan="600000"/>
+          </clustering>
+       </namedCache>
+    
+       <namedCache name="withReplicatinQueue">
+          <clustering>
+             <async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
+          </clustering>
+       </namedCache>
+    
+       <namedCache name="lockPerEntry">
+          <locking useLockStriping="false" />
+       </namedCache>
+    
+       <namedCache name="cacheWithCustomInterceptors">
+          <!--
+          Define custom interceptors.  All custom interceptors need to extend org.jboss.cache.interceptors.base.CommandInterceptor
+          -->
+          <!--
+          <customInterceptors>
+             <interceptor position="first" class="com.mycompany.CustomInterceptor1">
+                <property name="com.mycompany.attributeOne" value="value1" />
+                <property name="com.mycompany.attributeTwo" value="value2" />
+             </interceptor>
+             <interceptor position="last" class="com.mycompany.CustomInterceptor2"/>
+             <interceptor index="3" class="com.mycompany.CustomInterceptor1"/>
+             <interceptor before="org.infinispanpan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor2"/>
+             <interceptor after="org.infinispanpan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor1"/>
+          </customInterceptors>
+          -->
+       </namedCache>
+    </infinispan>
+  </infinispan-config>
+</infinispan-configs>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list