[infinispan-commits] Infinispan SVN: r744 - trunk/core/src/main/java/org/infinispan/manager.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Aug 27 07:41:58 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-08-27 07:41:58 -0400 (Thu, 27 Aug 2009)
New Revision: 744

Modified:
   trunk/core/src/main/java/org/infinispan/manager/CacheManager.java
   trunk/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java
Log:
[ISPN-174] (CacheManager to expose a list of cache names)

Modified: trunk/core/src/main/java/org/infinispan/manager/CacheManager.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/manager/CacheManager.java	2009-08-27 11:40:59 UTC (rev 743)
+++ trunk/core/src/main/java/org/infinispan/manager/CacheManager.java	2009-08-27 11:41:58 UTC (rev 744)
@@ -12,6 +12,7 @@
 import org.infinispan.remoting.transport.Address;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * A <tt>CacheManager</tt> is the primary mechanism for retrieving a {@link org.infinispan.Cache} instance, and is often
@@ -58,20 +59,20 @@
    /**
     * Defines a named cache's configuration using the following algorithm:
     * <p/>
-    * If cache name hasn't been defined before, this method creates a clone of the default cache's configuration, 
+    * If cache name hasn't been defined before, this method creates a clone of the default cache's configuration,
     * applies a clone of the configuration overrides passed in and returns this configuration instance.
     * <p/>
-    * If cache name has been previously defined, this method creates a clone of this cache's existing configuration, 
+    * If cache name has been previously defined, this method creates a clone of this cache's existing configuration,
     * applies a clone of the configuration overrides passed in and returns the configuration instance.
     * <p/>
-    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache 
+    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache
     * manager.  This method enables you to override certain properties that have previously been defined via XML.
     * <p/>
-    * Passing a brand new Configuration instance as configuration override without having called any of its setters
-    * will effectively return the named cache's configuration since no overrides where passed to it.
+    * Passing a brand new Configuration instance as configuration override without having called any of its setters will
+    * effectively return the named cache's configuration since no overrides where passed to it.
     *
-    * @param cacheName              name of cache whose configuration is being defined
-    * @param configurationOverride  configuration overrides to use
+    * @param cacheName             name of cache whose configuration is being defined
+    * @param configurationOverride configuration overrides to use
     * @return a cloned configuration instance
     */
    Configuration defineConfiguration(String cacheName, Configuration configurationOverride);
@@ -79,24 +80,24 @@
    /**
     * Defines a named cache's configuration using the following algorithm:
     * <p/>
-    * Regardless of whether the cache name has been defined or not, this method creates a clone of the configuration 
-    * of the cache whose name matches the given template cache name, then applies a clone of the configuration overrides 
+    * Regardless of whether the cache name has been defined or not, this method creates a clone of the configuration of
+    * the cache whose name matches the given template cache name, then applies a clone of the configuration overrides
     * passed in and finally returns this configuration instance.
-    * <p/>  
-    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache manager.  
-    * This method enables you to override certain properties that have previously been defined via XML.
     * <p/>
-    * Passing a brand new Configuration instance as configuration override without having called any of its setters
-    * will effectively return the named cache's configuration since no overrides where passed to it.
+    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache
+    * manager. This method enables you to override certain properties that have previously been defined via XML.
     * <p/>
-    * If templateName is null or there isn't any named cache with that name, this methods works exactly like 
-    * {@link #defineConfiguration(String, Configuration)} in the sense that the base configuration used is the
-    * default cache configuration.
+    * Passing a brand new Configuration instance as configuration override without having called any of its setters will
+    * effectively return the named cache's configuration since no overrides where passed to it.
+    * <p/>
+    * If templateName is null or there isn't any named cache with that name, this methods works exactly like {@link
+    * #defineConfiguration(String, Configuration)} in the sense that the base configuration used is the default cache
+    * configuration.
     *
-    * @param cacheName              name of cache whose configuration is being defined
-    * @param templateName           name of cache to which to which apply overrides if cache name has not been previously 
-    *                               defined
-    * @param configurationOverride  configuration overrides to use
+    * @param cacheName             name of cache whose configuration is being defined
+    * @param templateName          name of cache to which to which apply overrides if cache name has not been previously
+    *                              defined
+    * @param configurationOverride configuration overrides to use
     * @return a cloned configuration instance
     */
    Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride);
@@ -116,8 +117,8 @@
     * <p/>
     * When creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
     * as a template, and then optionally apply any overrides previously defined for the named cache using the {@link
-    * #defineConfiguration(String, Configuration)} or {@link #defineConfiguration(String, String, Configuration)} methods, 
-    * or declared in the configuration file.
+    * #defineConfiguration(String, Configuration)} or {@link #defineConfiguration(String, String, Configuration)}
+    * methods, or declared in the configuration file.
     *
     * @param cacheName name of cache to retrieve
     * @return a cache instance identified by cacheName
@@ -138,7 +139,15 @@
    ComponentStatus getStatus();
 
    /**
-    * Returns the global configuration object associated to this CacheManager.
+    * @return the global configuration object associated to this CacheManager
     */
-   public GlobalConfiguration getGlobalConfiguration();
+   GlobalConfiguration getGlobalConfiguration();
+
+   /**
+    * If no named caches are registered, this method returns an empty set.  The default cache is never included in this
+    * set of cache names.
+    *
+    * @return an immutable set of non-default named caches registered with this cache manager.
+    */
+   Set<String> getCacheNames();
 }

Modified: trunk/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java	2009-08-27 11:40:59 UTC (rev 743)
+++ trunk/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java	2009-08-27 11:41:58 UTC (rev 744)
@@ -40,11 +40,12 @@
 import org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier;
 import org.infinispan.remoting.transport.Address;
 import org.infinispan.remoting.transport.Transport;
-import org.infinispan.util.FileLookup;
+import org.infinispan.util.Immutables;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -204,9 +205,9 @@
     * @param start             if true, the cache manager is started
     * @throws java.io.IOException if there is a problem with the configuration file.
     */
-   public DefaultCacheManager(String configurationFile, boolean start) throws IOException {      
+   public DefaultCacheManager(String configurationFile, boolean start) throws IOException {
       try {
-         initialize(InfinispanConfiguration.newInfinispanConfiguration(configurationFile,InfinispanConfiguration.resolveSchemaPath()));
+         initialize(InfinispanConfiguration.newInfinispanConfiguration(configurationFile, InfinispanConfiguration.resolveSchemaPath()));
       }
       catch (RuntimeException re) {
          throw new ConfigurationException(re);
@@ -235,9 +236,9 @@
     * @param start               if true, the cache manager is started
     * @throws java.io.IOException if there is a problem reading the configuration stream
     */
-   public DefaultCacheManager(InputStream configurationStream, boolean start) throws IOException {      
+   public DefaultCacheManager(InputStream configurationStream, boolean start) throws IOException {
       try {
-         initialize(InfinispanConfiguration.newInfinispanConfiguration(configurationStream,InfinispanConfiguration.findSchemaInputStream()));
+         initialize(InfinispanConfiguration.newInfinispanConfiguration(configurationStream, InfinispanConfiguration.findSchemaInputStream()));
       } catch (ConfigurationException ce) {
          throw ce;
       } catch (RuntimeException re) {
@@ -252,24 +253,28 @@
          Configuration c = globalConfiguration.getDefaultConfiguration().clone();
          c.applyOverrides(entry.getValue());
          configurationOverrides.put(entry.getKey(), c);
-         
+
       }
       globalComponentRegistry = new GlobalComponentRegistry(globalConfiguration, this);
    }
 
-   /** {@inheritDoc} */
+   /**
+    * {@inheritDoc}
+    */
    public Configuration defineConfiguration(String cacheName, Configuration configurationOverride) {
       return defineConfiguration(cacheName, configurationOverride, globalConfiguration.getDefaultConfiguration(), true);
    }
 
-   /** {@inheritDoc} */
+   /**
+    * {@inheritDoc}
+    */
    public Configuration defineConfiguration(String cacheName, String templateName, Configuration configurationOverride) {
       if (templateName != null) {
          Configuration c = configurationOverrides.get(templateName);
          if (c != null)
             return defineConfiguration(cacheName, configurationOverride, c, false);
          return defineConfiguration(cacheName, configurationOverride);
-      } 
+      }
       return defineConfiguration(cacheName, configurationOverride);
    }
 
@@ -284,7 +289,7 @@
             existing.applyOverrides(configOverride);
             return existing.clone();
          }
-      } 
+      }
       Configuration configuration = defaultConfigIfNotPresent.clone();
       configuration.applyOverrides(configOverride.clone());
       configurationOverrides.put(cacheName, configuration);
@@ -309,8 +314,8 @@
     * <p/>
     * When creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
     * as a template, and then optionally apply any overrides previously defined for the named cache using the {@link
-    * #defineConfiguration(String, Configuration)} or {@link #defineConfiguration(String, String, Configuration)} methods, 
-    * or declared in the configuration file.
+    * #defineConfiguration(String, Configuration)} or {@link #defineConfiguration(String, String, Configuration)}
+    * methods, or declared in the configuration file.
     *
     * @param cacheName name of cache to retrieve
     * @return a cache instance identified by cacheName
@@ -350,9 +355,9 @@
 
    private Cache createCache(String cacheName) {
       Configuration c = null;
-      if (cacheName.equals(DEFAULT_CACHE_NAME) || !configurationOverrides.containsKey(cacheName)) 
+      if (cacheName.equals(DEFAULT_CACHE_NAME) || !configurationOverrides.containsKey(cacheName))
          c = globalConfiguration.getDefaultConfiguration().clone();
-      else 
+      else
          c = configurationOverrides.get(cacheName);
 
       c.assertValid();
@@ -408,10 +413,19 @@
       return globalConfiguration;
    }
 
-   @ManagedAttribute(description = "the defined cache names and their status")
+   public Set<String> getCacheNames() {
+      Set<String> names = new HashSet<String>(configurationOverrides.keySet());
+      names.remove(DEFAULT_CACHE_NAME);
+      if (names.isEmpty())
+         return Collections.emptySet();
+      else
+         return Immutables.immutableSetWrap(names);
+   }
+
+   @ManagedAttribute(description = "The defined cache names and their statuses.  The default cache is not included in this representation.")
    public String getDefinedCacheNames() {
       StringBuilder result = new StringBuilder("[");
-      for (String cacheName : this.configurationOverrides.keySet()) {
+      for (String cacheName : getCacheNames()) {
          boolean started = caches.containsKey(cacheName);
          result.append(cacheName).append(started ? "(created)" : "(not created)");
       }
@@ -419,12 +433,12 @@
       return result.toString();
    }
 
-   @ManagedAttribute(description = "the total number of defined caches")
+   @ManagedAttribute(description = "The total number of defined caches, excluding the default cache.")
    public String getDefinedCacheCount() {
-      return String.valueOf(this.configurationOverrides.keySet().size());
+      return String.valueOf(this.configurationOverrides.keySet().size() - 1);
    }
 
-   @ManagedAttribute(description = "number of running caches")
+   @ManagedAttribute(description = "The total number of running caches, including the default cache.")
    public String getCreatedCacheCount() {
       return String.valueOf(this.caches.keySet().size());
    }



More information about the infinispan-commits mailing list